If a problem occurs, log
If an error occurs when you call the connect socket accept function, perror ("socket"); perror ("Connect"); printf ("% s \ n", strerror (errno )); can make specific errors
The select function emphasizes again: <0: Error returned, = 0: Normal, timeout returned, that is, there is no FD readable and writable, only for non-blocking> 0: normal return, you can also call the fdisset function to check the FD;
Socket operation on Non-socket errors may occur in two situations:
1. Create a socket:
If (listenfd = socket (af_inet, sock_stream, 0) =-1 ){
Perror ("creating socket failed! ");
Exit (-1 );
}
A socket operation on Non-socket error occurs during bind.
The correct code should be:
If (listenfd = socket (af_inet, sock_stream, 0) =-1 ){
Perror ("creating socket failed! ");
Exit (-1 );
}
2. Accept:
If (connfd = accept (listenfd, (struct sockaddr *) & client_addr, (socklen_t *) & sin_size) =-1 ){
Perror ("Accept error! ");
Exit (-1 );
}
A socket operation on Non-socket error occurs during Recv.
The correct code is:
If (connfd = accept (listenfd, (struct sockaddr *) & client_addr, (socklen_t *) & sin_size) =-1 ){
Perror ("Accept error! ");
Exit (-1 );
}
The reason for the socket operation on Non-socket error is:
If (listenfd = socket (af_inet, sock_stream, 0) =-1)
If (connfd = accept (listenfd, (struct sockaddr *) & client_addr, (socklen_t *) & sin_size) =-1)
This is because () is missing in the two sentences. The assignment has the lowest priority. As a result, the value of listenfd and connfd is 0 when the creation/connection is successful, and the value of listenfd and connfd is 1 when the connection fails.