Select poging nummer 1

This commit is contained in:
Thulinma 2010-11-07 16:57:27 +01:00
parent 86ebaa9b04
commit b11bfd7ea0

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"
@ -30,16 +30,15 @@ int main(){
unsigned int fts = 0; unsigned int fts = 0;
unsigned int ftst; unsigned int ftst;
SWUnixSocket ss; SWUnixSocket ss;
//fd_set pollset;
//struct timeval timeout;
//0 timeout - return immediately after select call
//timeout.tv_sec = 1; timeout.tv_usec = 0;
//FD_ZERO(&pollset);//clear the polling set
//FD_SET(0, &pollset);//add stdin to polling set
pollfd cinfd[1]; fd_set pollset;
cinfd[0].fd = fileno(stdin); struct timeval timeout;
cinfd[0].events = POLLIN; //0 timeout - return immediately after select call
timeout.tv_sec = 1; timeout.tv_usec = 0;
//pollfd cinfd[1];
//cinfd[0].fd = fileno(stdin);
//cinfd[0].events = POLLIN;
//first timestamp set //first timestamp set
firsttime = getNowMS(); firsttime = getNowMS();
@ -61,11 +60,11 @@ int main(){
fprintf(stderr, "Starting processing...\n"); fprintf(stderr, "Starting processing...\n");
#endif #endif
while (std::cin.good() && std::cout.good()){ while (std::cin.good() && std::cout.good()){
//select(1, &pollset, 0, 0, &timeout); FD_ZERO(&pollset);//clear the polling set
FD_SET(fileno(stdin), &pollset);//add stdin to polling set
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
//FD_ISSET(0, &pollset) || //NOTE: Polling does not work? WHY?!? WHY DAMN IT?!? 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)) && !stopparsing){fflush(stdout);parseChunk();fflush(stdout);}
if ((!ready4data || (snd_cnt - snd_window_at >= snd_window_size)) && poll(cinfd, 1, 100)){parseChunk();fflush(stdout);}
if (ready4data){ if (ready4data){
if (!inited){ if (!inited){
//we are ready, connect the socket! //we are ready, connect the socket!