Buffer met eerste poging epoll support

This commit is contained in:
Thulinma 2010-11-07 21:41:57 +01:00
parent 1d33319e4d
commit ea588b0791

View file

@ -11,6 +11,8 @@
#include "../util/flv.cpp" //FLV format parser #include "../util/flv.cpp" //FLV format parser
#include "user.cpp" #include "user.cpp"
#include <sys/epoll.h>
int get_empty( user ** list, int amount ) { int get_empty( user ** list, int amount ) {
for (int i = 0; i < amount; i++ ){ for (int i = 0; i < amount; i++ ){
if (!list[i]->is_connected){return i;} if (!list[i]->is_connected){return i;}
@ -51,14 +53,23 @@ int main( int argc, char * argv[] ) {
bool gotAudioInfo = false; bool gotAudioInfo = false;
//set stdin to be nonblocking //set stdin to be nonblocking
int flags = fcntl(0, F_GETFL, 0); //int flags = fcntl(0, F_GETFL, 0);
flags |= O_NONBLOCK; //flags |= O_NONBLOCK;
fcntl(0, F_SETFL, flags); //fcntl(0, F_SETFL, flags);
int infile = fileno(stdin);
int poller = epoll_create(1);
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
ev.data.fd = infile;
epoll_ctl(poller, EPOLL_CTL_ADD, infile, &ev);
struct epoll_event events[1];
while(!feof(stdin) && !All_Hell_Broke_Loose){ while(!feof(stdin) && !All_Hell_Broke_Loose){
//invalidate the current buffer //invalidate the current buffer
ringbuf[current_buffer]->number = -1; ringbuf[current_buffer]->number = -1;
if (FLV_GetPacket(ringbuf[current_buffer]->FLV)){ if ((epoll_wait(poller, events, 1, 100) > 0) && FLV_GetPacket(ringbuf[current_buffer]->FLV)){
loopcount ++; loopcount ++;
packtype = ringbuf[current_buffer]->FLV->data[0]; packtype = ringbuf[current_buffer]->FLV->data[0];
//store metadata, if available //store metadata, if available