设计思路
多个链路对应一个IO 多个是几个
所有串口用一个IO
TCP每10个用一个IO
总IO个数-CPU核数。
最优方案:
多个task/thread对应一个IO,IO总个数是=cpu core数。
https://www.cnblogs.com/fnlingnzb-learner/p/10402276.html
https://www.cnblogs.com/qbin/p/10860606.html
https://www.cnblogs.com/shirley18/p/9767622.html
https://www.zhihu.com/question/272025783
https://www.cnblogs.com/fnlingnzb-learner/p/10402232.html
https://blog.csdn.net/ybxuwei/article/details/53352603
多串口绑定单IO,多线程处理异步read伪代码
IoThreadPool
io_service io //io共享
work
threads//多线程
start(threads.join)
serialport
strand m_strand;
std::array<char, 8192> m_readBuffer;
open(
、、init io
init serialportparam
open
)
doWrite(str,len)
doRead(){
//异步读取绑定
async_read_some(m_readBuffer,size, m_strand[this,self](error ec, int nlen){
if(!ec){
string strRead = m_readBuffer[nlen];
processReadstr();
doRead();//循环 一定要循环,XXX很多例子都没说清楚为什么要循环
}
else{
excption
}
})
}
tcp类似,加上心跳检测连接状态,
reconnect