From 487732981204999a4ca4be7ebfc565cd64e4bf92 Mon Sep 17 00:00:00 2001 From: Christian Beier Date: Fri, 30 Oct 2009 15:51:58 +0100 Subject: libvncclient: make listenAtTCPPort() work under windows. Actually, initSockets() has to be called everywhere we possibly use sockets the first time. Also fix return value of initSockets(). Signed-off-by: Christian Beier Signed-off-by: Johannes Schindelin --- libvncclient/sockets.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index bdfd811..d1c507d 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -246,26 +246,27 @@ WriteToRFBServer(rfbClient* client, char *buf, int n) } -/* - * ConnectToTcpAddr connects to the given TCP port. - */ static int initSockets() { #ifdef WIN32 WSADATA trash; static rfbBool WSAinitted=FALSE; if(!WSAinitted) { - WSAinitted=TRUE; int i=WSAStartup(MAKEWORD(2,0),&trash); if(i!=0) { rfbClientErr("Couldn't init Windows Sockets\n"); - return -1; + return 0; } + WSAinitted=TRUE; } #endif return 1; } +/* + * ConnectToTcpAddr connects to the given TCP port. + */ + int ConnectClientToTcpAddr(unsigned int host, int port) { @@ -349,6 +350,9 @@ FindFreeTcpPort(void) addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); + if (!initSockets()) + return -1; + sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { rfbClientErr(": FindFreeTcpPort: socket\n"); @@ -383,6 +387,9 @@ ListenAtTcpPort(int port) addr.sin_port = htons(port); addr.sin_addr.s_addr = htonl(INADDR_ANY); + if (!initSockets()) + return -1; + sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { rfbClientErr("ListenAtTcpPort: socket\n"); -- cgit v1.2.3