curl-library
Re: Fwd: [PATCH] check ip callback
Date: Thu, 20 Sep 2007 16:17:20 +0200 (CEST)
On Fri, 14 Sep 2007, Dan Fandrich wrote:
>> + int* ai_family,
>> + int* ai_socktype,
>> + int* ai_protocol,
>> + struct sockaddr *ai_addr,
>> + socklen_t* ai_addrlen);
>
> Rather than passing these parameters individually, why not pass a pointer to
> a Curl_addrinfo? It would also need to be made public and therefore placed
> into curl/curl.h, which might be a bit tricky. In most cases it will end up
> being a typedef of the system's struct addrinfo, though.
I would prefer a struct pointer to prevent the number of arguments to be
ridiculously many.
I think I would prefer a separate new struct, as then it could also feature a
field or a bitmask for what struct members that have been modified and should
be used. In a spirit similar to this:
struct Curl_socketinfo {
int* si_family;
int* si_socktype;
int* si_protocol;
struct sockaddr *si_addr;
socklen_t* si_addrlen;
int si_setmask; /* bits as defined: */
#define CURL_SI_FAMILY (1<<0)
#define CURL_SI_SOCKTYPE (1<<1)
/* etc */
};
typedef int (*curl_sockopt_callback)(void *clientp,
curl_socket_t curlfd,
curlsocktype purpose,
struct Curl_socketinfo *info);
And then if you in the callback _only_ changes the family of the socket, it
would look like this:
int curl_sockopt_callback(void *clientp,
curl_socket_t curlfd,
curlsocktype purpose,
struct Curl_socketinfo *info)
{
info->si_family = MY_PREFERRED_FAMILY;
info->si_setmask = CURL_SI_FAMILY; /* family is modified */
return 0;
}
Good / bad ?
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2007-09-20