Note: UNIX Network Programming Volume 1: The Sockets Networking API (3rd Edition)

A. TCP / UDP basics

Two. I / O multiplexing

  • select
  • epoll

1.1 TCP / UDP contrast

items TCP UDP
Connect and establish Three-way handshake Without connecting operation is transmitted directly
Data transmission Process buffer is copied to the send buffer if the send buffer blocking the plug does not fit until transmit buffer is empty to continue the replication process buffer does not exist, so write only show returns successfully transmit buffer is available, does not mean that the data has been sent to the peer, the transmit buffer contents reserved until you receive the correct reply Process buffer is copied directly to the kernel buffer, too large an error is returned, otherwise sent directly, and discard the transmitted data
Process bind/listen/accept/connect sendto/recvfrom
Packet structure Address / serial number / congestion control / check / data + offset, Information / Checksum / data length +

1.2 TIME_WAIT state

  • TIME_WAIT state reason to exist:
  • 1) reliably achieve full-duplex TCP connection is terminated
    to ensure the final ACK packet sent by the client to reach the server, because this ACK packets may be lost, standing on the perspective of the server seems that I have sent a FIN + ACK packet Wen request disconnected, the client has not responded to me, should I send the request to disconnect it did not receive the message, so the server will resend once, and the client can receive in this period 2MSL this retransmission of packets, and then give a response packet, and 2MSL will restart the timer.

  • 2) to allow passage of the old packets in the network
    to prevent similar "three-way handshake" mentioned in the "connection request has failed segment" appear in this connection. After the last client sends a confirmation message, 2MSL this time, it is possible to connect all the segments present within the duration of the generated disappeared from the network. Such new connection request packet old connection does not occur.

1.3 and buffer size limit

1.4 socket related structures and details

1.5 socket interfaces related to each process should pay attention to local

1.6 基于fork的并发服务常见问题梳理

Guess you like

Origin www.cnblogs.com/zhangyi-studio/p/12297573.html