Socket options and protocol layer
|
|
|
SOL_SOCKET (General socket options) |
SO_KEEPALIVE O_RESUSEADDR SO_LINGER SO_SNDBUF SO_RCVBUF SO_TYPE SO_ERROR ...... |
Allow TCP link persistence Detection Allow reuse of local addresses Allow TCP connection to keep the data sent for a period of time Socket sending buffer size Socket receipt buffer size Obtain the socket type Obtain the socket-prone errors and clear them. .... |
SOL_TCP (TCP protocol layer options) |
SO_NODELAY TCP_MAXSEG |
Disable the TCP Nagle Algorithm Maximum TCP segment Value |
Because the server is always in the blocking status and waits for requests from the client
If a client breaks the connection established with the server due to shutdown or standby, the server process will not be able to know this situation in time, which will cause the server to keep these disconnected connectionsThe "Keep Alive" option can detect this situation.
TRUE 1 FALSE 0== setsockopt(sockfd,SOL_SOCKET,SO_KEEPALIVE,&so_keepalive,(so_keepalive));
TRUE 1 FALSE 0== setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&so_useaddr,(so_useaddr));