From 1640dbb93300efffa099f8390612c1af0d76e09f Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 22 Sep 2011 07:09:43 +0200 Subject: [PATCH] epoll fully removed - needs testing still --- Buffer/main.cpp | 31 ++++++++++++++++++++++--------- Connector_HTTP/main.cpp | 15 +-------------- Connector_RTMP/main.cpp | 18 ++---------------- 3 files changed, 25 insertions(+), 39 deletions(-) diff --git a/Buffer/main.cpp b/Buffer/main.cpp index 4dcdfd27..bcc0f68f 100644 --- a/Buffer/main.cpp +++ b/Buffer/main.cpp @@ -140,7 +140,7 @@ namespace Buffer{ } std::string waiting_ip = ""; bool ip_waiting = false; - int ip_input = -1; + Socket::Connection ip_input; if (argc >= 4){ waiting_ip += argv[3]; ip_waiting = true; @@ -174,7 +174,7 @@ namespace Buffer{ if ( (!ip_waiting && (std_input.canRead()) && ringbuf[current_buffer]->FLV.FileLoader(stdin) - ) || (ip_waiting && (ip_input > -1) && + ) || (ip_waiting && (ip_input.connected()) && ringbuf[current_buffer]->FLV.SockLoader(ip_input) ) ){ @@ -217,6 +217,7 @@ namespace Buffer{ lastproper = current_buffer; } } + if (loopcount > 5){gotData = true;} //keep track of buffers ringbuf[current_buffer]->number = loopcount; current_buffer++; @@ -236,14 +237,20 @@ namespace Buffer{ if (!users.back().S.write(FLV::Header, 13)){ users.back().Disconnect("failed to receive the header!"); }else{ - if (!users.back().S.write(metadata.data, metadata.len)){ - users.back().Disconnect("failed to receive metadata!"); + if (metadata.len > 0){ + if (!users.back().S.write(metadata.data, metadata.len)){ + users.back().Disconnect("failed to receive metadata!"); + } } - if (!users.back().S.write(audio_init.data, audio_init.len)){ - users.back().Disconnect("failed to receive audio init!"); + if (audio_init.len > 0){ + if (!users.back().S.write(audio_init.data, audio_init.len)){ + users.back().Disconnect("failed to receive audio init!"); + } } - if (!users.back().S.write(video_init.data, video_init.len)){ - users.back().Disconnect("failed to receive video init!"); + if (video_init.len > 0){ + if (!users.back().S.write(video_init.data, video_init.len)){ + users.back().Disconnect("failed to receive video init!"); + } } } } @@ -265,7 +272,13 @@ namespace Buffer{ if (tmp != ""){ std::cout << "Push attempt from IP " << tmp << std::endl; if (tmp == waiting_ip){ - std::cout << "Push accepted!" << std::endl; + if (!ip_input.connected()){ + std::cout << "Push accepted!" << std::endl; + ip_input = (*usersIt).S; + users.erase(usersIt); break; + }else{ + std::cout << "Push denied - push already in progress!" << std::endl; + } }else{ std::cout << "Push denied!" << std::endl; } diff --git a/Connector_HTTP/main.cpp b/Connector_HTTP/main.cpp index f45ec5e2..b11c7db9 100644 --- a/Connector_HTTP/main.cpp +++ b/Connector_HTTP/main.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include "../util/socket.h" @@ -134,15 +133,6 @@ namespace Connector_HTTP{ bool FlashFirstAudio = false; HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender. - int retval; - int poller = epoll_create(1); - int sspoller = epoll_create(1); - struct epoll_event ev; - ev.events = EPOLLIN; - ev.data.fd = conn.getSocket(); - epoll_ctl(poller, EPOLL_CTL_ADD, conn.getSocket(), &ev); - struct epoll_event events[1]; - std::string Movie = ""; std::string Quality = ""; int Segment = -1; @@ -221,9 +211,6 @@ namespace Connector_HTTP{ conn.close(); break; } - ev.events = EPOLLIN; - ev.data.fd = ss.getSocket(); - epoll_ctl(sspoller, EPOLL_CTL_ADD, ss.getSocket(), &ev); #if DEBUG >= 3 fprintf(stderr, "Everything connected, starting to send video data...\n"); #endif @@ -240,7 +227,7 @@ namespace Connector_HTTP{ fprintf(stderr, "Sending a video fragment. %i left in buffer, %i requested\n", (int)Flash_FragBuffer.size(), Flash_RequestPending); #endif } - retval = epoll_wait(sspoller, events, 1, 1); + ss.canRead(); switch (ss.ready()){ case -1: conn.close(); diff --git a/Connector_RTMP/main.cpp b/Connector_RTMP/main.cpp index 07432279..b7fba9a0 100644 --- a/Connector_RTMP/main.cpp +++ b/Connector_RTMP/main.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include "../util/socket.h" #include "../util/flv_tag.h" @@ -59,20 +58,10 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){ return 0; } - int retval; - int poller = epoll_create(1); - int sspoller = epoll_create(1); - struct epoll_event ev; - ev.events = EPOLLIN; - ev.data.fd = Socket.getSocket(); - epoll_ctl(poller, EPOLL_CTL_ADD, Socket.getSocket(), &ev); - struct epoll_event events[1]; - while (Socket.connected() && !FLV::Parse_Error){ //only parse input if available or not yet init'ed //rightnow = getNowMS(); - retval = epoll_wait(poller, events, 1, 1); - if ((retval > 0) || !ready4data){// || (snd_cnt - snd_window_at >= snd_window_size) + if (Socket.canRead() || !ready4data){// || (snd_cnt - snd_window_at >= snd_window_size) switch (Socket.ready()){ case -1: break; //disconnected case 0: break; //not ready yet @@ -90,15 +79,12 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){ Socket.close();//disconnect user break; } - ev.events = EPOLLIN; - ev.data.fd = SS.getSocket(); - epoll_ctl(sspoller, EPOLL_CTL_ADD, SS.getSocket(), &ev); #if DEBUG >= 3 fprintf(stderr, "Everything connected, starting to send video data...\n"); #endif inited = true; } - retval = epoll_wait(sspoller, events, 1, 1); + SS.canRead(); switch (SS.ready()){ case -1: #if DEBUG >= 1