[xcb] XCB polling and single-threadedness

Soeren Sandmann xcb@nickle.org
07 Jul 2002 12:49:58 +0200


Jamey Sharp <jamey@sharp.ath.cx> writes:

> OK, I guess that should have been obvious. XCBPollEvent is now
> done. :)

You beat me to it by a few minutes :-)=20

One comment: What does it mean when a function name is postfixed by
"Locked"? Does it mean

        (a) "you should lock before calling this function",=20

or does it mean=20

        (b) "this function will do its own locking".

It looks to me like XCBFlushLocked() uses the (a) meaning, and your
new XCBFillBufferLocked() uses the (b) meaning.


The patch below makes XCBFillBuffer empty the file descriptor instead
of calling read() just once. It also inserts a FIXME comment for the
case when the connection is closed; I am not sure what to do in that
case.


S=F8ren

Index: src/xcb_io.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /local/src/CVS/xcb/src/xcb_io.c,v
retrieving revision 1.10
diff -u -r1.10 xcb_io.c
--- src/xcb_io.c	7 Jul 2002 10:14:29 -0000	1.10
+++ src/xcb_io.c	7 Jul 2002 10:47:26 -0000
@@ -122,13 +122,30 @@
=20
 static int XCBFillBuffer(XCBIOHandle *h)
 {
-    int ret;
-    ret =3D read(h->fd, h->inqueue + h->n_inqueue, sizeof(h->inqueue) - h-=
>n_inqueue);
-    if(ret < 0)
-        return errno =3D=3D EAGAIN ? 1 : -1;
-    h->n_inqueue +=3D ret;
-    while(ret > 0)
-        ret =3D h->reader(h->readerdata, h);
+    int data_read =3D 0;
+
+    while(sizeof(h->inqueue) - h->n_inqueue > 0)
+    {
+	int ret;
+
+	ret =3D read(h->fd, h->inqueue + h->n_inqueue, sizeof(h->inqueue) - h->n_=
inqueue);
+	if(ret < 0)
+	{
+	    if(errno =3D=3D EAGAIN)
+		break;
+	    else
+		return -1;
+	}
+	else if (ret =3D=3D 0)
+	    /* FIXME: connection closed ... */
+	    ;
+
+	data_read =3D 1;
+	h->n_inqueue +=3D ret;
+    }
+    if(data_read)
+	while (h->reader(h->readerdata, h) > 0)
+	    ;
     return 1;
 }
=20