Subject: RE: socket callbacks

RE: socket callbacks

From: Fredrik Jansson <fredrik.jansson_at_columbitech.com>
Date: Thu, 28 Jun 2012 07:53:46 +0000

Hi!

That kind of open/close-socket functions would work great for me.

I cannot see that there is that much work with this approach:

1. Check if we have opensocket cb otherwise call socket.

The opensocket_cb would have the sams arguments as the "socket" call plus an additional user data ptr.

2. Replace the sclose macro with a function that checks if we have a closesocket cb.

Or am I over simplifying things?

Lijo, would that provide what you (will) need?

Fredrik
________________________________________
From: c-ares-bounces_at_cool.haxx.se [c-ares-bounces_at_cool.haxx.se] on behalf of Lijo Antony [lta_at_one.com]
Sent: Thursday, June 28, 2012 08:23
To: c-ares_at_cool.haxx.se
Subject: Re: socket callbacks

On 06/28/2012 01:12 AM, Daniel Stenberg wrote:
> On Wed, 27 Jun 2012, Fredrik Jansson wrote:

>> What did you have in mind for the opensocket cb? Anything I can fix
>> while I am at the sockopt cb?
>
> It might be an idea to _just_ make it an opensocket one. In your case
> you could easily have the callback do socket() and then the sockopts you
> need...
>
> But regarding an opensocket callback, what exactly would that be used
> for? The reason I'm asking is that if you want to be able to pass in a
> socket that is already for exampled tunneled over some other medium you
> may want to tell c-ares to _not_ do the connect() afterwards or similar.
>
> I figure an opensocket callback would need a corresponding closesocket
> version as well.
>

I use curl in a cross platform c++ application(linux, windows & mac). In
linux and mac, I use c-ares as name resolver. I also use boost::asio
instead of libevent for socket monitoring.

A platform limitation of asio on windows, requires me to have all the
sockets used by curl be opened by asio. For this reason I use curl
opensocket/closesocket/sockopt callbacks. But c-ares doesn't have this
option. This is not an issue since c-ares will not come into picture on
windows, but has the side effect of having some platform specific code
and this is my current state.

As Daniel mentioned opensocket would involve quite some work. And I am
afraid this might be a very specific use case and may not be useful to
others. Since the incentive is low, compared to the work involved, I
couldn't work on this. I guess for Fredrik also this would be too much
unnecessary work, since he only wants to configure the socket.

But If such a need arise, and people are interested, with
ares_set_sockopt_callback in place, we should be able to add missing
callbacks(open/close) and follow the same curl design without too much
difficulties.

-lijo
Received on 2012-06-28