This is a property of the TServerSocket class.
void setSendTimeout(int sendTimeout);
void setRecvTimeout(int recvTimeout);
Those methods set the timeout values for the client sockets that are accepted
by the TServerSocket.
The relevant snippet of code is in ::acceptImpl
shared_ptr<TSocket> client(new TSocket(clientSocket));
if (sendTimeout_ > 0) {
client->setSendTimeout(sendTimeout_);
}
if (recvTimeout_ > 0) {
client->setRecvTimeout(recvTimeout_);
}
So, simply call the setters on the TServerSocket before passing it into your
TThreadedServer.
It seems entirely reasonable to add a similar mechanism to TNonblockingServer,
I'm surprised it doesn't already exist. The implementation is a little more
involved with libevent, but should be pretty straightforward.
Re: DOS concerns it is generally assumed that these servers are intended for
deployment in trusted intranet environments, not on the open internet. Still
good to have timeouts for playing defense against poorly configured internal
clients though.
Cheers,
Mark
-----Original Message-----
From: Kyku [mailto:[email protected]]
Sent: Monday, March 08, 2010 12:28 AM
To: [email protected]
Subject: Re: Closing inactive sockets.
Ok, I decided to try TThreadedServer instead. However I don't know how
I can access client sockets to set a timeout on them.
2010/3/7 David Reiss <[email protected]>:
> Set a read timeout on the server.
>
> If a client is shut down, the OS should still send the FIN packet to
> the server.
>
> Bryan Duxbury wrote:
>> What language are you talking about? I don't believe that Java or Ruby's
>> servers have this weakness.
>>
>> -Bryan
>>
>> On Sun, Mar 7, 2010 at 2:29 AM, Kyku <[email protected]> wrote:
>>
>>> Hello,
>>>
>>> Is it possible to set a timeout for server that would close stale
>>> client connections? Normally if a client is shutdown or there's a
>>> communication failure the server's socket for the client will be never
>>> closed leading to loss of resources.
>>>
>