[xiph-commits] r17363 - icecast/branches/kh/net
karl at svn.xiph.org
karl at svn.xiph.org
Mon Aug 16 17:18:23 PDT 2010
Author: karl
Date: 2010-08-16 17:18:22 -0700 (Mon, 16 Aug 2010)
New Revision: 17363
Modified:
icecast/branches/kh/net/sock.c
icecast/branches/kh/net/sock.h
Log:
emulate pipe FDs using sockets on win32 as select does not work on pipe FDs
Modified: icecast/branches/kh/net/sock.c
===================================================================
--- icecast/branches/kh/net/sock.c 2010-08-04 00:59:21 UTC (rev 17362)
+++ icecast/branches/kh/net/sock.c 2010-08-17 00:18:22 UTC (rev 17363)
@@ -314,6 +314,7 @@
return writev (sock, iov, count);
}
+/* win32 has WSAsend for vectored writes */
#else
ssize_t sock_writev (sock_t sock, const struct iovec *iov, size_t count)
@@ -975,3 +976,41 @@
return ret;
}
+#ifdef _WIN32
+int sock_create_pipe_emulation (int handles[2])
+{
+ sock_t s;
+ struct sockaddr_in serv_addr;
+ int len = sizeof(serv_addr);
+
+ do
+ {
+ handles[0] = handles[1] = INVALID_SOCKET;
+ if ((s = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+ break;
+ memset((void *) &serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ serv_addr.sin_port = htons(0);
+ serv_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ if (bind(s, (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
+ break;
+ sock_listen (s,5);
+ if (getsockname(s, (SOCKADDR *) & serv_addr, &len) == INVALID_SOCKET)
+ break;
+ if ((handles[1] = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET)
+ break;
+ if (connect(handles[1], (SOCKADDR *) & serv_addr, len) == SOCKET_ERROR)
+ break;
+ if ((handles[0] = accept(s, (SOCKADDR *) & serv_addr, &len)) == INVALID_SOCKET)
+ break;
+ sock_close (s);
+ return 0;
+ } while(0);
+ if (handles[0] != INVALID_SOCKET)
+ sock_close (handles[0]);
+ if (handles[1] != INVALID_SOCKET)
+ sock_close (handles[1]);
+ sock_close (s);
+ return -1;
+}
+#endif
Modified: icecast/branches/kh/net/sock.h
===================================================================
--- icecast/branches/kh/net/sock.h 2010-08-04 00:59:21 UTC (rev 17362)
+++ icecast/branches/kh/net/sock.h 2010-08-17 00:18:22 UTC (rev 17363)
@@ -98,6 +98,7 @@
# define sock_listen _mangle(sock_listen)
# define sock_set_send_buffer _mangle(sock_set_send_buffer)
# define sock_accept _mangle(sock_accept)
+# define sock_create_pipe_emulation _mangle(sock_create_pipe_emulation)
#endif
/* Misc socket functions */
@@ -117,6 +118,7 @@
int sock_set_delay(sock_t sock);
void sock_set_error(int val);
int sock_close(sock_t sock);
+int sock_create_pipe_emulation (int handles[2]);
/* Connection related socket functions */
sock_t sock_connect_wto(const char *hostname, int port, int timeout);
More information about the commits
mailing list