In a TCP connection, we encounter port multiplexing, sticky packet problems, and so on.
When the server side actively shuts down the socket, it generates a time_wait state, so we need to add the option of port multiplexing to resolve the problem.
Because TCP is a streaming protocol, it is not possible to provide the message service, which needs to deal with the problem of sticky packets, the solution is:
1) Use fixed length to send data, so the limitations are relatively large.
2) Each time the message is sent, a 4-byte length information is sent, and then the actual message is sent, so that the receiver receives 4 bytes of length information, and then receives the corresponding actual message according to the length information.
3) Each message uses the ' \ n ' character as the end, and the receiver uses ReadLine as the receive function.
In TCP processing, the difference between close and shutdown:
1) Close is based on the reference count and is only actually closed if the count is 0 o'clock.
2) shutdown is not related to reference counting.
3) Close both read and Write,shutdown can be specified to close one end.
Implementation of server Concurrency:
1) using loops, each time a new client is accepted, this is called an iterative server .
2) Multi-process programming concurrency, at this time, the need to deal with zombie signals, processing signals are:
A) ignore the SIGCHLD directly, this is suitable for the child process to die without additional processing.
b) Write a handler function for SIGCHLD, calling Waitpid internally.
c) Use Waitpid directly, but this is not possible in concurrent servers because Waitpid needs to be blocked, which reduces the concurrent server to an iterative server .
3) Multithreaded writing concurrency, it is important to note that when you pass FD to a thread, you need to allocate memory space using malloc.
4) IO multiplexing model (SELECT, poll, Epoll).
Several IO multiplexing models are different:
1) The Disadvantages of select:
A) The limit of the number of FD, the kernel needs to be recompiled.
b) The FD array is copied from the user space to the kernel space.
c) Select system calls need to poll each FD one by one, as the number of FD increases and the efficiency decreases.
2) Although the poll model solves the problem of the number of FD, there is still a drawback of the decrease of copy and polling efficiency.
3) Advantages of Epoll:
A) for the FD is directly registered to the kernel, there is no duplication to the kernel space overhead.
b) The internal use of the callback function, focusing only on the active FD, so does not increase with the number of FD resulting in efficiency degradation.
Specific code and tests can be queried on my github:
Https://github.com/gjn135120/my_epoll
Linux Fundamentals--some operations of system integration Server and client