天天看點

設定socket為非阻塞

1。window int make_socket_noblocking(int sock) { u_long nonblocking = 1; if (ioctlsocket(sock, FIONBIO, &nonblocking) == SOCKET_ERROR) { event_sock_warn(fd, "fcntl(%d, F_GETFL)", (int)fd); return -1; } return 0; } 2。linux int make_socket_noblocking(int sock) { int flags; if ((flags = fcntl(sock, F_GETFL, NULL)) < 0) { return -1; } if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) { return -1; } return 0; }

頭檔案 #include <fcntl.h>

繼續閱讀