Commit 48773298 authored by Christian Beier's avatar Christian Beier Committed by Johannes Schindelin

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: 's avatarChristian Beier <dontmind@freeshell.org>
Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parent 62ae6bb7
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment