geen polling meer - poging 1

This commit is contained in:
Thulinma 2010-11-07 21:22:08 +01:00
parent adf644445d
commit 1d33319e4d

View file

@ -4,9 +4,6 @@
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
//needed for epoll
#include <sys/epoll.h>
//for connection to server //for connection to server
#include "../sockets/SocketW.h" #include "../sockets/SocketW.h"
bool ready4data = false;//set to true when streaming starts bool ready4data = false;//set to true when streaming starts
@ -24,15 +21,10 @@ int main(){
unsigned int ftst; unsigned int ftst;
SWUnixSocket ss; SWUnixSocket ss;
int poller = epoll_create(1);
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP;
ev.data.fd = fileno(stdin);
epoll_ctl(poller, EPOLL_CTL_ADD, fileno(stdin), &ev);
struct epoll_event events[1];
//first timestamp set //first timestamp set
firsttime = getNowMS(); firsttime = getNowMS();
int lastcheck = getNowMS();
int rightnow = 0;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Doing handshake...\n"); fprintf(stderr, "Doing handshake...\n");
@ -52,7 +44,12 @@ int main(){
#endif #endif
while (!ferror(stdin) && !ferror(stdout)){ while (!ferror(stdin) && !ferror(stdout)){
//only parse input from stdin if available or not yet init'ed //only parse input from stdin if available or not yet init'ed
if ((!ready4data || (snd_cnt - snd_window_at >= snd_window_size)) && (epoll_wait(poller, events, 1, 100) > 0)){parseChunk();fflush(stdout);} rightnow = getNowMS();
if ((!ready4data || (snd_cnt - snd_window_at >= snd_window_size)) && (rightnow - lastcheck > 100)){
lastcheck = rightnow;
parseChunk();
fflush(stdout);
}
if (ready4data){ if (ready4data){
if (!inited){ if (!inited){
//we are ready, connect the socket! //we are ready, connect the socket!