Add XCBPollForReply and deprecate XCBGetRequestRead and XCBGetQueuedRequestRead.
authorJamey Sharp <jamey@minilop.net>
Wed, 19 Apr 2006 23:49:32 +0000 (16:49 -0700)
committerJamey Sharp <jamey@minilop.net>
Wed, 19 Apr 2006 23:49:32 +0000 (16:49 -0700)
src/xcb.h
src/xcb_in.c
src/xcbext.h
src/xcbxlib.h

index 204164a..d4d02b4 100644 (file)
--- a/src/xcb.h
+++ b/src/xcb.h
@@ -273,9 +273,10 @@ XCBGenericEvent *XCBPollForEvent(XCBConnection *c, int *error);
  * processed. This function enables applications to determine whether
  * forcing a cookie is going to block.
  *
- * @todo review that function.
+ * @deprecated This function is deprecated in favor of XCBPollForReply.
+ * It must not be used in newly written code.
  */
-unsigned int XCBGetRequestRead(XCBConnection *c);
+unsigned int XCBGetRequestRead(XCBConnection *c) deprecated;
 
 
 /* xcb_ext.c */
index 76f9702..4ad4654 100644 (file)
@@ -239,6 +239,51 @@ static int read_block(const int fd, void *buf, const size_t len)
     return len;
 }
 
+static int poll_for_reply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error)
+{
+    struct reply_list *head;
+
+    if(!request)
+        head = 0;
+    else if(c->in.request_completed >= request)
+    {
+        head = _xcb_map_remove(c->in.replies, request);
+        if(head && head->next)
+            _xcb_map_put(c->in.replies, request, head->next);
+    }
+    else if(c->in.request_read == request && c->in.current_reply)
+    {
+        head = c->in.current_reply;
+        c->in.current_reply = head->next;
+        if(!head->next)
+            c->in.current_reply_tail = &c->in.current_reply;
+    }
+    else
+        /* Would block: do nothing. */
+        return 0;
+
+    if(error)
+        *error = 0;
+    *reply = 0;
+
+    if(head)
+    {
+        if(((XCBGenericRep *) head->reply)->response_type == XCBError)
+        {
+            if(error)
+                *error = head->reply;
+            else
+                free(head->reply);
+        }
+        else
+            *reply = head->reply;
+
+        free(head);
+    }
+
+    return 1;
+}
+
 /* Public interface */
 
 void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e)
@@ -323,6 +368,16 @@ done:
     return ret;
 }
 
+int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error)
+{
+    int ret;
+    assert(reply != 0);
+    pthread_mutex_lock(&c->iolock);
+    ret = poll_for_reply(c, request, reply, error);
+    pthread_mutex_unlock(&c->iolock);
+    return ret;
+}
+
 XCBGenericEvent *XCBWaitEvent(XCBConnection *c)
 {
     return XCBWaitForEvent(c);
index 0d172e9..508ebf0 100644 (file)
@@ -63,6 +63,7 @@ unsigned int XCBSendRequest(XCBConnection *c, int flags, struct iovec *vector, c
 /* xcb_in.c */
 
 void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e);
+int XCBPollForReply(XCBConnection *c, unsigned int request, void **reply, XCBGenericError **error);
 
 
 /* xcb_xid.c */
index 462e2e3..4ceb03e 100644 (file)
@@ -32,7 +32,7 @@
 #include "xcb.h"
 
 /* This function must be called with the IOLock held. */
-unsigned int XCBGetQueuedRequestRead(XCBConnection *c);
+unsigned int XCBGetQueuedRequestRead(XCBConnection *c) deprecated;
 
 /* This function must be called with the IOLock held. */
 unsigned int XCBGetRequestSent(XCBConnection *c);