[rtmpdump] r121 - trunk/rtmpsrv.c
hyc
subversion at mplayerhq.hu
Mon Dec 28 09:59:16 CET 2009
Author: hyc
Date: Mon Dec 28 09:59:15 2009
New Revision: 121
Log:
Restore Windows compatibility patches
Modified:
trunk/rtmpsrv.c
Modified: trunk/rtmpsrv.c
==============================================================================
--- trunk/rtmpsrv.c Mon Dec 28 09:53:48 2009 (r120)
+++ trunk/rtmpsrv.c Mon Dec 28 09:59:15 2009 (r121)
@@ -36,8 +36,14 @@
#include "rtmp.h"
#include "parseurl.h"
+#ifdef WIN32
+#include <process.h>
+#else
+#ifdef linux
#include <linux/netfilter_ipv4.h>
+#endif
#include <pthread.h>
+#endif
#define RTMPDUMP_SERVER_VERSION "v2.0"
@@ -47,6 +53,20 @@
#define PACKET_SIZE 1024*1024
+#ifdef WIN32
+#define InitSockets() {\
+ WORD version; \
+ WSADATA wsaData; \
+ \
+ version = MAKEWORD(1,1); \
+ WSAStartup(version, &wsaData); }
+
+#define CleanupSockets() WSACleanup()
+#else
+#define InitSockets()
+#define CleanupSockets()
+#endif
+
enum
{
STREAMING_ACCEPTING,
@@ -428,6 +448,19 @@ ServePacket(STREAMING_SERVER *server, RT
return ret;
}
+#ifdef WIN32
+HANDLE
+ThreadCreate(void *(*routine) (void *), void *args)
+{
+ HANDLE thd;
+
+ thd = (HANDLE) _beginthread(routine, 0, args);
+ if (thd == -1L)
+ LogPrintf("%s, _beginthread failed with %d\n", __FUNCTION__, errno);
+
+ return thd;
+}
+#else
pthread_t
ThreadCreate(void *(*routine) (void *), void *args)
{
@@ -446,6 +479,7 @@ ThreadCreate(void *(*routine) (void *),
return id;
}
+#endif
void *
controlServerThread(void *unused)
@@ -545,15 +579,19 @@ serverThread(STREAMING_SERVER * server)
if (sockfd > 0)
{
+#ifdef linux
struct sockaddr_in dest;
char destch[16];
socklen_t destlen = sizeof(struct sockaddr_in);
getsockopt(sockfd, SOL_IP, SO_ORIGINAL_DST, &dest, &destlen);
strcpy(destch, inet_ntoa(dest.sin_addr));
- /* Create a new process and transfer the control to that */
Log(LOGDEBUG, "%s: accepted connection from %s to %s\n", __FUNCTION__,
inet_ntoa(addr.sin_addr), destch);
- /* Create a new process and transfer the control to that */
+#else
+ Log(LOGDEBUG, "%s: accepted connection from %s\n", __FUNCTION__,
+ inet_ntoa(addr.sin_addr));
+#endif
+ /* Create a new thread and transfer the control to that */
doServe(server, sockfd);
Log(LOGDEBUG, "%s: processed request\n", __FUNCTION__);
}
@@ -677,6 +715,8 @@ main(int argc, char **argv)
netstackdump_read = fopen("netstackdump_read", "wb");
#endif
+ InitSockets();
+
// start text UI
ThreadCreate(controlServerThread, 0);
@@ -696,6 +736,8 @@ main(int argc, char **argv)
}
Log(LOGDEBUG, "Done, exiting...");
+ CleanupSockets();
+
#ifdef _DEBUG
if (netstackdump != 0)
fclose(netstackdump);
More information about the rtmpdump
mailing list