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.git
make
- the shared library will be generated. and also the pool
test
and the simple testserver
- for
CharlesTcpPool::getConnection(timeout)
, thistimeout
is the timeout you wait for a valid connection and you can't ignore it, or you can just modify the code. this function will returnNULL
if it can't give you a valid connection. in this situation, you shouldn't useputConnection()
to put this connection back sinceNULL
is not a connection. and even though you get a connection notNULL
, when you dowrite
orread
you 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 ownKEEPALIVE
config in progress scope. - there is possibility that if you use blocking io, think about it, client do
write
thenread
and some bad server doread
,write
and thenclose
. if thisclose
packet isn't received by client after client dogetConnection
write
read
getConnection
(get the same fd, but it is closed)write
read
, the lastread
will return0
. and it is your responsibility to handleclient/server
logic, I ensure you this pool works fine.