backport some xts fixes from git

This commit is contained in:
Adam Jackson 2011-06-23 17:11:00 -04:00
parent 1425dac270
commit 6c46fe074d
4 changed files with 85 additions and 340 deletions

View File

@ -1,30 +0,0 @@
commit ee89850e68205a7f8961ace0839b5be86040dade
Author: elupus <elupus@ecce.se>
Date: Tue May 26 16:14:48 2009 +0200
Disable Nagle on TCP socket
Signed-off-by: Julien Danjou <julien@danjou.info>
diff --git a/src/xcb_util.c b/src/xcb_util.c
index adac909..55aadb7 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -30,6 +30,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
+#include <netinet/tcp.h>
#ifdef DNETCONN
#include <netdnet/dnetdb.h>
#include <netdnet/dn.h>
@@ -257,6 +258,9 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port)
{
fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
if(fd >= 0) {
+ int on = 1;
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on));
+
if (connect(fd, addr->ai_addr, addr->ai_addrlen) >= 0)
break;
close(fd);

View File

@ -1,309 +0,0 @@
diff --git a/configure.ac b/configure.ac
index 6fe3e57..46c4611 100644
--- a/configure.ac
+++ b/configure.ac
@@ -116,6 +116,8 @@ AC_PREREQ([2.59c], [], [AC_SUBST([htmldir], [m4_ifset([AC_PACKAGE_TARNAME],
XCB_CHECK_DOXYGEN()
+AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], )
+
XCB_EXTENSION(Composite, "yes")
XCB_EXTENSION(Damage, "yes")
XCB_EXTENSION(DPMS, "yes")
diff --git a/src/c_client.py b/src/c_client.py
index 73bd064..d86d05e 100755
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -135,6 +135,9 @@ def c_open(self):
_ns = self.namespace
_ns.c_ext_global_name = _n(_ns.prefix + ('id',))
+ # Build the type-name collision avoidance table used by c_enum
+ build_collision_table()
+
_h_setlevel(0)
_c_setlevel(0)
@@ -216,13 +219,26 @@ def c_close(self):
cfile.write('\n')
cfile.close()
+def build_collision_table():
+ global namecount
+ namecount = {}
+
+ for v in module.types.values():
+ name = _t(v[0])
+ namecount[name] = (namecount.get(name) or 0) + 1
+
def c_enum(self, name):
'''
Exported function that handles enum declarations.
'''
+
+ tname = _t(name)
+ if namecount[tname] > 1:
+ tname = _t(name + ('enum',))
+
_h_setlevel(0)
_h('')
- _h('typedef enum %s {', _t(name))
+ _h('typedef enum %s {', tname)
count = len(self.values)
@@ -232,7 +248,7 @@ def c_enum(self, name):
comma = ',' if count > 0 else ''
_h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
- _h('} %s;', _t(name))
+ _h('} %s;', tname)
def _c_type_setup(self, name, postfix):
'''
diff --git a/src/xcb_auth.c b/src/xcb_auth.c
index b44855e..93a6f68 100644
--- a/src/xcb_auth.c
+++ b/src/xcb_auth.c
@@ -187,7 +187,7 @@ static int compute_auth(xcb_auth_info_t *info, Xauth *authptr, struct sockaddr *
struct sockaddr_in6 *si6 = (struct sockaddr_in6 *) sockname;
if(IN6_IS_ADDR_V4MAPPED(SIN6_ADDR(sockname)))
{
- APPEND(info->data, j, si6->sin6_addr.s6_addr[12]);
+ do_append(info->data, &j, &si6->sin6_addr.s6_addr[12], 4);
APPEND(info->data, j, si6->sin6_port);
}
else
@@ -243,7 +243,14 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display)
int ret = 1;
if (getpeername(fd, sockname, &socknamelen) == -1)
- return 0; /* can only authenticate sockets */
+ {
+ if (getsockname(fd, sockname, &socknamelen) == -1)
+ return 0; /* can only authenticate sockets */
+ if (sockname->sa_family != AF_UNIX)
+ return 0;
+ /* Some systems like hpux or Hurd do not expose peer names
+ * for UNIX Domain Sockets. We do not need it anyway. */
+ }
authptr = get_authptr(sockname, socknamelen, display);
if (authptr == 0)
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index 5b097f7..251d62e 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -31,12 +31,16 @@
#include <unistd.h>
#include <stdlib.h>
#include <netinet/in.h>
-#include <sys/select.h>
#include <fcntl.h>
#include <errno.h>
#include "xcb.h"
#include "xcbint.h"
+#if USE_POLL
+#include <poll.h>
+#else
+#include <sys/select.h>
+#endif
typedef struct {
uint8_t status;
@@ -258,7 +262,11 @@ void _xcb_conn_shutdown(xcb_connection_t *c)
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count)
{
int ret;
+#if USE_POLL
+ struct pollfd fd;
+#else
fd_set rfds, wfds;
+#endif
/* If the thing I should be doing is already being done, wait for it. */
if(count ? c->out.writing : c->in.reading)
@@ -267,20 +275,38 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
return 1;
}
+#if USE_POLL
+ memset(&fd, 0, sizeof(fd));
+ fd.fd = c->fd;
+ fd.events = POLLIN;
+#else
FD_ZERO(&rfds);
FD_SET(c->fd, &rfds);
+#endif
++c->in.reading;
+#if USE_POLL
+ if(count)
+ {
+ fd.events |= POLLOUT;
+ ++c->out.writing;
+ }
+#else
FD_ZERO(&wfds);
if(count)
{
FD_SET(c->fd, &wfds);
++c->out.writing;
}
+#endif
pthread_mutex_unlock(&c->iolock);
do {
+#if USE_POLL
+ ret = poll(&fd, 1, -1);
+#else
ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
+#endif
} while (ret == -1 && errno == EINTR);
if (ret < 0)
{
@@ -291,10 +317,18 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
if(ret)
{
+#if USE_POLL
+ if((fd.revents & POLLIN) == POLLIN)
+#else
if(FD_ISSET(c->fd, &rfds))
+#endif
ret = ret && _xcb_in_read(c);
+#if USE_POLL
+ if((fd.revents & POLLOUT) == POLLOUT)
+#else
if(FD_ISSET(c->fd, &wfds))
+#endif
ret = ret && write_vec(c, vector, count);
}
diff --git a/src/xcb_in.c b/src/xcb_in.c
index 212dc9a..26ab358 100644
--- a/src/xcb_in.c
+++ b/src/xcb_in.c
@@ -30,12 +30,16 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
-#include <sys/select.h>
#include <errno.h>
#include "xcb.h"
#include "xcbext.h"
#include "xcbint.h"
+#if USE_POLL
+#include <poll.h>
+#else
+#include <sys/select.h>
+#endif
#define XCB_ERROR 0
#define XCB_REPLY 1
@@ -268,12 +272,22 @@ static int read_block(const int fd, void *buf, const ssize_t len)
done += ret;
if(ret < 0 && errno == EAGAIN)
{
+#if USE_POLL
+ struct pollfd pfd;
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ do {
+ ret = poll(&pfd, 1, -1);
+ } while (ret == -1 && errno == EINTR);
+#else
fd_set fds;
FD_ZERO(&fds);
FD_SET(fd, &fds);
do {
ret = select(fd + 1, &fds, 0, 0, 0);
} while (ret == -1 && errno == EINTR);
+#endif
}
if(ret <= 0)
return ret;
diff --git a/src/xcb_xid.c b/src/xcb_xid.c
index 7ff0c5f..3df5dbe 100644
--- a/src/xcb_xid.c
+++ b/src/xcb_xid.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
+/* Copyright (C) 2001-2008 Bart Massey and Jamey Sharp.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -25,6 +25,7 @@
/* XID allocators. */
+#include <assert.h>
#include <stdlib.h>
#include "xcb.h"
#include "xcbext.h"
@@ -39,21 +40,40 @@ uint32_t xcb_generate_id(xcb_connection_t *c)
if(c->has_error)
return -1;
pthread_mutex_lock(&c->xid.lock);
- if(c->xid.last == c->xid.max)
+ if(c->xid.last >= c->xid.max - c->xid.inc + 1)
{
xcb_xc_misc_get_xid_range_reply_t *range;
- range = xcb_xc_misc_get_xid_range_reply(c, xcb_xc_misc_get_xid_range(c), 0);
- if(!range)
- {
- pthread_mutex_unlock(&c->xid.lock);
- return -1;
+ assert(c->xid.last == c->xid.max);
+ if (c->xid.last == 0) {
+ /* finish setting up initial range */
+ c->xid.max = c->setup->resource_id_mask;
+ } else {
+ /* check for extension */
+ const xcb_query_extension_reply_t *xc_misc_reply =
+ xcb_get_extension_data(c, &xcb_xc_misc_id);
+ if (!xc_misc_reply) {
+ pthread_mutex_unlock(&c->xid.lock);
+ return -1;
+ }
+ /* get new range */
+ range = xcb_xc_misc_get_xid_range_reply(c,
+ xcb_xc_misc_get_xid_range(c), 0);
+ /* XXX The latter disjunct is what the server returns
+ when it is out of XIDs. Sweet. */
+ if(!range || (range->start_id == 0 && range->count == 1))
+ {
+ pthread_mutex_unlock(&c->xid.lock);
+ return -1;
+ }
+ assert(range->count > 0 && range->start_id > 0);
+ c->xid.last = range->start_id;
+ c->xid.max = range->start_id + (range->count - 1) * c->xid.inc;
+ free(range);
}
- c->xid.last = range->start_id;
- c->xid.max = range->start_id + (range->count - 1) * c->xid.inc;
- free(range);
+ } else {
+ c->xid.last += c->xid.inc;
}
ret = c->xid.last | c->xid.base;
- c->xid.last += c->xid.inc;
pthread_mutex_unlock(&c->xid.lock);
return ret;
}
@@ -65,8 +85,8 @@ int _xcb_xid_init(xcb_connection_t *c)
if(pthread_mutex_init(&c->xid.lock, 0))
return 0;
c->xid.last = 0;
+ c->xid.max = 0;
c->xid.base = c->setup->resource_id_base;
- c->xid.max = c->setup->resource_id_mask;
c->xid.inc = c->setup->resource_id_mask & -(c->setup->resource_id_mask);
return 1;
}

View File

@ -0,0 +1,79 @@
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index 7e18891..e30c5ca 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -42,13 +42,18 @@
#include <sys/select.h>
#endif
+/* SHUT_RDWR is fairly recent and is not available on all platforms */
+#if !defined(SHUT_RDWR)
+#define SHUT_RDWR 2
+#endif
+
typedef struct {
uint8_t status;
uint8_t pad0[5];
uint16_t length;
} xcb_setup_generic_t;
-static const int error_connection = 1;
+const int error_connection = 1;
static int set_fd_flags(const int fd)
{
@@ -243,10 +248,13 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
void xcb_disconnect(xcb_connection_t *c)
{
- if(c->has_error)
+ if(c == (xcb_connection_t *) &error_connection)
return;
free(c->setup);
+
+ /* disallow further sends and receives */
+ shutdown(c->fd, SHUT_RDWR);
close(c->fd);
pthread_mutex_destroy(&c->iolock);
@@ -311,6 +319,13 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
do {
#if USE_POLL
ret = poll(&fd, 1, -1);
+ /* If poll() returns an event we didn't expect, such as POLLNVAL, treat
+ * it as if it failed. */
+ if(ret >= 0 && (fd.revents & ~fd.events))
+ {
+ ret = -1;
+ break;
+ }
#else
ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
#endif
diff --git a/src/xcb_util.c b/src/xcb_util.c
index 5a82ac1..07fa4a3 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -49,8 +49,6 @@
#include "xcbext.h"
#include "xcbint.h"
-static const int error_connection = 1;
-
int xcb_popcount(uint32_t mask)
{
uint32_t y;
diff --git a/src/xcbint.h b/src/xcbint.h
index f07add8..6991238 100644
--- a/src/xcbint.h
+++ b/src/xcbint.h
@@ -174,6 +174,8 @@ void _xcb_ext_destroy(xcb_connection_t *c);
/* xcb_conn.c */
+extern const int error_connection;
+
struct xcb_connection_t {
int has_error;

View File

@ -1,6 +1,6 @@
Name: libxcb
Version: 1.7
Release: 2%{?dist}
Release: 3%{?dist}
Summary: A C binding to the X11 protocol
Group: System Environment/Libraries
@ -13,6 +13,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
# we don't need the library because glibc has working pthreads, but we need
# the pkgconfig file so libs that link against libxcb know this...
Source1: pthread-stubs.pc.in
Patch0: libxcb-1.7-xts-fixes.patch
BuildRequires: autoconf automake libtool pkgconfig
@ -49,6 +50,7 @@ The %{name}-doc package contains documentation for the %{name} library.
%prep
%setup -q
%patch0 -p1 -b .xts
%build
sed -i 's/pthread-stubs //' configure.ac
@ -110,6 +112,9 @@ rm -rf $RPM_BUILD_ROOT
%{_datadir}/doc/%{name}-%{version}
%changelog
* Thu Jun 23 2011 Adam Jackson <ajax@redhat.com> 1.7-3
- libxcb-1.7-xts-fixes.patch: Backport some XTS5 fixes from git.
* Tue Feb 08 2011 Adam Jackson <ajax@redhat.com> 1.7-2
- Fix FTBFS.