Only _xcb_conn_wait calls _xcb_out_write now, so move it to xcb_conn.c and make it static.

This commit is contained in:
Jamey Sharp 2006-03-12 13:20:29 -08:00
parent fb61c94d68
commit b83f18a4cc
3 changed files with 30 additions and 31 deletions

View File

@ -33,6 +33,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/fcntl.h> #include <sys/fcntl.h>
#include <errno.h>
#include "xcb.h" #include "xcb.h"
#include "xcbint.h" #include "xcbint.h"
@ -138,6 +139,34 @@ static int read_setup(XCBConnection *c)
return 1; 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 */ /* Public interface */
XCBConnSetupSuccessRep *XCBGetSetup(XCBConnection *c) XCBConnSetupSuccessRep *XCBGetSetup(XCBConnection *c)
@ -233,7 +262,7 @@ int _xcb_conn_wait(XCBConnection *c, pthread_cond_t *cond, struct iovec **vector
ret = ret && _xcb_in_read(c); ret = ret && _xcb_in_read(c);
if(FD_ISSET(c->fd, &wfds)) if(FD_ISSET(c->fd, &wfds))
ret = ret && _xcb_out_write(c, vector, count); ret = ret && write_vec(c, vector, count);
} }
if(count) if(count)

View File

@ -29,7 +29,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "xcb.h" #include "xcb.h"
#include "xcbext.h" #include "xcbext.h"
@ -224,34 +223,6 @@ void _xcb_out_destroy(_xcb_out *out)
pthread_mutex_destroy(&out->reqlenlock); 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 _xcb_out_send(XCBConnection *c, struct iovec **vector, int *count)
{ {
int ret = 1; int ret = 1;

View File

@ -74,7 +74,6 @@ typedef struct _xcb_out {
int _xcb_out_init(_xcb_out *out); int _xcb_out_init(_xcb_out *out);
void _xcb_out_destroy(_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_send(XCBConnection *c, struct iovec **vector, int *count);
int _xcb_out_flush_to(XCBConnection *c, unsigned int request); int _xcb_out_flush_to(XCBConnection *c, unsigned int request);