记录一下套接字的非阻塞设置
1. #include <sys/socket.h> 2. #include <fcntl.h> 3. #include <netinet/in.h> 4. 5. int main() 6. { 7. int socketfd = socket(AF_INET, SOCK_STREAM, 0); 8. 9. struct sockaddr_in servaddr; 10. servaddr.sin_addr.s_addr = htonl(INADDR_ANY); 11. servaddr.sin_family = AF_INET; 12. servaddr.sin_port = htons(9999); 13. 14. int flags = fcntl(socketfd, F_GETFL, 0); 15. flags |= O_NONBLOCK; 16. fcntl(socketfd, F_SETFL, flags); 17}