Use WSAStartup()/WSACleanup() on WIN32

The alternative is to use these in every WIN32 application which uses xcb. Doing
it this way should be safe, as, according to MSDN, "There must be a call to
WSACleanup for each successful call to WSAStartup. Only the final WSACleanup
function call performs the actual cleanup. The preceding calls simply decrement
an internal reference count"

(We should probably also include ws2_32 in Libs.private for libxcb, as anything
which links with libxcb will also need that, but there seems to be some pkg-config
issues to resolve first...)

v2: Check for errors so WSAStartup()/WSACleanup() uses are balanced
v3: Use same indentation style as surrounding code

Reviewed-by: Peter Harris <pharris@opentext.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Ryan Pavlik 2012-01-11 18:06:50 +01:00 committed by Julien Danjou
parent 0e9246def5
commit 31b57676e8
2 changed files with 16 additions and 1 deletions

View File

@ -315,6 +315,10 @@ void xcb_disconnect(xcb_connection_t *c)
_xcb_xid_destroy(c);
free(c);
#ifdef _WIN32
WSACleanup();
#endif
}
/* Private interface */

View File

@ -426,11 +426,22 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
if(!parsed) {
c = _xcb_conn_ret_error(XCB_CONN_CLOSED_PARSE_ERR);
goto out;
} else
} else {
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
c = (xcb_connection_t *) &error_connection;
goto out;
}
#endif
fd = _xcb_open(host, protocol, display);
}
if(fd == -1) {
c = _xcb_conn_ret_error(XCB_CONN_ERROR);
#ifdef _WIN32
WSACleanup();
#endif
goto out;
}