[Xcb-commit] 6 commits - xcb
Jamey Sharp
jamey at kemper.freedesktop.org
Sun Mar 12 13:54:25 PST 2006
xcb/src/xcb_conn.c | 45 +++++++++++++++++++----
xcb/src/xcb_in.c | 9 ++--
xcb/src/xcb_out.c | 103 ++++++++++++++++++++---------------------------------
xcb/src/xcbint.h | 9 +---
4 files changed, 84 insertions(+), 82 deletions(-)
New commits:
diff-tree 62ad73204c06463c8a6b0ddd648e090f91b42374 (from parents)
Merge: 2c3330a3398b5d89509392a19b247b74914b256e 284d28a2a968f4e520a60cda1c7c326074ca9f65
Author: Jamey Sharp <jamey at minilop.net>
Date: Sun Mar 12 13:36:33 2006 -0800
Merge branch 'master' of git+ssh://git.freedesktop.org/git/xcb
diff-tree 2c3330a3398b5d89509392a19b247b74914b256e (from 64f28ac66473093fa2cbcbe74d7485bb8b14ff75)
Author: Jamey Sharp <jamey at minilop.net>
Date: Sun Mar 12 13:20:29 2006 -0800
Only _xcb_conn_wait calls _xcb_out_write now, so move it to xcb_conn.c and make it static.
diff --git a/xcb/src/xcb_conn.c b/xcb/src/xcb_conn.c
index 1b3e1a2..2da3150 100644
--- a/xcb/src/xcb_conn.c
+++ b/xcb/src/xcb_conn.c
@@ -33,6 +33,7 @@
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/fcntl.h>
+#include <errno.h>
#include "xcb.h"
#include "xcbint.h"
@@ -138,6 +139,34 @@ static int read_setup(XCBConnection *c)
return 1;
}
+/* precondition: there must be something for us to write. */
+static int write_vec(XCBConnection *c, struct iovec **vector, int *count)
+{
+ int n;
+ assert(!c->out.queue_len);
+ n = writev(c->fd, *vector, *count);
+ if(n < 0 && errno == EAGAIN)
+ return 1;
+ if(n <= 0)
+ return 0;
+
+ for(; *count; --*count, ++*vector)
+ {
+ int cur = (*vector)->iov_len;
+ if(cur > n)
+ cur = n;
+ (*vector)->iov_len -= cur;
+ (*vector)->iov_base = (char *) (*vector)->iov_base + cur;
+ n -= cur;
+ if((*vector)->iov_len)
+ break;
+ }
+ if(!*count)
+ *vector = 0;
+ assert(n == 0);
+ return 1;
+}
+
/* Public interface */
XCBConnSetupSuccessRep *XCBGetSetup(XCBConnection *c)
@@ -233,7 +262,7 @@ int _xcb_conn_wait(XCBConnection *c, pth
ret = ret && _xcb_in_read(c);
if(FD_ISSET(c->fd, &wfds))
- ret = ret && _xcb_out_write(c, vector, count);
+ ret = ret && write_vec(c, vector, count);
}
if(count)
diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index b0130e7..2b1a434 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -29,7 +29,6 @@
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <errno.h>
#include "xcb.h"
#include "xcbext.h"
@@ -224,34 +223,6 @@ void _xcb_out_destroy(_xcb_out *out)
pthread_mutex_destroy(&out->reqlenlock);
}
-/* precondition: there must be something for us to write. */
-int _xcb_out_write(XCBConnection *c, struct iovec **vector, int *count)
-{
- int n;
- assert(!c->out.queue_len);
- n = writev(c->fd, *vector, *count);
- if(n < 0 && errno == EAGAIN)
- return 1;
- if(n <= 0)
- return 0;
-
- for(; *count; --*count, ++*vector)
- {
- int cur = (*vector)->iov_len;
- if(cur > n)
- cur = n;
- (*vector)->iov_len -= cur;
- (*vector)->iov_base = (char *) (*vector)->iov_base + cur;
- n -= cur;
- if((*vector)->iov_len)
- break;
- }
- if(!*count)
- *vector = 0;
- assert(n == 0);
- return 1;
-}
-
int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count)
{
int ret = 1;
diff --git a/xcb/src/xcbint.h b/xcb/src/xcbint.h
index e90ede2..7b32248 100644
--- a/xcb/src/xcbint.h
+++ b/xcb/src/xcbint.h
@@ -74,7 +74,6 @@ typedef struct _xcb_out {
int _xcb_out_init(_xcb_out *out);
void _xcb_out_destroy(_xcb_out *out);
-int _xcb_out_write(XCBConnection *c, struct iovec **vector, int *count);
int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count);
int _xcb_out_flush_to(XCBConnection *c, unsigned int request);
diff-tree 64f28ac66473093fa2cbcbe74d7485bb8b14ff75 (from 3e480013bf62a6eae266bd4d2e3cd92712f4eeb8)
Author: Jamey Sharp <jamey at minilop.net>
Date: Sun Mar 12 12:40:34 2006 -0800
Remove c->out.vec. Pass iovecs directly down the call tree. Add _xcb_out_flush_to, refactor other functions, make write_block static.
diff --git a/xcb/src/xcb_conn.c b/xcb/src/xcb_conn.c
index 792dfb8..1b3e1a2 100644
--- a/xcb/src/xcb_conn.c
+++ b/xcb/src/xcb_conn.c
@@ -89,8 +89,10 @@ static int write_setup(XCBConnection *c,
assert(count <= sizeof(parts) / sizeof(*parts));
pthread_mutex_lock(&c->iolock);
- _xcb_out_write_block(c, parts, count);
- ret = _xcb_out_flush(c);
+ {
+ struct iovec *parts_ptr = parts;
+ ret = _xcb_out_send(c, &parts_ptr, &count);
+ }
pthread_mutex_unlock(&c->iolock);
return ret;
}
diff --git a/xcb/src/xcb_in.c b/xcb/src/xcb_in.c
index fe9a873..89b06ab 100644
--- a/xcb/src/xcb_in.c
+++ b/xcb/src/xcb_in.c
@@ -252,9 +252,8 @@ void *XCBWaitForReply(XCBConnection *c,
pthread_mutex_lock(&c->iolock);
/* If this request has not been written yet, write it. */
- if((signed int) (c->out.request_written - request) < 0)
- if(!_xcb_out_flush(c))
- goto done; /* error */
+ if(!_xcb_out_flush_to(c, request))
+ goto done; /* error */
for(prev_reader = &c->in.readers; *prev_reader && (*prev_reader)->request <= request; prev_reader = &(*prev_reader)->next)
if((*prev_reader)->request == request)
diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index ba60d3f..b0130e7 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -36,6 +36,26 @@
#include "xcbint.h"
#include "extensions/bigreq.h"
+static int write_block(XCBConnection *c, struct iovec *vector, int count)
+{
+ while(count && c->out.queue_len + vector[0].iov_len <= sizeof(c->out.queue))
+ {
+ memcpy(c->out.queue + c->out.queue_len, vector[0].iov_base, vector[0].iov_len);
+ c->out.queue_len += vector[0].iov_len;
+ vector[0].iov_base = (char *) vector[0].iov_base + vector[0].iov_len;
+ vector[0].iov_len = 0;
+ ++vector, --count;
+ }
+ if(!count)
+ return 1;
+
+ --vector, ++count;
+ vector[0].iov_base = c->out.queue;
+ vector[0].iov_len = c->out.queue_len;
+ c->out.queue_len = 0;
+ return _xcb_out_send(c, &vector, &count);
+}
+
/* Public interface */
CARD32 XCBGetMaximumRequestLength(XCBConnection *c)
@@ -163,7 +183,7 @@ unsigned int XCBSendRequest(XCBConnectio
vector[0].iov_base = prefix + !prefix[0];
}
- if(!_xcb_out_write_block(c, vector, veclen))
+ if(!write_block(c, vector, veclen))
request = 0;
pthread_mutex_unlock(&c->iolock);
return request;
@@ -173,7 +193,7 @@ int XCBFlush(XCBConnection *c)
{
int ret;
pthread_mutex_lock(&c->iolock);
- ret = _xcb_out_flush(c);
+ ret = _xcb_out_flush_to(c, c->out.request);
pthread_mutex_unlock(&c->iolock);
return ret;
}
@@ -187,8 +207,6 @@ int _xcb_out_init(_xcb_out *out)
out->writing = 0;
out->queue_len = 0;
- out->vec = 0;
- out->vec_len = 0;
out->request = 0;
out->request_written = 0;
@@ -234,46 +252,32 @@ int _xcb_out_write(XCBConnection *c, str
return 1;
}
-int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count)
+int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count)
{
- assert(!c->out.vec && !c->out.vec_len);
- while(count && c->out.queue_len + vector[0].iov_len <= sizeof(c->out.queue))
- {
- memcpy(c->out.queue + c->out.queue_len, vector[0].iov_base, vector[0].iov_len);
- c->out.queue_len += vector[0].iov_len;
- vector[0].iov_base = (char *) vector[0].iov_base + vector[0].iov_len;
- vector[0].iov_len = 0;
- ++vector, --count;
- }
- if(!count)
- return 1;
-
- --vector, ++count;
- vector[0].iov_base = c->out.queue;
- vector[0].iov_len = c->out.queue_len;
- c->out.queue_len = 0;
-
- c->out.vec_len = count;
- c->out.vec = vector;
- return _xcb_out_flush(c);
+ int ret = 1;
+ while(ret && *count)
+ ret = _xcb_conn_wait(c, &c->out.cond, vector, count);
+ c->out.request_written = c->out.request;
+ pthread_cond_broadcast(&c->out.cond);
+ return ret;
}
-int _xcb_out_flush(XCBConnection *c)
+int _xcb_out_flush_to(XCBConnection *c, unsigned int request)
{
- int ret = 1;
- struct iovec vec;
+ assert(request <= c->out.request);
+ if(c->out.request_written >= request)
+ return 1;
if(c->out.queue_len)
{
- assert(!c->out.vec && !c->out.vec_len);
+ struct iovec vec, *vec_ptr = &vec;
+ int count = 1;
vec.iov_base = c->out.queue;
vec.iov_len = c->out.queue_len;
- c->out.vec = &vec;
- c->out.vec_len = 1;
c->out.queue_len = 0;
+ return _xcb_out_send(c, &vec_ptr, &count);
}
- while(ret && c->out.vec_len)
- ret = _xcb_conn_wait(c, &c->out.cond, &c->out.vec, &c->out.vec_len);
- c->out.request_written = c->out.request;
- pthread_cond_broadcast(&c->out.cond);
- return ret;
+ while(c->out.writing)
+ pthread_cond_wait(&c->out.cond, &c->iolock);
+ assert(c->out.request_written >= request);
+ return 1;
}
diff --git a/xcb/src/xcbint.h b/xcb/src/xcbint.h
index a8287e8..e90ede2 100644
--- a/xcb/src/xcbint.h
+++ b/xcb/src/xcbint.h
@@ -63,8 +63,6 @@ typedef struct _xcb_out {
char queue[4096];
int queue_len;
- struct iovec *vec;
- int vec_len;
unsigned int request;
unsigned int request_written;
@@ -77,8 +75,8 @@ int _xcb_out_init(_xcb_out *out);
void _xcb_out_destroy(_xcb_out *out);
int _xcb_out_write(XCBConnection *c, struct iovec **vector, int *count);
-int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count);
-int _xcb_out_flush(XCBConnection *c);
+int _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count);
+int _xcb_out_flush_to(XCBConnection *c, unsigned int request);
/* xcb_in.c */
diff-tree 3e480013bf62a6eae266bd4d2e3cd92712f4eeb8 (from 97d064e80e060243b335aa5904e87b84960a5427)
Author: Jamey Sharp <jamey at minilop.net>
Date: Thu Mar 9 00:02:42 2006 -0800
Move c->out.vec refs out of _xcb_conn_wait up to _xcb_out_flush.
diff --git a/xcb/src/xcb_conn.c b/xcb/src/xcb_conn.c
index 0491721..792dfb8 100644
--- a/xcb/src/xcb_conn.c
+++ b/xcb/src/xcb_conn.c
@@ -198,13 +198,13 @@ void XCBDisconnect(XCBConnection *c)
/* Private interface */
-int _xcb_conn_wait(XCBConnection *c, const int should_write, pthread_cond_t *cond)
+int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector, int *count)
{
int ret;
fd_set rfds, wfds;
/* If the thing I should be doing is already being done, wait for it. */
- if(should_write ? c->out.writing : c->in.reading)
+ if(count ? c->out.writing : c->in.reading)
{
pthread_cond_wait(cond, &c->iolock);
return 1;
@@ -215,7 +215,7 @@ int _xcb_conn_wait(XCBConnection *c, con
++c->in.reading;
FD_ZERO(&wfds);
- if(should_write)
+ if(count)
{
FD_SET(c->fd, &wfds);
++c->out.writing;
@@ -231,10 +231,10 @@ int _xcb_conn_wait(XCBConnection *c, con
ret = ret && _xcb_in_read(c);
if(FD_ISSET(c->fd, &wfds))
- ret = ret && _xcb_out_write(c, &c->out.vec, &c->out.vec_len);
+ ret = ret && _xcb_out_write(c, vector, count);
}
- if(should_write)
+ if(count)
--c->out.writing;
--c->in.reading;
diff --git a/xcb/src/xcb_in.c b/xcb/src/xcb_in.c
index ea851c7..fe9a873 100644
--- a/xcb/src/xcb_in.c
+++ b/xcb/src/xcb_in.c
@@ -269,7 +269,7 @@ void *XCBWaitForReply(XCBConnection *c,
* wait for one. */
while(c->in.request_completed < request &&
!(c->in.request_read == request && c->in.current_reply))
- if(!_xcb_conn_wait(c, /*should_write*/ 0, &cond))
+ if(!_xcb_conn_wait(c, &cond, 0, 0))
goto done;
if(c->in.request_read != request)
@@ -329,7 +329,7 @@ XCBGenericEvent *XCBWaitForEvent(XCBConn
pthread_mutex_lock(&c->iolock);
/* get_event returns 0 on empty list. */
while(!(ret = get_event(c)))
- if(!_xcb_conn_wait(c, /*should_write*/ 0, &c->in.event_cond))
+ if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
break;
wake_up_next_reader(c);
diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index c84a27c..ba60d3f 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -272,7 +272,7 @@ int _xcb_out_flush(XCBConnection *c)
c->out.queue_len = 0;
}
while(ret && c->out.vec_len)
- ret = _xcb_conn_wait(c, /*should_write*/ 1, &c->out.cond);
+ ret = _xcb_conn_wait(c, &c->out.cond, &c->out.vec, &c->out.vec_len);
c->out.request_written = c->out.request;
pthread_cond_broadcast(&c->out.cond);
return ret;
diff --git a/xcb/src/xcbint.h b/xcb/src/xcbint.h
index e6f540a..a8287e8 100644
--- a/xcb/src/xcbint.h
+++ b/xcb/src/xcbint.h
@@ -157,7 +157,7 @@ struct XCBConnection {
_xcb_xid xid;
};
-int _xcb_conn_wait(XCBConnection *c, const int should_write, pthread_cond_t *cond);
+int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector, int *count);
#ifdef GCC_HAS_VISIBILITY
#pragma GCC visibility pop
diff-tree 97d064e80e060243b335aa5904e87b84960a5427 (from c2f66ae5c599d1c76789ad4e0e0691e732490c52)
Author: Jamey Sharp <jamey at minilop.net>
Date: Wed Mar 8 14:21:16 2006 -0800
Move c->out.vec refs out of _xcb_out_write up to _xcb_conn_wait.
diff --git a/xcb/src/xcb_conn.c b/xcb/src/xcb_conn.c
index 5839ed8..0491721 100644
--- a/xcb/src/xcb_conn.c
+++ b/xcb/src/xcb_conn.c
@@ -231,7 +231,7 @@ int _xcb_conn_wait(XCBConnection *c, con
ret = ret && _xcb_in_read(c);
if(FD_ISSET(c->fd, &wfds))
- ret = ret && _xcb_out_write(c);
+ ret = ret && _xcb_out_write(c, &c->out.vec, &c->out.vec_len);
}
if(should_write)
diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index 1faf2a5..c84a27c 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -207,29 +207,29 @@ void _xcb_out_destroy(_xcb_out *out)
}
/* precondition: there must be something for us to write. */
-int _xcb_out_write(XCBConnection *c)
+int _xcb_out_write(XCBConnection *c, struct iovec **vector, int *count)
{
int n;
assert(!c->out.queue_len);
- n = writev(c->fd, c->out.vec, c->out.vec_len);
+ n = writev(c->fd, *vector, *count);
if(n < 0 && errno == EAGAIN)
return 1;
if(n <= 0)
return 0;
- for(; c->out.vec_len; --c->out.vec_len, ++c->out.vec)
+ for(; *count; --*count, ++*vector)
{
- int cur = c->out.vec->iov_len;
+ int cur = (*vector)->iov_len;
if(cur > n)
cur = n;
- c->out.vec->iov_len -= cur;
- c->out.vec->iov_base = (char *) c->out.vec->iov_base + cur;
+ (*vector)->iov_len -= cur;
+ (*vector)->iov_base = (char *) (*vector)->iov_base + cur;
n -= cur;
- if(c->out.vec->iov_len)
+ if((*vector)->iov_len)
break;
}
- if(!c->out.vec_len)
- c->out.vec = 0;
+ if(!*count)
+ *vector = 0;
assert(n == 0);
return 1;
}
diff --git a/xcb/src/xcbint.h b/xcb/src/xcbint.h
index 7c8f331..e6f540a 100644
--- a/xcb/src/xcbint.h
+++ b/xcb/src/xcbint.h
@@ -76,7 +76,7 @@ typedef struct _xcb_out {
int _xcb_out_init(_xcb_out *out);
void _xcb_out_destroy(_xcb_out *out);
-int _xcb_out_write(XCBConnection *c);
+int _xcb_out_write(XCBConnection *c, struct iovec **vector, int *count);
int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count);
int _xcb_out_flush(XCBConnection *c);
diff-tree c2f66ae5c599d1c76789ad4e0e0691e732490c52 (from 06683c10caa826b7397a4d9e5c2a2c0d1ee64870)
Author: Jamey Sharp <jamey at minilop.net>
Date: Tue Mar 7 21:19:58 2006 -0800
Fix off-by-one error that kept the last byte(s) of the output queue from being used.
diff --git a/xcb/src/xcb_out.c b/xcb/src/xcb_out.c
index 2494ef3..1faf2a5 100644
--- a/xcb/src/xcb_out.c
+++ b/xcb/src/xcb_out.c
@@ -237,7 +237,7 @@ int _xcb_out_write(XCBConnection *c)
int _xcb_out_write_block(XCBConnection *c, struct iovec *vector, size_t count)
{
assert(!c->out.vec && !c->out.vec_len);
- while(count && c->out.queue_len + vector[0].iov_len < sizeof(c->out.queue))
+ while(count && c->out.queue_len + vector[0].iov_len <= sizeof(c->out.queue))
{
memcpy(c->out.queue + c->out.queue_len, vector[0].iov_base, vector[0].iov_len);
c->out.queue_len += vector[0].iov_len;
More information about the xcb-commit
mailing list