Linux network programming advanced socket

Source: Internet
Author: User
Tags keep alive

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));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.