diff options
author | Arvind Umrao <arvind.umrao@oracle.com> | 2011-11-04 15:42:05 +0530 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2012-01-11 18:01:29 +0100 |
commit | 769acff0da8b9859ebdf052dce80045465c7598c (patch) | |
tree | da557d02c65a7f3ba8dfd73284c0300f780593a1 /src/xcb_conn.c | |
parent | 9b4d6f30a339e2d18ebaea98149da81aba453216 (diff) |
Added more error states and removed global error_connection
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=41443
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=42304
I have added more xcb connection error states at xcb.h header.
Also I have removed global error_connection variable, and added
an interface that returns connection error state.
TBD:
I will segregate errors states in a separate header file and try to
provide more precise error states, in future. Also I will give patch
for libX11, in that patch xcb_connection_t::has_error will be passed
to default io handler of libX11. This value can then be used for
displaying error messages.
Reviewed-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Reviewed-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Arvind Umrao <arvind.umrao@oracle.com>
Diffstat (limited to 'src/xcb_conn.c')
-rw-r--r-- | src/xcb_conn.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/xcb_conn.c b/src/xcb_conn.c index 3ab5385..f79de33 100644 --- a/src/xcb_conn.c +++ b/src/xcb_conn.c @@ -59,7 +59,9 @@ typedef struct { uint16_t length; } xcb_setup_generic_t; -const int error_connection = 1; +static const int xcb_con_error = XCB_CONN_ERROR; +static const int xcb_con_closed_mem_er = XCB_CONN_CLOSED_MEM_INSUFFICIENT; +static const int xcb_con_closed_parse_er = XCB_CONN_CLOSED_PARSE_ERR; static int set_fd_flags(const int fd) { @@ -209,7 +211,7 @@ static int write_vec(xcb_connection_t *c, struct iovec **vector, int *count) if(n <= 0) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_ERROR); return 0; } @@ -263,7 +265,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info) if(fd >= FD_SETSIZE) /* would overflow in FD_SET */ { close(fd); - return (xcb_connection_t *) &error_connection; + return _xcb_conn_ret_error(XCB_CONN_ERROR); } #endif #endif /* !_WIN32*/ @@ -271,7 +273,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info) c = calloc(1, sizeof(xcb_connection_t)); if(!c) { close(fd); - return (xcb_connection_t *) &error_connection; + return _xcb_conn_ret_error(XCB_CONN_CLOSED_MEM_INSUFFICIENT) ; } c->fd = fd; @@ -288,7 +290,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info) )) { xcb_disconnect(c); - return (xcb_connection_t *) &error_connection; + return _xcb_conn_ret_error(XCB_CONN_ERROR); } return c; @@ -296,7 +298,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info) void xcb_disconnect(xcb_connection_t *c) { - if(c == (xcb_connection_t *) &error_connection) + if(c->has_error) return; free(c->setup); @@ -317,9 +319,34 @@ void xcb_disconnect(xcb_connection_t *c) /* Private interface */ -void _xcb_conn_shutdown(xcb_connection_t *c) +void _xcb_conn_shutdown(xcb_connection_t *c, int err) { - c->has_error = 1; + c->has_error = err; +} + +/* Return connection error state. + * To make thread-safe, I need a seperate static + * variable for every possible error. + */ +xcb_connection_t *_xcb_conn_ret_error(int err) +{ + + switch(err) + { + case XCB_CONN_CLOSED_MEM_INSUFFICIENT: + { + return (xcb_connection_t *) &xcb_con_closed_mem_er; + } + case XCB_CONN_CLOSED_PARSE_ERR: + { + return (xcb_connection_t *) &xcb_con_closed_parse_er; + } + case XCB_CONN_ERROR: + default: + { + return (xcb_connection_t *) &xcb_con_error; + } + } } int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count) @@ -380,7 +407,7 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec } while (ret == -1 && errno == EINTR); if(ret < 0) { - _xcb_conn_shutdown(c); + _xcb_conn_shutdown(c, XCB_CONN_ERROR); ret = 0; } pthread_mutex_lock(&c->iolock); |