aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2015-03-17 17:06:22 +0100
committerPierre Ossman <ossman@cendio.se>2015-03-17 17:18:50 +0100
commit3ab5db438436a1a68ae76fe8799e1a3cbe8bde0b (patch)
tree06e899edb40ae4b7278cc1ed434cce16d3dbb559 /common
parenta08a8436a95161b6f732601d77340f029ee8bf08 (diff)
downloadtigervnc-3ab5db438436a1a68ae76fe8799e1a3cbe8bde0b.tar.gz
tigervnc-3ab5db438436a1a68ae76fe8799e1a3cbe8bde0b.zip
Replacement for dup() on Windows
It doesn't work on sockets, which require a bit more care.
Diffstat (limited to 'common')
-rw-r--r--common/network/TcpSocket.cxx21
1 files changed, 19 insertions, 2 deletions
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index bd9971c1..1ed6df08 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -120,6 +120,23 @@ static void initSockets() {
}
+// -=- Socket duplication help for Windows
+static int dupsocket(int fd)
+{
+#ifdef WIN32
+ int ret;
+ WSAPROTOCOL_INFO info;
+ ret = WSADuplicateSocket(fd, GetCurrentProcessId(), &info);
+ if (ret != 0)
+ throw SocketException("unable to duplicate socket", errorNumber);
+ return WSASocket(info.iAddressFamily, info.iSocketType, info.iProtocol,
+ &info, 0, 0);
+#else
+ return dup(fd);
+#endif
+}
+
+
// -=- TcpSocket
TcpSocket::TcpSocket(int sock, bool close)
@@ -432,7 +449,7 @@ TcpListener::TcpListener(int sock)
TcpListener::TcpListener(const TcpListener& other)
{
- fd = dup (other.fd);
+ fd = dupsocket (other.fd);
// Hope TcpListener::shutdown(other) doesn't get called...
}
@@ -441,7 +458,7 @@ TcpListener& TcpListener::operator= (const TcpListener& other)
if (this != &other)
{
closesocket (fd);
- fd = dup (other.fd);
+ fd = dupsocket (other.fd);
// Hope TcpListener::shutdown(other) doesn't get called...
}
return *this;