summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Beier <dontmind@freeshell.org>2009-10-30 15:51:58 +0100
committerJohannes Schindelin <johannes.schindelin@gmx.de>2009-10-30 17:18:02 +0100
commit487732981204999a4ca4be7ebfc565cd64e4bf92 (patch)
treedba43470e404464b52dc75bdeedf7f7cc3ee3837
parent62ae6bb7bef5a2f2a20cd2e39521e58e9874f189 (diff)
downloadlibvncserver-487732981204999a4ca4be7ebfc565cd64e4bf92.zip
libvncserver-487732981204999a4ca4be7ebfc565cd64e4bf92.tar.gz
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 <dontmind@freeshell.org> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
-rw-r--r--libvncclient/sockets.c17
1 files 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");
OpenPOWER on IntegriCloud