... <看更多>
「linux fd_set」的推薦目錄:
- 關於linux fd_set 在 [問題] select() system call問題- 看板C_and_CPP - 批踢踢實業坊 的評價
- 關於linux fd_set 在 Extracting filedescriptors from fd_set - linux - Stack Overflow 的評價
- 關於linux fd_set 在 c-network-programming-best-snipts/Handle multiple socket ... 的評價
- 關於linux fd_set 在 poll, select, pselect6, ppoll - Linux x86_64系统调用简介 的評價
linux fd_set 在 c-network-programming-best-snipts/Handle multiple socket ... 的推薦與評價
Handle multiple socket connections with select and fd_set on Linux. Silver Moon ( [email protected]). */. #include <stdio.h>. ... <看更多>
linux fd_set 在 poll, select, pselect6, ppoll - Linux x86_64系统调用简介 的推薦與評價
#include <sys/select.h> int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); ... ... <看更多>
linux fd_set 在 [問題] select() system call問題- 看板C_and_CPP - 批踢踢實業坊 的推薦與評價
以下程式碼,在linux系統下
使用gcc編譯
編譯後會出現 line 16: storage size of "master_set" isn't known
"working_set"
查了一下該include也include了
為什麼這邊編譯後會出現錯誤呢
#include <stdio.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <sys/select.h>
#include <sys/time.h>
int main(){
int i;
struct timeval timeout;
struct fd_set master_set, working_set;
char buf[1024];
FD_ZERO(&master_set);
FD_SET(0, &master_set);
timeout.tv_sec = 5;
timeout.tv_usec = 0;
i = 0;
while(1){
memcpy(&working_set, &master_set, sizeof(master_set));
select(1, &working_set, NULL, NULL, &timeout);
if(FD_ISSET(0, &working_set)){
read(0, buf, sizeof(buf));
write(1, buf, strlen(buf));
}
printf("iteration: %d\n", i++);
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.42.101.127
可以執行了,但是執行時
當我輸入某字串 + ENTER後
他應該會輸出我輸入的字串
而後我沒輸入的話應該是會等5秒
印一次 ITERATION
但是奇怪的是
我輸入完後
他第一次會等5秒
5秒後,就開始瘋狂印ITERATION了
不知哪裡邏輯有誤?
謝謝
※ 編輯: kumusou 來自: 114.42.101.127 (11/19 23:52)
... <看更多>