XCB: Print error code on Xlib I/O errors

When Xlib detects that its underlying XCB connection got into an error
state, it calls its I/O error handler. However, the default
implementation doesn't print the error code from XCB which might be
useful for debugging.

This commit adds an I/O error handler which prints the error code from
XCB with a string describing the error and then calls Xlib's default
error handler.

Change-Id: I7f1fb3f1e8d0fdc3ac9db03ae7d154330c31db0c
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
bb10
Uli Schlachter 2014-04-08 23:12:28 +02:00 committed by The Qt Project
parent 02ecd3ae40
commit b1afb91ffe
1 changed files with 28 additions and 0 deletions

View File

@ -93,10 +93,37 @@
QT_BEGIN_NAMESPACE
#ifdef XCB_USE_XLIB
static const char * const xcbConnectionErrors[] = {
"No error", /* Error 0 */
"I/O error", /* XCB_CONN_ERROR */
"Unsupported extension used", /* XCB_CONN_CLOSED_EXT_NOTSUPPORTED */
"Out of memory", /* XCB_CONN_CLOSED_MEM_INSUFFICIENT */
"Maximum allowed requested length exceeded", /* XCB_CONN_CLOSED_REQ_LEN_EXCEED */
"Failed to parse display string", /* XCB_CONN_CLOSED_PARSE_ERR */
"No such screen on display", /* XCB_CONN_CLOSED_INVALID_SCREEN */
"Error during FD passing" /* XCB_CONN_CLOSED_FDPASSING_FAILED */
};
static int nullErrorHandler(Display *, XErrorEvent *)
{
return 0;
}
static int ioErrorHandler(Display *dpy)
{
xcb_connection_t *conn = XGetXCBConnection(dpy);
if (conn != NULL) {
/* Print a message with a textual description of the error */
int code = xcb_connection_has_error(conn);
const char *str = "Unknown error";
int arrayLength = sizeof(xcbConnectionErrors) / sizeof(xcbConnectionErrors[0]);
if (code >= 0 && code < arrayLength)
str = xcbConnectionErrors[code];
qWarning("The X11 connection broke: %s (code %d)", str, code);
}
return _XDefaultIOError(dpy);
}
#endif
QXcbScreen* QXcbConnection::findOrCreateScreen(QList<QXcbScreen *>& newScreens,
@ -284,6 +311,7 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra
m_connection = XGetXCBConnection(dpy);
XSetEventQueueOwner(dpy, XCBOwnsEventQueue);
XSetErrorHandler(nullErrorHandler);
XSetIOErrorHandler(ioErrorHandler);
m_xlib_display = dpy;
}
#else