Subject: Re: socket callbacks

Re: socket callbacks

From: Lijo Antony <lta_at_one.com>
Date: Thu, 28 Jun 2012 15:24:28 +0400

On 06/28/2012 11:53 AM, Fredrik Jansson wrote:
> 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?
>

This is correct.
But for a generic use case, a few more aspects may have to be
considered. For example, as Daniel mentioned, if user want to return a
socket which is already connected, there should be a way to inform
c-ares, not to do connect again. Callbacks may also require parameters,
by which c-ares can inform additional details for the socket(ip, port,
protocol etc). I guess Daniel and others would be able to give better
suggestions on this.

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

My use case would require the c-ares interface be similar to (and
complex) that of libcurl. Specifically, I would require the socket
details in opencallback and a way to avoid connect by c-ares, possibly
using sockopt callback.

I think the best way would be to go ahead with the way you want it.
Additional features can be added later. You may want to take a look at
libcurl interface, as it would help you to have an extensible api.

-lijo
Received on 2012-06-28