Experience of writing a network framework

1. Socket is one kind of I/O handle, just like a file handle.
Accessing a socket with multithreading is very similar to accessing a  file with multithreading.

2. The network programming models are very mature today.
You may first refer to some old documents to know more about that:
     http://think-async.com/Asio/LinuxPerformanceImprovements
     http://www.kegel.com/c10k.html#strategies

3. If you are not very familiar with multithreading (MT),
it is
recommended to use single threading + asynchronous socket programming  model.
Because in this model, it would be easy to make your code run
correctly as you expect.
Oppositely, if you are going to process I/O data with multithreading you should think about
- the correctness and completeness of the data you get from a socket via  multiple threads;
- using a thread pool.

4. Try to reduce memory copies when you process I/O data got from the  sockets.
Especially for C/C++ programmers, it'd better to use smart pointers 
(when you need to create something in heap) and pass them within the  processing flows.

5. Adjust the parameters of the socket/thread API functions to proper  values
so that your program can work well for your project's
requirements.
The parameters might be the I/O buffer size, the timeout
period, the stack size of a thread, etc.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值