Polling poging 1

This commit is contained in:
Thulinma 2010-11-07 17:32:23 +01:00
parent de6a80253b
commit 5c3ddab657

View file

@ -12,7 +12,7 @@
#include <unistd.h> #include <unistd.h>
//needed for poll //needed for poll
//#include <poll.h> #include <poll.h>
//for connection to server //for connection to server
#include "../sockets/SocketW.h" #include "../sockets/SocketW.h"
@ -34,9 +34,9 @@ int main(){
fd_set pollset; fd_set pollset;
struct timeval timeout; struct timeval timeout;
//pollfd cinfd[1]; pollfd cinfd[1];
//cinfd[0].fd = fileno(stdin); cinfd[0].fd = fileno(stdin);
//cinfd[0].events = POLLIN; cinfd[0].events = POLLIN;
//first timestamp set //first timestamp set
firsttime = getNowMS(); firsttime = getNowMS();
@ -57,13 +57,14 @@ int main(){
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Starting processing...\n"); fprintf(stderr, "Starting processing...\n");
#endif #endif
int infile = fileno(stdin);
while (std::cin.good() && std::cout.good()){ while (std::cin.good() && std::cout.good()){
FD_ZERO(&pollset);//clear the polling set
FD_SET(fileno(stdin), &pollset);//add stdin to polling set
timeout.tv_sec = 1; timeout.tv_usec = 0; timeout.tv_sec = 1; timeout.tv_usec = 0;
FD_ZERO(&pollset);//clear the polling set
FD_SET(infile, &pollset);//add stdin to polling set
select(1, &pollset, 0, 0, &timeout); select(1, &pollset, 0, 0, &timeout);
//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)) && FD_ISSET(0, &pollset)){parseChunk();fflush(stdout);} if ((!ready4data || (snd_cnt - snd_window_at >= snd_window_size)) && poll(cinfd, 1, 500)){parseChunk();fflush(stdout);}
if (ready4data){ if (ready4data){
if (!inited){ if (!inited){
//we are ready, connect the socket! //we are ready, connect the socket!