epoll fully removed - needs testing still

This commit is contained in:
Thulinma 2011-09-22 07:09:43 +02:00
parent f45d02124a
commit 1640dbb933
3 changed files with 25 additions and 39 deletions

View file

@ -140,7 +140,7 @@ namespace Buffer{
} }
std::string waiting_ip = ""; std::string waiting_ip = "";
bool ip_waiting = false; bool ip_waiting = false;
int ip_input = -1; Socket::Connection ip_input;
if (argc >= 4){ if (argc >= 4){
waiting_ip += argv[3]; waiting_ip += argv[3];
ip_waiting = true; ip_waiting = true;
@ -174,7 +174,7 @@ namespace Buffer{
if ( if (
(!ip_waiting && (!ip_waiting &&
(std_input.canRead()) && ringbuf[current_buffer]->FLV.FileLoader(stdin) (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) ringbuf[current_buffer]->FLV.SockLoader(ip_input)
) )
){ ){
@ -217,6 +217,7 @@ namespace Buffer{
lastproper = current_buffer; lastproper = current_buffer;
} }
} }
if (loopcount > 5){gotData = true;}
//keep track of buffers //keep track of buffers
ringbuf[current_buffer]->number = loopcount; ringbuf[current_buffer]->number = loopcount;
current_buffer++; current_buffer++;
@ -236,18 +237,24 @@ namespace Buffer{
if (!users.back().S.write(FLV::Header, 13)){ if (!users.back().S.write(FLV::Header, 13)){
users.back().Disconnect("failed to receive the header!"); users.back().Disconnect("failed to receive the header!");
}else{ }else{
if (metadata.len > 0){
if (!users.back().S.write(metadata.data, metadata.len)){ if (!users.back().S.write(metadata.data, metadata.len)){
users.back().Disconnect("failed to receive metadata!"); users.back().Disconnect("failed to receive metadata!");
} }
}
if (audio_init.len > 0){
if (!users.back().S.write(audio_init.data, audio_init.len)){ if (!users.back().S.write(audio_init.data, audio_init.len)){
users.back().Disconnect("failed to receive audio init!"); users.back().Disconnect("failed to receive audio init!");
} }
}
if (video_init.len > 0){
if (!users.back().S.write(video_init.data, video_init.len)){ if (!users.back().S.write(video_init.data, video_init.len)){
users.back().Disconnect("failed to receive video init!"); users.back().Disconnect("failed to receive video init!");
} }
} }
} }
} }
}
//send all connections what they need, if and when they need it //send all connections what they need, if and when they need it
if (users.size() > 0){ if (users.size() > 0){
@ -265,7 +272,13 @@ namespace Buffer{
if (tmp != ""){ if (tmp != ""){
std::cout << "Push attempt from IP " << tmp << std::endl; std::cout << "Push attempt from IP " << tmp << std::endl;
if (tmp == waiting_ip){ if (tmp == waiting_ip){
if (!ip_input.connected()){
std::cout << "Push accepted!" << std::endl; 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{ }else{
std::cout << "Push denied!" << std::endl; std::cout << "Push denied!" << std::endl;
} }

View file

@ -9,7 +9,6 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/epoll.h>
#include <getopt.h> #include <getopt.h>
#include <ctime> #include <ctime>
#include "../util/socket.h" #include "../util/socket.h"
@ -134,15 +133,6 @@ namespace Connector_HTTP{
bool FlashFirstAudio = false; bool FlashFirstAudio = false;
HTTP::Parser HTTP_R, HTTP_S;//HTTP Receiver en HTTP Sender. 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 Movie = "";
std::string Quality = ""; std::string Quality = "";
int Segment = -1; int Segment = -1;
@ -221,9 +211,6 @@ namespace Connector_HTTP{
conn.close(); conn.close();
break; break;
} }
ev.events = EPOLLIN;
ev.data.fd = ss.getSocket();
epoll_ctl(sspoller, EPOLL_CTL_ADD, ss.getSocket(), &ev);
#if DEBUG >= 3 #if DEBUG >= 3
fprintf(stderr, "Everything connected, starting to send video data...\n"); fprintf(stderr, "Everything connected, starting to send video data...\n");
#endif #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); fprintf(stderr, "Sending a video fragment. %i left in buffer, %i requested\n", (int)Flash_FragBuffer.size(), Flash_RequestPending);
#endif #endif
} }
retval = epoll_wait(sspoller, events, 1, 1); ss.canRead();
switch (ss.ready()){ switch (ss.ready()){
case -1: case -1:
conn.close(); conn.close();

View file

@ -9,7 +9,6 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/epoll.h>
#include <getopt.h> #include <getopt.h>
#include "../util/socket.h" #include "../util/socket.h"
#include "../util/flv_tag.h" #include "../util/flv_tag.h"
@ -59,20 +58,10 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){
return 0; 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){ while (Socket.connected() && !FLV::Parse_Error){
//only parse input if available or not yet init'ed //only parse input if available or not yet init'ed
//rightnow = getNowMS(); //rightnow = getNowMS();
retval = epoll_wait(poller, events, 1, 1); if (Socket.canRead() || !ready4data){// || (snd_cnt - snd_window_at >= snd_window_size)
if ((retval > 0) || !ready4data){// || (snd_cnt - snd_window_at >= snd_window_size)
switch (Socket.ready()){ switch (Socket.ready()){
case -1: break; //disconnected case -1: break; //disconnected
case 0: break; //not ready yet case 0: break; //not ready yet
@ -90,15 +79,12 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){
Socket.close();//disconnect user Socket.close();//disconnect user
break; break;
} }
ev.events = EPOLLIN;
ev.data.fd = SS.getSocket();
epoll_ctl(sspoller, EPOLL_CTL_ADD, SS.getSocket(), &ev);
#if DEBUG >= 3 #if DEBUG >= 3
fprintf(stderr, "Everything connected, starting to send video data...\n"); fprintf(stderr, "Everything connected, starting to send video data...\n");
#endif #endif
inited = true; inited = true;
} }
retval = epoll_wait(sspoller, events, 1, 1); SS.canRead();
switch (SS.ready()){ switch (SS.ready()){
case -1: case -1:
#if DEBUG >= 1 #if DEBUG >= 1