简体   繁体   English

选择无法使用的Unix C

[英]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. 我的函数“ comandos()”只是从用户读取命令并执行某些操作,而函数VerificaLogin(pipelogin)只是让用户登录或不登录。 I can only user "comando" once and VerificaLogin only works after the first "comando"...Can someone tell me what's wrong in here ? 我只能使用一次“ comando”,而VerificaLogin只能在第一个“ comando”之后使用...有人可以告诉我这里有什么问题吗? Sorry for bad english. 对不起,英语不好。

The select function is a status-reporting function. select功能是状态报告功能。 Unless the status changes, it will continue to report the same status. 除非状态更改,否则它将继续报告相同的状态。

Also, you should never use select with blocking sockets. 另外, 绝对不要select与阻塞套接字一起使用。 That will only cause pain. 那只会引起痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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