Polling poging 1
This commit is contained in:
parent
de6a80253b
commit
5c3ddab657
1 changed files with 8 additions and 7 deletions
|
@ -12,7 +12,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
//needed for poll
|
||||
//#include <poll.h>
|
||||
#include <poll.h>
|
||||
|
||||
//for connection to server
|
||||
#include "../sockets/SocketW.h"
|
||||
|
@ -34,9 +34,9 @@ int main(){
|
|||
fd_set pollset;
|
||||
struct timeval timeout;
|
||||
|
||||
//pollfd cinfd[1];
|
||||
//cinfd[0].fd = fileno(stdin);
|
||||
//cinfd[0].events = POLLIN;
|
||||
pollfd cinfd[1];
|
||||
cinfd[0].fd = fileno(stdin);
|
||||
cinfd[0].events = POLLIN;
|
||||
|
||||
//first timestamp set
|
||||
firsttime = getNowMS();
|
||||
|
@ -57,13 +57,14 @@ int main(){
|
|||
#ifdef DEBUG
|
||||
fprintf(stderr, "Starting processing...\n");
|
||||
#endif
|
||||
int infile = fileno(stdin);
|
||||
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;
|
||||
FD_ZERO(&pollset);//clear the polling set
|
||||
FD_SET(infile, &pollset);//add stdin to polling set
|
||||
select(1, &pollset, 0, 0, &timeout);
|
||||
//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 (!inited){
|
||||
//we are ready, connect the socket!
|
||||
|
|
Loading…
Add table
Reference in a new issue