From: hyc Date: Thu, 7 Apr 2011 19:11:13 +0000 (+0000) Subject: Handle multiple sessions at once (ugly) X-Git-Tag: v2.4~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=041cf3f2c927b26dc4b27b5e802fbb89362ea3e2;p=rtmpdump Handle multiple sessions at once (ugly) git-svn-id: svn://svn.mplayerhq.hu/rtmpdump/trunk@567 400ebc74-4327-4243-bc38-086b20814532 --- diff --git a/rtmpsuck.c b/rtmpsuck.c index ce6d879..3293e8b 100644 --- a/rtmpsuck.c +++ b/rtmpsuck.c @@ -718,15 +718,15 @@ controlServerThread(void *unused) TFRET(); } -void doServe(STREAMING_SERVER * server, // server socket and state (our listening socket) - int sockfd // client connection socket - ) +TFTYPE doServe(void *arg) // server socket and state (our listening socket) { + STREAMING_SERVER *server = arg; RTMPPacket pc = { 0 }, ps = { 0 }; RTMPChunk rk = { 0 }; char *buf = NULL; unsigned int buflen = 131072; int paused = FALSE; + int sockfd = server->socket; // timeout for http requests fd_set rfds; @@ -990,7 +990,7 @@ quit: if (server->state == STREAMING_IN_PROGRESS) server->state = STREAMING_ACCEPTING; - return; + TFRET(); } TFTYPE @@ -1003,6 +1003,7 @@ serverThread(void *arg) { struct sockaddr_in addr; socklen_t addrlen = sizeof(struct sockaddr_in); + STREAMING_SERVER *srv2 = malloc(sizeof(STREAMING_SERVER)); int sockfd = accept(server->socket, (struct sockaddr *) &addr, &addrlen); @@ -1020,8 +1021,10 @@ serverThread(void *arg) RTMP_Log(RTMP_LOGDEBUG, "%s: accepted connection from %s\n", __FUNCTION__, inet_ntoa(addr.sin_addr)); #endif + *srv2 = *server; + srv2->socket = sockfd; /* Create a new thread and transfer the control to that */ - doServe(server, sockfd); + ThreadCreate(doServe, srv2); RTMP_Log(RTMP_LOGDEBUG, "%s: processed request\n", __FUNCTION__); } else