Commit 34505299 authored by Pekka Pessi's avatar Pekka Pessi

sresolv: use sres_socket_t in API instead of plain int.

sres_socket_t is typedef to SOCKET or int.

darcs-hash:20060831164221-65a35-efc091fea435b5edf7543dea2187df4719e4f6fa.gz
parent dd594d28
......@@ -74,7 +74,7 @@ struct context
unsigned short sr_port;
int sr_n_sockets;
int *sr_sockets;
sres_socket_t *sr_sockets;
struct pollfd *sr_pollfds;
#if 0
......
......@@ -68,8 +68,8 @@ typedef SRES_ASYNC_T sres_async_t;
* socket that should be added to the poll() or select() set.
*/
typedef int sres_update_f(sres_async_t *async,
int new_socket,
int old_socket);
sres_socket_t new_socket,
sres_socket_t old_socket);
/** Set asynchronous operation data. */
SRESPUBFUN
......@@ -84,7 +84,9 @@ sres_async_t *sres_resolver_get_async(sres_resolver_t const *res,
sres_update_f *update);
/** Create sockets for resolver. */
SRESPUBFUN int sres_resolver_sockets(sres_resolver_t *, int *sockets, int n);
SRESPUBFUN int sres_resolver_sockets(sres_resolver_t *,
sres_socket_t *sockets,
int n);
/** Resolver timer function. */
SRESPUBFUN void sres_resolver_timer(sres_resolver_t *, int dummy);
......
......@@ -52,4 +52,14 @@
#endif
#endif
/* ---------------------------------------------------------------------- */
/* Types required by Win32/64 */
#if defined(_WIN32)
typedef SOCKET sres_socket_t;
#else
typedef int sres_socket_t;
#endif
#endif /* SOFIA_RESOLV_SRES_CONFIG_H */
......@@ -72,7 +72,7 @@ SOFIAPUBFUN sres_resolver_t *sres_resolver_create(su_root_t *root,
SOFIAPUBFUN int sres_resolver_destroy(sres_resolver_t *res);
/* Return socket used by root. @deprecated */
SOFIAPUBFUN int sres_resolver_root_socket(sres_resolver_t *res);
SOFIAPUBFUN su_socket_t sres_resolver_root_socket(sres_resolver_t *res);
SOFIA_END_DECLS
......
......@@ -91,7 +91,6 @@ struct sockaddr_storage {
#include <sofia-sip/su_alloc.h>
#include <sofia-sip/su_strlst.h>
#include <sofia-sip/su_errno.h>
#include <sofia-sip/su.h>
#include "sofia-sip/htable.h"
......@@ -145,7 +144,7 @@ enum edns {
};
struct sres_server {
int dns_socket;
sres_socket_t dns_socket;
char dns_name[48]; /**< Server name */
struct sockaddr_storage dns_addr[1]; /**< Server node address */
......@@ -354,7 +353,8 @@ static void sres_servers_close(sres_resolver_t *res,
static int sres_servers_count(sres_server_t * const *servers);
static int sres_server_socket(sres_resolver_t *res, sres_server_t *dns);
static sres_socket_t sres_server_socket(sres_resolver_t *res,
sres_server_t *dns);
static sres_query_t * sres_query_alloc(sres_resolver_t *res,
sres_answer_f *callback,
......@@ -399,11 +399,12 @@ static void
sres_resend_dns_query(sres_resolver_t *res, sres_query_t *q, int timeout);
static
sres_server_t *sres_server_by_socket(sres_resolver_t const *ts, int socket);
sres_server_t *sres_server_by_socket(sres_resolver_t const *ts,
sres_socket_t socket);
static
int sres_resolver_report_error(sres_resolver_t *res,
int socket,
sres_socket_t socket,
int errcode,
struct sockaddr_storage *remote,
socklen_t remotelen,
......@@ -993,13 +994,10 @@ sres_query_t *
sres_query_make(sres_resolver_t *res,
sres_answer_f *callback,
sres_context_t *context,
int socket,
int dummy,
uint16_t type,
char const *domain)
{
if (socket == -1)
return errno = EINVAL, NULL;
return sres_query(res, callback, context, type, domain);
}
......@@ -1018,7 +1016,7 @@ sres_query_t *
sres_query_make_sockaddr(sres_resolver_t *res,
sres_answer_f *callback,
sres_context_t *context,
int socket,
int dummy,
uint16_t type,
struct sockaddr const *addr)
{
......@@ -1027,13 +1025,10 @@ sres_query_make_sockaddr(sres_resolver_t *res,
if (!res || !addr)
return su_seterrno(EFAULT), (void *)NULL;
if (socket == -1)
return errno = EINVAL, NULL;
if (!sres_sockaddr2string(res, name, sizeof(name), addr))
return NULL;
return sres_query_make(res, callback, context, socket, type, name);
return sres_query_make(res, callback, context, dummy, type, name);
}
......@@ -2292,10 +2287,10 @@ int sres_servers_count(sres_server_t *const *servers)
}
static
int sres_server_socket(sres_resolver_t *res, sres_server_t *dns)
sres_socket_t sres_server_socket(sres_resolver_t *res, sres_server_t *dns)
{
int family = dns->dns_addr->ss_family;
int s;
sres_socket_t s;
if (dns->dns_socket != -1)
return dns->dns_socket;
......@@ -2376,7 +2371,8 @@ sres_send_dns_query(sres_resolver_t *res,
{
sres_message_t m[1];
uint8_t i, i0, N = res->res_n_servers;
int s, transient, error = 0;
sres_socket_t s;
int transient, error = 0;
unsigned size, no_edns_size, edns_size;
uint16_t id = q->q_id;
uint16_t type = q->q_type;
......@@ -2690,7 +2686,7 @@ sres_resend_dns_query(sres_resolver_t *res, sres_query_t *q, int timeout)
/** Get a server by socket */
static
sres_server_t *
sres_server_by_socket(sres_resolver_t const *res, int socket)
sres_server_by_socket(sres_resolver_t const *res, sres_socket_t socket)
{
int i;
......@@ -2749,7 +2745,9 @@ sres_canonize_sockaddr(struct sockaddr_storage *from, socklen_t *fromlen)
#endif
static
int sres_no_update(sres_async_t *async, int new_socket, int old_socket)
int sres_no_update(sres_async_t *async,
sres_socket_t new_socket,
sres_socket_t old_socket)
{
return 0;
}
......@@ -2757,10 +2755,11 @@ int sres_no_update(sres_async_t *async, int new_socket, int old_socket)
/** Create connected sockets for resolver.
*/
int sres_resolver_sockets(sres_resolver_t *res,
int *return_sockets,
sres_socket_t *return_sockets,
int n)
{
int s = -1, i, retval;
sres_socket_t s = -1;
int i, retval;
if (!sres_resolver_set_async(res, sres_no_update,
(sres_async_t *)-1, 1))
......@@ -2775,6 +2774,7 @@ int sres_resolver_sockets(sres_resolver_t *res,
sres_server_t *dns = res->res_servers[i];
s = sres_server_socket(res, dns);
return_sockets[i++] = s;
}
......@@ -2943,7 +2943,7 @@ int sres_resolver_error(sres_resolver_t *res, int socket)
static
int
sres_resolver_report_error(sres_resolver_t *res,
int socket,
sres_socket_t socket,
int errcode,
struct sockaddr_storage *remote,
socklen_t remotelen,
......
......@@ -98,8 +98,8 @@ struct sres_blocking_context_s
static
int sres_blocking_update(sres_blocking_t *b,
int new_socket,
int old_socket)
sres_socket_t new_socket,
sres_socket_t old_socket)
{
int i, N = b->n_sockets;
......
......@@ -79,8 +79,8 @@ struct sres_sofia_s {
};
static int sres_sofia_update(sres_sofia_t *,
int new_socket,
int old_socket);
su_socket_t new_socket,
su_socket_t old_socket);
static void sres_sofia_timer(su_root_magic_t *magic,
su_timer_t *t,
......@@ -168,8 +168,8 @@ sres_resolver_destroy(sres_resolver_t *res)
* @retval -1 upon failure
*/
static int sres_sofia_update(sres_sofia_t *srs,
int new_socket,
int old_socket)
su_socket_t new_socket,
su_socket_t old_socket)
{
char const *what = NULL;
su_wait_t wait[1];
......@@ -178,7 +178,8 @@ static int sres_sofia_update(sres_sofia_t *srs,
int i, index = -1, error = 0;
int N = SRES_MAX_NAMESERVERS;
SU_DEBUG_9(("sres_sofia_update(%p, %d, %d)\n", srs, new_socket, old_socket));
SU_DEBUG_9(("sres_sofia_update(%p, %d, %d)\n", srs,
(int)new_socket, (int)old_socket));
if (srs == NULL)
return 0;
......@@ -269,19 +270,19 @@ static int sres_sofia_update(sres_sofia_t *srs,
/** Return a socket registered to su_root_t object.
*
* @retval sockfd if succesful
* @retval -1 upon an error
* @retval SOCKET_ERROR (-1) upon an error
*
* @ERRORS
* @ERROR EFAULT Invalid argument passed.
* @ERROR EINVAL Resolver is not using su_root_t.
*/
int sres_resolver_root_socket(sres_resolver_t *res)
su_socket_t sres_resolver_root_socket(sres_resolver_t *res)
{
sres_sofia_t *srs;
int i, N = SRES_MAX_NAMESERVERS;
if (res == NULL)
return su_seterrno(EFAULT);
return (void)su_seterrno(EFAULT), SOCKET_ERROR;
srs = sres_resolver_get_async(res, sres_sofia_update);
......@@ -291,7 +292,7 @@ int sres_resolver_root_socket(sres_resolver_t *res)
if (sres_resolver_set_async(res, sres_sofia_update, srs, 1) < 0)
return -1;
if (srs->srs_socket != -1)
if (srs->srs_socket != SOCKET_ERROR)
return srs->srs_socket;
for (i = 0; i < N; i++) {
......@@ -303,7 +304,7 @@ int sres_resolver_root_socket(sres_resolver_t *res)
srs->srs_socket = srs->srs_reg[i].reg_socket;
}
else {
int socket;
su_socket_t socket;
if (sres_resolver_sockets(res, &socket, 1) < 0)
return -1;
}
......
......@@ -110,7 +110,7 @@ struct sres_context_s
int ready;
int n_sockets;
int sockets[SRES_MAX_NAMESERVERS];
sres_socket_t sockets[SRES_MAX_NAMESERVERS];
#if HAVE_POLL
struct pollfd fds[SRES_MAX_NAMESERVERS];
#endif
......@@ -124,8 +124,11 @@ static void test_answer_multi(sres_context_t *ctx, sres_query_t *query,
static int tstflags = 0;
#if 1
#if HAVE_POLL && 0
static
int setblocking(int s, int blocking)
int setblocking(sres_socket_t s, int blocking)
{
unsigned mode = fcntl(s, F_GETFL, 0);
......@@ -140,14 +143,12 @@ int setblocking(int s, int blocking)
return fcntl(s, F_SETFL, mode);
}
#if HAVE_POLL && 0
/** Test few assumptions about sockets */
static
int test_socket(sres_context_t *ctx)
{
int af;
int s1, s2, s3, s4;
su_sockeet_t s1, s2, s3, s4;
struct sockaddr_storage a[1];
struct sockaddr_storage a1[1], a2[1], a3[1], a4[1];
struct sockaddr_in *sin = (void *)a;
......@@ -162,10 +163,10 @@ int test_socket(sres_context_t *ctx)
af = AF_INET;
for (;;) {
TEST_1((s1 = socket(af, SOCK_DGRAM, 0)) != -1);
TEST_1((s2 = socket(af, SOCK_DGRAM, 0)) != -1);
TEST_1((s3 = socket(af, SOCK_DGRAM, 0)) != -1);
TEST_1((s4 = socket(af, SOCK_DGRAM, 0)) != -1);
TEST_1((s1 = su_socket(af, SOCK_DGRAM, 0)) != SOCKET_ERROR);
TEST_1((s2 = su_socket(af, SOCK_DGRAM, 0)) != SOCKET_ERROR);
TEST_1((s3 = su_socket(af, SOCK_DGRAM, 0)) != SOCKET_ERROR);
TEST_1((s4 = su_socket(af, SOCK_DGRAM, 0)) != SOCKET_ERROR);
TEST_1(setblocking(s1, 0) == 0);
TEST_1(setblocking(s2, 0) == 0);
......@@ -1839,7 +1840,7 @@ static
int test_conf_errors(sres_context_t *ctx, char const *conf_file)
{
sres_resolver_t *res;
int socket;
sres_socket_t socket;
int n;
BEGIN();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment