c - Poll utilisation for blocking -


how block poll gets activated when press keyboard button.

because continues alone without event.

i have read manual that.

 while(i<5){         struct pollfd fds[2];     int timeout_msecs = 500;     int ret;       fds[0].fd=stdin_fileno;       fds[0].events=pollin | pollwrband | pollhup;      ret = poll(fds, 2, -1);     snprintf(buffer, 12,"%d",ret);      //write_raw(7,i,"z",1);                if(ret > 0) {               //  write_raw(3,i,"a",1);                   if (fds[0].revents & pollin) {                    // write_raw(4,i,"b",1);         //      write_raw(3,1,buffer,1);          posx=posx-1;               write_raw(posy,posx,"_|_",3);                sleep(5);               fds[0].events = pollhup;                  }                   if(fds[0].revents & pollhup){                write_raw(4,i,"a",1);                   }               }               fds[0].events=null;                i++;     } 

you have 1 file descriptor want monitor events, you're telling poll() have 2. need do

 ret = poll(fds, 1, -1); 

you have no use getting event when can write urgent data stdin (whatever mean, so

  fds[0].events=pollin | pollhup; 

this makes no sense

 fds[0].events=null;  

remove line.

your next issue register read events. never read input on stdin. if there's data available, event every time, until read available data.

your question states want keyboard events, reading data, code have calls write_raw() function, sounds writes data instead of reading data.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -