Recent work summary

Source: Internet
Author: User

I have recently developed several multi-threaded network programming. I will summarize some of the things I have used here.

1. the blocking and non-blocking of socket encapsulates two functions for secure sending and receiving. However, in blocking mode, the socket is still healthy. in addition, I don't quite understand why we criticized non-blocking socket in TCP connections. In fact, this project has a high requirement on real-time data, and even has considered using UDP, if blocking transmission is used, the latency is completely controlled by the operating system. Although it is stable, it is really bad if you are not in control... otherwise, if the non-blocking method is used, I can immediately get the returned value to make the corresponding processing method. Of course, if the above is used for secure sending, the non-blocking mode is slightly different from the blocking mode. One is blocking in the system, and the other is blocking in your own code...

However, the TCP connection is indeed a relatively stable connection. In the initial test, there was not much problem... the network bandwidth is not enough, and many problems may occur =. =

2. the idea of software design... I don't know if it is because I am using C ++. We all say that what I write is too complicated and simple things are complicated... although I do not want to admit it, if more than two people say so, I restructured the code... because the thinking and requirements of the first writing were relatively simple, the initial structure design was indeed quite problematic as the demand gradually increased. In addition, some things should have their own opinions, it is right to listen more, but there is a problem if you always follow others' suggestions. after code refactoring, I really understood how complicated the original framework is...

3. FIFO and buffer pool. in the first few projects, FIFO is used as the cache data structure, which is precisely for this reason. Considering that we have implemented the single-write, single-read, secure, and non-lock FIFO, only with the initial framework design, but for network programming, it is a big pitfall to prevent concurrent sending... the initial design concept is too simple... after introducing the buffer pool idea, it is easier to implement the single-write and multi-read data structure, and I have mixed some designs of the ring linked list, such as the next pointer, concepts of nodes... the self-release lock zmutex and condition lock zconditon are added to the node... although it was initially a bit worried about efficiency, it was not affected during initial testing.
Works well

4. After code refactoring, I am most satisfied with the fact that the client should be encapsulated into an object for processing. This solves the dilemma of socket Management in multithreading in the initial framework...

5. You must sleep enough ~~

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.