diff options
author | Jamey Sharp <jamey@minilop.net> | 2006-09-15 01:09:27 -0700 |
---|---|---|
committer | Jamey Sharp <jamey@minilop.net> | 2006-09-21 15:18:57 -0700 |
commit | 7f71bf9c0f30536e85907b2c991cb7001861e1d3 (patch) | |
tree | d8c3587b5b3851cf9df9b8555e11acd3581d2743 /src | |
parent | 0aa96bfc7abe18889cd85bfaa05b05d53e572bb1 (diff) |
Make all public functions do nothing on an error connection.
Diffstat (limited to 'src')
-rw-r--r-- | src/xcb_conn.c | 6 | ||||
-rw-r--r-- | src/xcb_ext.c | 4 | ||||
-rw-r--r-- | src/xcb_in.c | 40 | ||||
-rw-r--r-- | src/xcb_out.c | 7 | ||||
-rw-r--r-- | src/xcb_xid.c | 2 | ||||
-rw-r--r-- | src/xcb_xlib.c | 4 |
6 files changed, 50 insertions, 13 deletions
diff --git a/src/xcb_conn.c b/src/xcb_conn.c index 0176524..2b24dc0 100644 --- a/src/xcb_conn.c +++ b/src/xcb_conn.c @@ -179,12 +179,16 @@ static int write_vec(XCBConnection *c, struct iovec **vector, int *count) const XCBSetup *XCBGetSetup(XCBConnection *c) { + if(c->has_error) + return 0; /* doesn't need locking because it's never written to. */ return c->setup; } int XCBGetFileDescriptor(XCBConnection *c) { + if(c->has_error) + return -1; /* doesn't need locking because it's never written to. */ return c->fd; } @@ -225,7 +229,7 @@ XCBConnection *XCBConnectToFD(int fd, XCBAuthInfo *auth_info) void XCBDisconnect(XCBConnection *c) { - if(!c) + if(c->has_error) return; free(c->setup); diff --git a/src/xcb_ext.c b/src/xcb_ext.c index 610ec57..3732515 100644 --- a/src/xcb_ext.c +++ b/src/xcb_ext.c @@ -84,6 +84,8 @@ static lazyreply *get_lazyreply(XCBConnection *c, XCBExtension *ext) const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension *ext) { lazyreply *data; + if(c->has_error) + return 0; pthread_mutex_lock(&c->ext.lock); data = get_lazyreply(c, ext); @@ -99,6 +101,8 @@ const XCBQueryExtensionRep *XCBGetExtensionData(XCBConnection *c, XCBExtension * void XCBPrefetchExtensionData(XCBConnection *c, XCBExtension *ext) { + if(c->has_error) + return; pthread_mutex_lock(&c->ext.lock); get_lazyreply(c, ext); pthread_mutex_unlock(&c->ext.lock); diff --git a/src/xcb_in.c b/src/xcb_in.c index eab8b1d..d8b608a 100644 --- a/src/xcb_in.c +++ b/src/xcb_in.c @@ -308,6 +308,8 @@ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError ** void *ret = 0; if(e) *e = 0; + if(c->has_error) + return 0; pthread_mutex_lock(&c->iolock); @@ -356,6 +358,13 @@ void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError ** int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error) { int ret; + if(c->has_error) + { + *reply = 0; + if(error) + *error = 0; + return 1; /* would not block */ + } assert(reply != 0); pthread_mutex_lock(&c->iolock); ret = poll_for_reply(c, request, reply, error); @@ -366,6 +375,8 @@ int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGen XCBGenericEvent *XCBWaitForEvent(XCBConnection *c) { XCBGenericEvent *ret; + if(c->has_error) + return 0; pthread_mutex_lock(&c->iolock); /* get_event returns 0 on empty list. */ while(!(ret = get_event(c))) @@ -379,19 +390,22 @@ XCBGenericEvent *XCBWaitForEvent(XCBConnection *c) XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error) { - XCBGenericEvent *ret = 0; - int success; - pthread_mutex_lock(&c->iolock); - /* FIXME: follow X meets Z architecture changes. */ - success = _xcb_in_read(c); - if(success) - ret = get_event(c); - pthread_mutex_unlock(&c->iolock); - if(success) + if(!c->has_error) { - if(error) - *error = 0; - return ret; + XCBGenericEvent *ret = 0; + int success; + pthread_mutex_lock(&c->iolock); + /* FIXME: follow X meets Z architecture changes. */ + success = _xcb_in_read(c); + if(success) + ret = get_event(c); + pthread_mutex_unlock(&c->iolock); + if(success) + { + if(error) + *error = 0; + return ret; + } } if(error) *error = -1; @@ -410,6 +424,8 @@ XCBGenericError *XCBRequestCheck(XCBConnection *c, XCBVoidCookie cookie) * XCBGetInputFocusReply, and XCBWaitForReply. */ XCBGenericError *ret; void *reply; + if(c->has_error) + return 0; if(XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_expected) && XCB_SEQUENCE_COMPARE(cookie.sequence,>,c->in.request_completed)) { diff --git a/src/xcb_out.c b/src/xcb_out.c index 56e02f7..91f7ea1 100644 --- a/src/xcb_out.c +++ b/src/xcb_out.c @@ -59,6 +59,8 @@ static int write_block(XCBConnection *c, struct iovec *vector, int count) CARD32 XCBGetMaximumRequestLength(XCBConnection *c) { + if(c->has_error) + return 0; pthread_mutex_lock(&c->out.reqlenlock); if(!c->out.maximum_request_length) { @@ -91,6 +93,9 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c int veclen = req->count; enum workarounds workaround = WORKAROUND_NONE; + if(c->has_error) + return 0; + assert(c != 0); assert(vector != 0); assert(req->count > 0); @@ -200,6 +205,8 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c int XCBFlush(XCBConnection *c) { int ret; + if(c->has_error) + return 0; pthread_mutex_lock(&c->iolock); ret = _xcb_out_flush_to(c, c->out.request); pthread_mutex_unlock(&c->iolock); diff --git a/src/xcb_xid.c b/src/xcb_xid.c index 1c53b53..a2e7dec 100644 --- a/src/xcb_xid.c +++ b/src/xcb_xid.c @@ -36,6 +36,8 @@ CARD32 XCBGenerateID(XCBConnection *c) { CARD32 ret; + if(c->has_error) + return -1; pthread_mutex_lock(&c->xid.lock); if(c->xid.last == c->xid.max) { diff --git a/src/xcb_xlib.c b/src/xcb_xlib.c index 61518f7..054bc2e 100644 --- a/src/xcb_xlib.c +++ b/src/xcb_xlib.c @@ -28,10 +28,14 @@ unsigned int XCBGetRequestSent(XCBConnection *c) { + if(c->has_error) + return 0; return c->out.request; } pthread_mutex_t *XCBGetIOLock(XCBConnection *c) { + if(c->has_error) + return 0; return &c->iolock; } |