Is it possible to implement a non-blocking client socket? I have tried using
sockfd = socket(AF_INET, SOCK_STREAM, 0);
fcntl(sockfd, F_SETFL, O_NONBLOCK);
connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr));
but when the application reaches the connect
statement, i开发者_JAVA百科t exists with the following error:
ERROR connecting: Operation now in progress
I need to create a completely non-blocking socket, that doesn't even wait for the TCP handshake. Is this possible using standard socket functions or do I have to go into threading?
The error you receive is normal when in non-blocking mode. It just means that the operation could not be completed immediatly. That means you need to wait on the file descriptor for the connect to be finished before you can use it.
This is the way non-blocking sockets are working in C.
精彩评论