projects
/
free-sw
/
xcb
/
libxcb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
xcb_disconnect: call shutdown() to force a disconnect
[free-sw/xcb/libxcb]
/
src
/
xcb_conn.c
diff --git
a/src/xcb_conn.c
b/src/xcb_conn.c
index
251d62e
..
803f7aa
100644
(file)
--- a/
src/xcb_conn.c
+++ b/
src/xcb_conn.c
@@
-42,6
+42,11
@@
#include <sys/select.h>
#endif
#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];
typedef struct {
uint8_t status;
uint8_t pad0[5];
@@
-102,10
+107,7
@@
static int write_setup(xcb_connection_t *c, xcb_auth_info_t *auth_info)
assert(count <= (int) (sizeof(parts) / sizeof(*parts)));
pthread_mutex_lock(&c->iolock);
assert(count <= (int) (sizeof(parts) / sizeof(*parts)));
pthread_mutex_lock(&c->iolock);
- {
- struct iovec *parts_ptr = parts;
- ret = _xcb_out_send(c, &parts_ptr, &count);
- }
+ ret = _xcb_out_send(c, parts, count);
pthread_mutex_unlock(&c->iolock);
return ret;
}
pthread_mutex_unlock(&c->iolock);
return ret;
}
@@
-210,9
+212,19
@@
xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
{
xcb_connection_t* c;
{
xcb_connection_t* c;
+#ifndef USE_POLL
+ if(fd >= FD_SETSIZE) /* would overflow in FD_SET */
+ {
+ close(fd);
+ return (xcb_connection_t *) &error_connection;
+ }
+#endif
+
c = calloc(1, sizeof(xcb_connection_t));
c = calloc(1, sizeof(xcb_connection_t));
- if(!c)
+ if(!c) {
+ close(fd);
return (xcb_connection_t *) &error_connection;
return (xcb_connection_t *) &error_connection;
+ }
c->fd = fd;
c->fd = fd;
@@
-240,6
+252,9
@@
void xcb_disconnect(xcb_connection_t *c)
return;
free(c->setup);
return;
free(c->setup);
+
+ /* disallow further sends and receives */
+ shutdown(c->fd, SHUT_RDWR);
close(c->fd);
pthread_mutex_destroy(&c->iolock);
close(c->fd);
pthread_mutex_destroy(&c->iolock);
@@
-303,15
+318,15
@@
int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
pthread_mutex_unlock(&c->iolock);
do {
#if USE_POLL
pthread_mutex_unlock(&c->iolock);
do {
#if USE_POLL
- ret = poll(&fd, 1, -1);
+
ret = poll(&fd, 1, -1);
#else
#else
- ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
+
ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
#endif
} while (ret == -1 && errno == EINTR);
#endif
} while (ret == -1 && errno == EINTR);
- if
(ret < 0)
+ if(ret < 0)
{
_xcb_conn_shutdown(c);
{
_xcb_conn_shutdown(c);
- ret = 0;
+
ret = 0;
}
pthread_mutex_lock(&c->iolock);
}
pthread_mutex_lock(&c->iolock);