Make all public functions do nothing on an error connection.

This commit is contained in:
Jamey Sharp 2006-09-15 01:09:27 -07:00
parent 0aa96bfc7a
commit 7f71bf9c0f
6 changed files with 50 additions and 13 deletions

View 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);

View 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);

View 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))
{

View 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);

View 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)
{

View File

@ -28,10 +28,14 @@
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;
}