简体   繁体   中英

Select not working Unix C

fd_set read_fds;
struct timeval tv;
while(1){
    tv.tv_sec = 3;
    tv.tv_usec = 0;
    FD_ZERO(&read_fds);
    FD_SET(0,&read_fds);
    FD_SET(pipelogin,&read_fds);
    nfd = select(1,&read_fds,NULL,NULL,&tv);
    if(FD_ISSET(0,&read_fds)){
         printf("Comando"); }
         //comandos();
    if(FD_ISSET(pipelogin,&read_fds)){
         printf("Login"); }
         //VerificaLogin(pipelogin);
}

My function "comandos()" just read commands from user and do something and function VerificaLogin(pipelogin) just let the user login or not. I can only user "comando" once and VerificaLogin only works after the first "comando"...Can someone tell me what's wrong in here ? Sorry for bad english.

The select function is a status-reporting function. Unless the status changes, it will continue to report the same status.

Also, you should never use select with blocking sockets. That will only cause pain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM