Overview
Features
Download
Documentation
Community
Add-Ons & Services

How to limit inbound TCP connections

Please post support and help requests here.

How to limit inbound TCP connections

Postby jthomas » 24 Nov 2008, 17:24

Hello,

I am experimenting with the Poco C++ Libraries v1.3.2 with excellent results.

At the moment, I am implementing a ServiceHandler based on the use of StreamSocket and SocketReactor. I am using EchoServer as an example.

I want to limit the number of simultaneous connections to perhaps three. I do this by maintaining an instance counter in my ServiceHandler constructor, and if max connections has been reached, I 'delete this' to close the connection based on the onShutdown example in EchoServer.

It works great. But I am a little nervous about calling 'delete this' within the constructor context for the same object.

Is that safe?

Is there a better way to detect the connection attempt via the Poco framework and close the connection based on an instance counter or other application constraint?

Thanks.

Jim Thomas
jthomas
 
Posts: 7
Joined: 27 Mar 2008, 00:53

Re: How to limit inbound TCP connections

Postby alex » 24 Nov 2008, 21:15

>I am experimenting with the Poco C++ Libraries v1.3.2 with excellent results.

I recommend upgrade to 1.3.3

> I want to limit the number of simultaneous connections to perhaps three.

If three connections are all you need, then Reactor may be an overkill. You may want to consider using TCPServer in conjunction with TCPServerParams.

^> It works great. But I am a little nervous about calling 'delete this' within the constructor context for the same object.

> Is that safe?^

As things currently stand, it should be, unless you shoot yourself in the foot by doing something in destructor that depends on the object being properly constructed. Additionally, framework authors may decide to shoot you in the foot if they ever decide to do something with returned pointer that expects fully constructed object.

> Is there a better way to detect the connection attempt via the Poco framework and close the connection based on an instance counter or other application constraint?

Yes - inherit from SocketAcceptor, override the createServiceHandler() and manage your limits from there.

HTH

Alex
alex
 
Posts: 1106
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron