EPolling poging 1

This commit is contained in:
Thulinma 2010-11-07 20:25:27 +01:00
parent f71a51cc1b
commit adf644445d

View file

@ -4,15 +4,8 @@
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
//needed for select //needed for epoll
#include <stdio.h> #include <sys/epoll.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
//needed for poll
#include <poll.h>
//for connection to server //for connection to server
#include "../sockets/SocketW.h" #include "../sockets/SocketW.h"
@ -31,10 +24,13 @@ int main(){
unsigned int ftst; unsigned int ftst;
SWUnixSocket ss; SWUnixSocket ss;
pollfd cinfd[1]; int poller = epoll_create(1);
cinfd[0].fd = fileno(stdin); struct epoll_event ev;
cinfd[0].events = POLLIN; 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();
@ -54,10 +50,9 @@ int main(){
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Starting processing...\n"); fprintf(stderr, "Starting processing...\n");
#endif #endif
int infile = fileno(stdin);
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)) && poll(cinfd, 1, 100)){parseChunk();fflush(stdout);} if ((!ready4data || (snd_cnt - snd_window_at >= snd_window_size)) && (epoll_wait(poller, events, 1, 100) > 0)){parseChunk();fflush(stdout);}
if (ready4data){ if (ready4data){
if (!inited){ if (!inited){
//we are ready, connect the socket! //we are ready, connect the socket!