[Xcb] [PATCH 3/3] Use WSAStartup()/WSACleanup() on WIN32
Jon TURNEY
jon.turney at dronecode.org.uk
Fri Jan 6 10:52:58 PST 2012
From: Ryan Pavlik <rpavlik at iastate.edu>
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
src/xcb_conn.c | 4 ++++
src/xcb_util.c | 14 +++++++++++++-
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/src/xcb_conn.c b/src/xcb_conn.c
index 3ab5385..f684438 100644
--- a/src/xcb_conn.c
+++ b/src/xcb_conn.c
@@ -313,6 +313,10 @@ void xcb_disconnect(xcb_connection_t *c)
_xcb_xid_destroy(c);
free(c);
+
+#ifdef _WIN32
+ WSACleanup();
+#endif
}
/* Private interface */
diff --git a/src/xcb_util.c b/src/xcb_util.c
index 62c51e1..49b0226 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -426,11 +426,23 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
if(!parsed) {
c = (xcb_connection_t *) &error_connection;
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_connection_t *) &error_connection;
+#ifdef _WIN32
+ WSACleanup();
+#endif
goto out;
}
--
1.7.5.1
More information about the Xcb
mailing list