Welcome to Charles TCP Pool, it is a simple self-repair tcp connection pool. And it would be very nice to extend it. I will be grateful.
git clone https://github.com/linghuazaii/Charles-TcpPool.gitmake- the shared library will be generated. and also the pool
testand the simple testserver
- for
CharlesTcpPool::getConnection(timeout), thistimeoutis the timeout you wait for a valid connection and you can't ignore it, or you can just modify the code. this function will returnNULLif it can't give you a valid connection. in this situation, you shouldn't useputConnection()to put this connection back sinceNULLis not a connection. and even though you get a connection notNULL, when you dowriteorreadyou may find that this connection is bad,but don't worry, justputConnection()to return to the pool and wait for some time or continue to try togetConnection()until your job is done. you better wait for some time, since my baby thread will repair the bad connection which might be caused by crashed server or server closes the connection. - for
TCP_KEEPALIVE, this part is not integrated, you can extend it. some server may close connection if connection is not active for some time. but that's ok, if it is closed then it is repaired. if you useTCP_KEEPALIVE, this version will use system config, you can extend it to use your ownKEEPALIVEconfig in progress scope. - there is possibility that if you use blocking io, think about it, client do
writethenreadand some bad server doread,writeand thenclose. if thisclosepacket isn't received by client after client dogetConnectionwritereadgetConnection(get the same fd, but it is closed)writeread, the lastreadwill return0. and it is your responsibility to handleclient/serverlogic, I ensure you this pool works fine.