Make all public functions do nothing on an error connection.
authorJamey Sharp <jamey@minilop.net>
Fri, 15 Sep 2006 08:09:27 +0000 (01:09 -0700)
committerJamey Sharp <jamey@minilop.net>
Thu, 21 Sep 2006 22:18:57 +0000 (15:18 -0700)
src/xcb_conn.c
src/xcb_ext.c
src/xcb_in.c
src/xcb_out.c
src/xcb_xid.c
src/xcb_xlib.c

index 0176524..2b24dc0 100644 (file)
@@ -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);
index 610ec57..3732515 100644 (file)
@@ -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);
index eab8b1d..d8b608a 100644 (file)
@@ -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))
     {
index 56e02f7..91f7ea1 100644 (file)
@@ -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);
index 1c53b53..a2e7dec 100644 (file)
@@ -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)
     {
index 61518f7..054bc2e 100644 (file)
 
 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;
 }