Commit d8d8be80 authored by Pekka Pessi's avatar Pekka Pessi

Using su_socket() and su_socket_t. Added socket_tag_class, tag_socket_v(), tag_socket_vr().

darcs-hash:20060906191338-65a35-89465dcb1f8c7d7e4ebd11e0f9a6cf703ed847c6.gz
parent 4725a433
......@@ -90,7 +90,8 @@ int main(int argc, char *argv[])
int n, N = 0;
unsigned long portno;
unsigned short port;
int af, s;
int af;
su_socket_t s;
socklen_t salen;
struct sockaddr_storage ss[1];
struct sockaddr *sa = (void *)ss;
......@@ -177,14 +178,14 @@ int main(int argc, char *argv[])
port = portno;
for (n = 0; n < N;) {
s = socket(sa->sa_family = af, types[n], protos[n]);
s = su_socket(sa->sa_family = af, types[n], protos[n]);
#if HAVE_SIN6
if (s == -1 && af == AF_INET6 && !o_ip6)
s = socket(sa->sa_family = af = AF_INET, types[n], protos[n]);
if (s == SOCKET_ERROR && af == AF_INET6 && !o_ip6)
s = su_socket(sa->sa_family = af = AF_INET, types[n], protos[n]);
#endif
if (s == -1) {
if (s == SOCKET_ERROR) {
fprintf(stderr, "%s: socket(AF_INET%s, 0, %s): %s\n",
name, af == AF_INET ? "" : "6", names[n], strerror(errno));
exit(1);
......
......@@ -153,8 +153,7 @@ struct agent_t {
/* Dummy servers */
char const *ag_sink_port;
int ag_sink_socket;
int ag_down_socket;
su_socket_t ag_sink_socket, ag_down_socket;
};
static int test_init(agent_t *ag, char const *resolv_conf);
......@@ -425,8 +424,9 @@ int test_init(agent_t *ag, char const *resolv_conf)
{
char const *contact = "sip:*:*;comp=sigcomp";
su_sockaddr_t su;
socklen_t sulen;
int s, af, sulen0;
socklen_t sulen, sulen0;
su_socket_t s;
int af;
BEGIN();
......@@ -454,7 +454,7 @@ int test_init(agent_t *ag, char const *resolv_conf)
contact = getenv("SIPCONTACT");
/* Sink server */
s = socket(af, SOCK_DGRAM, 0); TEST_1(s != -1);
s = socket(af, SOCK_DGRAM, 0); TEST_1(s != SOCKET_ERROR);
memset(&su, 0, sulen = sulen0);
su.su_family = af;
if (getenv("sink")) {
......@@ -467,7 +467,7 @@ int test_init(agent_t *ag, char const *resolv_conf)
ag->ag_sink_socket = s;
/* Down server */
s = socket(af, SOCK_STREAM, 0); TEST_1(s != -1);
s = socket(af, SOCK_STREAM, 0); TEST_1(s != SOCKET_ERROR);
memset(&su, 0, sulen = sulen0);
su.su_family = af;
if (getenv("down")) {
......@@ -701,7 +701,7 @@ static int test_bad_messages(agent_t *ag)
hints->ai_protocol = IPPROTO_UDP;
TEST(su_getaddrinfo(host, port, hints, &ai), 0); TEST_1(ai);
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); TEST_1(s != -1);
s = su_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); TEST_1(s != -1);
memset(su, 0, sulen = sizeof su);
su->su_len = sizeof su; su->su_family = ai->ai_family;
TEST_1(bind(s, &su->su_sa, sulen) == 0);
......@@ -2409,7 +2409,7 @@ int test_call(agent_t *ag)
{
sip_content_type_t *c = ag->ag_content_type;
sip_payload_t *sdp = ag->ag_payload;
nta_leg_t *leg, *old_leg;
nta_leg_t *old_leg;
sip_replaces_t *r1, *r2;
BEGIN();
......
......@@ -151,7 +151,7 @@ static int site_create(tester_t *t, int status, char const *phrase,
static int init_test(tester_t *t)
{
int s;
su_socket_t s;
char const *agent_pem;
BEGIN();
......@@ -161,7 +161,8 @@ static int init_test(tester_t *t)
TEST_1(t->t_mclass);
t->t_addr->su_len = (sizeof t->t_addr->su_sin);
s = socket(t->t_addr->su_family = AF_INET, SOCK_STREAM, 0); TEST_1(s != -1);
s = su_socket(t->t_addr->su_family = AF_INET, SOCK_STREAM, 0);
TEST_1(s != SOCKET_ERROR);
TEST_1(inet_pton(AF_INET, "127.0.0.1", &t->t_addr->su_sin.sin_addr) >= 0);
TEST_1(bind(s, &t->t_addr->su_sa,
t->t_addrlen = (sizeof t->t_addr->su_sin)) != -1);
......@@ -449,14 +450,14 @@ static int send_request(tester_t *t, char const *req, size_t reqlen,
char reply[], int rlen,
int *return_len)
{
static su_socket_t c = -1;
static su_socket_t c = SOCKET_ERROR;
int m, r;
su_wait_t w[1];
BEGIN();
if (c == -1) {
c = socket(t->t_addr->su_family, SOCK_STREAM, 0); TEST_1(c != -1);
if (c == SOCKET_ERROR) {
c = su_socket(t->t_addr->su_family, SOCK_STREAM, 0); TEST_1(c != SOCK_STREAM);
TEST_1(connect(c, &t->t_addr->su_sa, t->t_addrlen) != -1);
while (su_root_step(t->t_root, 1) == 0);
......@@ -613,7 +614,7 @@ static int test_requests(tester_t *t)
static int init_engine(tester_t *t)
{
BEGIN();
int s;
su_socket_t s;
t->t_engine = nth_engine_create(t->t_root,
NTHTAG_STREAMING(0),
......
......@@ -105,7 +105,7 @@ struct nat {
/* ...but source address will be "fake" */
su_localinfo_t *localinfo, *private, *fake;
int udp_socket, tcp_socket;
su_socket_t udp_socket, tcp_socket;
int udp_register, tcp_register;
char buffer[65536];
......@@ -118,7 +118,7 @@ struct binding
struct binding *next, **prev;
struct nat *nat; /* backpointer */
int socktype, protocol;
int in_socket, out_socket;
su_socket_t in_socket, out_socket;
int in_register, out_register;
int in_closed, out_closed;
char in_name[64], out_name[64];
......@@ -128,7 +128,7 @@ static struct binding *nat_binding_new(struct nat *nat,
char const *protoname,
int socktype, int protocol,
int connected,
int in_socket,
su_socket_t in_socket,
su_sockaddr_t *from,
socklen_t fromlen);
static void nat_binding_destroy(struct binding *);
......@@ -165,7 +165,7 @@ test_nat_init(su_root_t *root, struct nat *nat)
su_wait_t wait[1];
nat->root = root;
nat->udp_socket = -1, nat->tcp_socket = -1;
nat->udp_socket = SOCKET_ERROR, nat->tcp_socket = SOCKET_ERROR;
tl_gets(nat->tags,
TESTNATTAG_SYMMETRIC_REF(nat->symmetric),
......@@ -201,7 +201,7 @@ test_nat_init(su_root_t *root, struct nat *nat)
/* Bind TCP and UDP to same port */
for (;;) {
nat->udp_socket = su_socket(li->li_family, SOCK_DGRAM, IPPROTO_UDP);
if (nat->udp_socket == -1)
if (nat->udp_socket == SOCKET_ERROR)
return -1;
if (bind(nat->udp_socket, (void *)su, sulen) < 0) {
......@@ -212,9 +212,9 @@ test_nat_init(su_root_t *root, struct nat *nat)
fprintf(stderr, "test_nat: port %u: %s\n",
port, su_strerror(su_errno()));
su_close(nat->udp_socket);
nat->udp_socket = -1;
nat->udp_socket = SOCKET_ERROR;
if (++port > 65535)
port = 1024;
......@@ -240,12 +240,12 @@ test_nat_init(su_root_t *root, struct nat *nat)
}
nat->tcp_socket = su_socket(li->li_family, SOCK_STREAM, IPPROTO_TCP);
if (nat->tcp_socket == -1)
if (nat->tcp_socket == SOCKET_ERROR)
return -1;
if (bind(nat->tcp_socket, (void *)su, sulen) < 0) {
su_close(nat->tcp_socket);
nat->tcp_socket = -1;
nat->tcp_socket = SOCKET_ERROR;
fprintf(stderr, "test_nat: port %u: %s\n",
port, su_strerror(su_errno()));
......@@ -311,9 +311,9 @@ test_nat_deinit(su_root_t *root, struct nat *nat)
if (nat->udp_register)
su_root_deregister(root, nat->udp_register);
if (nat->udp_socket != -1)
if (nat->udp_socket != SOCKET_ERROR)
su_close(nat->udp_socket);
if (nat->tcp_socket != -1)
if (nat->tcp_socket != SOCKET_ERROR)
su_close(nat->tcp_socket);
su_freelocalinfo(nat->localinfo);
......@@ -427,7 +427,7 @@ struct binding *nat_binding_new(struct nat *nat,
int socktype,
int protocol,
int connected,
int in_socket,
su_socket_t in_socket,
su_sockaddr_t *from,
socklen_t fromlen)
{
......@@ -466,7 +466,7 @@ static int binding_init(struct binding *b,
socklen_t fromlen)
{
struct nat *nat = b->nat;
int out_socket;
su_socket_t out_socket;
su_sockaddr_t addr[1];
socklen_t addrlen = (sizeof addr);
char ipname[64];
......@@ -478,11 +478,11 @@ static int binding_init(struct binding *b,
else
in_to_out = udp_in_to_out, out_to_in = udp_out_to_in;
if (b->in_socket == -1) {
if (b->in_socket == SOCKET_ERROR) {
int in_socket;
in_socket = su_socket(from->su_family, b->socktype, b->protocol);
if (in_socket < 0) {
if (in_socket == SOCKET_ERROR) {
su_perror("nat_binding_new: socket");
return -1;
}
......@@ -502,7 +502,7 @@ static int binding_init(struct binding *b,
}
out_socket = su_socket(li->li_family, b->socktype, b->protocol);
if (out_socket < 0) {
if (out_socket == SOCKET_ERROR) {
su_perror("nat_binding_new: socket");
return -1;
}
......@@ -717,7 +717,7 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
static int new_tcp(struct nat *nat, su_wait_t *wait, struct binding *dummy)
{
int events;
int in_socket;
su_socket_t in_socket;
su_sockaddr_t from[1];
socklen_t fromlen = (sizeof from);
struct binding *b;
......@@ -725,7 +725,7 @@ static int new_tcp(struct nat *nat, su_wait_t *wait, struct binding *dummy)
events = su_wait_events(wait, nat->tcp_socket);
in_socket = accept(nat->tcp_socket, (void *)from, &fromlen);
if (in_socket < 0) {
if (in_socket == SOCKET_ERROR) {
su_perror("new_tcp: accept");
return 0;
}
......@@ -822,12 +822,13 @@ static int invalidate_binding(struct binding *b)
struct nat *nat = b->nat;
su_sockaddr_t addr[1];
socklen_t addrlen = (sizeof addr);
int out, out_register;
su_socket_t out;
int out_register;
su_wait_t wout[1];
char name[64];
out = su_socket(nat->fake->li_family, b->socktype, 0);
if (out < 0) {
if (out == SOCKET_ERROR) {
su_perror("new_udp: socket");
return -1;
}
......
......@@ -291,10 +291,12 @@ SOFIAPUBFUN int stun_dns_lookup_stp_addr(stun_dns_lookup_t *self,
SOFIAPUBFUN stun_mini_t *stun_mini_create(void);
SOFIAPUBFUN void stun_mini_destroy(stun_mini_t *);
SOFIAPUBFUN int stun_mini_add_socket(stun_mini_t *server, int socket);
SOFIAPUBFUN int stun_mini_remove_socket(stun_mini_t *server, int socket);
SOFIAPUBFUN int stun_mini_add_socket(stun_mini_t *server,
su_socket_t socket);
SOFIAPUBFUN int stun_mini_remove_socket(stun_mini_t *server,
su_socket_t socket);
SOFIAPUBFUN void stun_mini_request(stun_mini_t *server, int socket,
SOFIAPUBFUN void stun_mini_request(stun_mini_t *server, su_socket_t socket,
void *msg, ssize_t msglen,
void *addr, socklen_t addrlen);
......
......@@ -36,6 +36,9 @@
#ifndef SU_TAG_H
#include <sofia-sip/su_tag.h>
#endif
#ifndef SU_TAG_IO_H
#include <sofia-sip/su_tag_io.h>
#endif
SOFIA_BEGIN_DECLS
......@@ -66,9 +69,9 @@ SOFIAPUBVAR tag_typedef_t stuntag_integrity;
#define STUNTAG_INTEGRITY_REF(x) stuntag_integrity_ref, tag_int_vr(&(x))
SOFIAPUBVAR tag_typedef_t stuntag_integrity_ref;
#define STUNTAG_SOCKET(x) stuntag_socket, tag_int_v(x)
#define STUNTAG_SOCKET(x) stuntag_socket, tag_socket_v(x)
SOFIAPUBVAR tag_typedef_t stuntag_socket;
#define STUNTAG_SOCKET_REF(x) stuntag_socket_ref, tag_int_vr(&(x))
#define STUNTAG_SOCKET_REF(x) stuntag_socket_ref, tag_socket_vr(&(x))
SOFIAPUBVAR tag_typedef_t stuntag_socket_ref;
#define STUNTAG_REGISTER_EVENTS(x) stuntag_register_events, tag_int_v(x)
......
......@@ -547,7 +547,7 @@ int stun_obtain_shared_secret(stun_handle_t *sh,
/* open tcp connection to server */
s = su_socket(family = AF_INET, SOCK_STREAM, 0);
if (s == -1) {
if (s == SOCKET_ERROR) {
STUN_ERROR(errno, socket);
return -1;
}
......@@ -738,7 +738,8 @@ void stun_handle_destroy(stun_handle_t *sh)
/** Create wait object and register it to the handle callback */
int assign_socket(stun_discovery_t *sd, su_socket_t s, int reg_socket)
static
int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket)
{
stun_handle_t *sh = sd->sd_handle;
int events;
......@@ -754,8 +755,8 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int reg_socket)
enter;
if (s == -1) {
SU_DEBUG_3(("%s: invalid socket.\n", __func__));
if (s == SOCKET_ERROR) {
SU_DEBUG_3(("%s: invalid socket\n", __func__));
return errno = EINVAL, -1;
}
......@@ -769,7 +770,7 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int reg_socket)
}
sd->sd_socket = s;
if (reg_socket != 1)
if (!register_socket)
return 0;
/* set socket asynchronous */
......@@ -1037,7 +1038,7 @@ int stun_bind(stun_handle_t *sh,
tag_type_t tag, tag_value_t value,
...)
{
su_socket_t s = -1;
su_socket_t s = SOCKET_ERROR;
stun_request_t *req = NULL;
stun_discovery_t *sd = NULL;
ta_list ta;
......@@ -1206,7 +1207,7 @@ int stun_test_nattype(stun_handle_t *sh,
stun_request_t *req = NULL;
stun_discovery_t *sd = NULL;
su_sockaddr_t bind_addr;
su_socket_t s = -1;
su_socket_t s = SOCKET_ERROR;
socklen_t bind_len;
su_sockaddr_t *destination = NULL;
......@@ -1496,7 +1497,7 @@ static int stun_tls_callback(su_root_magic_t *m, su_wait_t *w, su_wakeup_arg_t *
/* closed TLS connection */
SSL_shutdown(ssl);
su_close(sd->sd_socket);
su_close(sd->sd_socket), sd->sd_socket = SOCKET_ERROR;
SSL_free(self->sh_ssl), ssl = NULL;
SSL_CTX_free(self->sh_ctx), ctx = NULL;
......@@ -2411,7 +2412,7 @@ static int stun_send_binding_request(stun_request_t *req,
su_sockaddr_t *srvr_addr)
{
su_timer_t *sendto_timer = NULL;
int s;
su_socket_t s;
stun_handle_t *sh = req->sr_handle;
stun_msg_t *msg = req->sr_msg;
......@@ -2705,7 +2706,8 @@ int stun_test_lifetime(stun_handle_t *sh,
stun_request_t *req = NULL;
stun_discovery_t *sd = NULL;
ta_list ta;
int s = -1, err, index = 0, s_reg = 0;
su_socket_t s = SOCKET_ERROR;
int err, index = 0, s_reg = 0;
char ipaddr[SU_ADDRSIZE + 2] = { 0 };
char const *server = NULL;
su_socket_t sockfdy;
......@@ -2935,7 +2937,7 @@ int stun_keepalive(stun_handle_t *sh,
tag_type_t tag, tag_value_t value,
...)
{
int s = -1;
su_socket_t s = SOCKET_ERROR;
unsigned int timeout = 0;
ta_list ta;
stun_discovery_t *sd;
......
......@@ -61,7 +61,7 @@ struct stun_dns_lookup_s {
su_root_t *stun_root;
stun_magic_t *stun_magic;
sres_resolver_t *stun_sres;
int stun_socket;
su_socket_t stun_socket;
stun_dns_lookup_f stun_cb;
char *stun_tcp_target;
char *stun_udp_target;
......@@ -138,7 +138,7 @@ stun_dns_lookup_t *stun_dns_lookup(stun_magic_t *magic,
{
stun_dns_lookup_t *self = su_zalloc(NULL, sizeof(stun_dns_lookup_t));
sres_query_t *query;
int socket;
su_socket_t socket;
/* see nta.c:outgoing_answer_srv() */
......@@ -149,7 +149,7 @@ stun_dns_lookup_t *stun_dns_lookup(stun_magic_t *magic,
self->stun_sres = sres_resolver_create(root, NULL, TAG_END());
if (self->stun_sres) {
socket = sres_resolver_root_socket(self->stun_sres);
if (socket >= 0) {
if (socket != SOCKET_ERROR) {
char *query_udp = su_sprintf(self->stun_home, "%s.%s", STUN_SRV_SERVICE_UDP, domain);
char *query_tcp = su_sprintf(self->stun_home, "%s.%s", STUN_SRV_SERVICE_TCP, domain);
......@@ -160,7 +160,7 @@ stun_dns_lookup_t *stun_dns_lookup(stun_magic_t *magic,
}
else {
sres_resolver_destroy(self->stun_sres);
self->stun_socket = -1;
self->stun_socket = SOCKET_ERROR;
su_free(NULL, self), self = NULL;
}
}
......
......@@ -45,7 +45,7 @@ typedef struct stun_socket_s stun_socket_t;
struct stun_socket_s
{
stun_socket_t *ss_next;
int ss_socket;
su_socket_t ss_socket;
int ss_scope; /* LI_SCOPE */
socklen_t ss_addrlen;
union {
......@@ -96,7 +96,7 @@ void stun_mini_destroy(stun_mini_t *mini)
}
/** Add a socket to stun miniserver. */
int stun_mini_add_socket(stun_mini_t *mini, int socket)
int stun_mini_add_socket(stun_mini_t *mini, su_socket_t socket)
{
stun_socket_t *ss, **next;
struct sockaddr_storage addr[1];
......@@ -128,7 +128,7 @@ int stun_mini_add_socket(stun_mini_t *mini, int socket)
}
/** Remove socket from stun miniserver */
int stun_mini_remove_socket(stun_mini_t *mini, int socket)
int stun_mini_remove_socket(stun_mini_t *mini, su_socket_t socket)
{
stun_socket_t *ss, **next;
......@@ -147,7 +147,7 @@ int stun_mini_remove_socket(stun_mini_t *mini, int socket)
}
void stun_mini_request(stun_mini_t *mini,
int socket,
su_socket_t socket,
void *msg, ssize_t msglen,
void *from, socklen_t fromlen)
{
......
......@@ -126,7 +126,7 @@ tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(integrity);
*
* Corresponding tag taking reference parameter is STUNTAG_SOCKET_REF()
*/
tag_typedef_t stuntag_socket = INTTAG_TYPEDEF(socket);
tag_typedef_t stuntag_socket = SOCKETTAG_TYPEDEF(socket);
/**@def STUNTAG_REGISTER_EVENTS(x)
*
......@@ -139,14 +139,14 @@ tag_typedef_t stuntag_socket = INTTAG_TYPEDEF(socket);
* stun_keepalive() \n
*
* @par Parameter type
* int (su_register_socket_t)
* bool
*
* @par Values
* IPv4 (AF_INET) register_events
* false (0) or true (nonzero)
*
* Corresponding tag taking reference parameter is STUNTAG_REGISTER_EVENTS_REF()
*/
tag_typedef_t stuntag_register_events = INTTAG_TYPEDEF(register_events);
tag_typedef_t stuntag_register_events = BOOLTAG_TYPEDEF(register_events);
/**@def STUNTAG_ACTION(x)
*
......
......@@ -55,6 +55,7 @@ SOFIA_BEGIN_DECLS
#define UINTTAG_TYPEDEF(t) TAG_TYPEDEF(t, uint)
#define BOOLTAG_TYPEDEF(t) TAG_TYPEDEF(t, bool)
#define PTRTAG_TYPEDEF(t) TAG_TYPEDEF(t, ptr)
#define SOCKETTAG_TYPEDEF(t) TAG_TYPEDEF(t, socket)
#define CSTRTAG_TYPEDEF(t) TAG_TYPEDEF(t, cstr)
#define STRTAG_TYPEDEF(t) TAG_TYPEDEF(t, str)
#define NSTAG_TYPEDEF(t) TAG_TYPEDEF(t, ns)
......@@ -82,6 +83,7 @@ SOFIAPUBVAR tag_class_t int_tag_class[];
SOFIAPUBVAR tag_class_t uint_tag_class[];
SOFIAPUBVAR tag_class_t bool_tag_class[];
SOFIAPUBVAR tag_class_t ptr_tag_class[];
SOFIAPUBVAR tag_class_t socket_tag_class[];
SOFIAPUBVAR tag_class_t cstr_tag_class[];
SOFIAPUBVAR tag_class_t str_tag_class[];
SOFIAPUBVAR tag_class_t ns_tag_class[];
......
......@@ -38,12 +38,28 @@
#ifndef SU_TAG_H
#include <sofia-sip/su_tag.h>
#endif
#ifndef SU_H
#include <sofia-sip/su.h>
#endif
#include <stdio.h>
SOFIA_BEGIN_DECLS
SOFIAPUBFUN void tl_print(FILE *f, char const *title, tagi_t const lst[]);
#if SU_HAVE_INLINE
su_inline tag_value_t tag_socket_v(su_socket_t v) {
return (tag_value_t)v;
}
su_inline tag_value_t tag_socket_vr(su_socket_t *vp) {
return (tag_value_t)vp;
}
#else
#define tag_socket_v(v) (tag_value_t)(v)
#define tag_socket_vr(v) (tag_value_t)(v)
#endif
SOFIA_END_DECLS
#endif
......@@ -51,9 +51,9 @@
int su_socket_close_on_exec = 0;
/** Create an endpoint for communication. */
su_socket_t su_socket(int af, int sock, int proto)
su_socket_t su_socket(int af, int socktype, int proto)
{
su_socket_t s = socket(af, sock, proto);
su_socket_t s = socket(af, socktype, proto);
#if SU_HAVE_BSDSOCK
if (s != SOCKET_ERROR && su_socket_close_on_exec) {
fcntl(s, F_SETFD, FD_CLOEXEC); /* Close on exec */
......@@ -85,7 +85,7 @@ int su_close(su_socket_t s)
return close(s);
}
int su_setblocking(int s, int blocking)
int su_setblocking(su_socket_t s, int blocking)
{
int mode = fcntl(s, F_GETFL, 0);
......
......@@ -461,13 +461,13 @@ void su_port_destroy(su_port_t *self)
SU_DEBUG_9(("su_port_destroy() called\n"));
#if SU_HAVE_MBOX
if (self->sup_mbox[0] != INVALID_SOCKET) {
if (self->sup_mbox[0] != SOCKET_ERROR) {
su_port_unregister(self, NULL, &self->sup_mbox_wait, NULL,
(su_wakeup_arg_t *)self->sup_mbox);
su_wait_destroy(&self->sup_mbox_wait);
su_close(self->sup_mbox[0]); self->sup_mbox[0] = INVALID_SOCKET;
su_close(self->sup_mbox[0]); self->sup_mbox[0] = SOCKET_ERROR;
#if HAVE_SOCKETPAIR
su_close(self->sup_mbox[1]); self->sup_mbox[1] = INVALID_SOCKET;
su_close(self->sup_mbox[1]); self->sup_mbox[1] = SOCKET_ERROR;
#endif
SU_DEBUG_9(("su_port_destroy() close mailbox\n"));
}
......@@ -552,7 +552,7 @@ int su_port_send(su_port_t *self, su_msg_r rmsg)
/* if (!pthread_equal(pthread_self(), self->sup_tid)) */
if (wakeup)
{
assert(self->sup_mbox[MBOX_SEND] != INVALID_SOCKET);
assert(self->sup_mbox[MBOX_SEND] != SOCKET_ERROR);
if (send(self->sup_mbox[MBOX_SEND], "X", 1, 0) == -1) {
#if HAVE_SOCKETPAIR
......
......@@ -1256,6 +1256,40 @@ tag_class_t ptr_tag_class[1] =
/* tc_scan */ NULL,
}};
/* ====================================================================== */
/* socket tag - pass socket */
#include <sofia-sip/su.h>
int t_socket_snprintf(tagi_t const *t, char b[], size_t size)
{
/* socket can be int or DWORD (or QWORD on win64?) */
return snprintf(b, size, LLI, (longlong)t->t_value);
}
int t_socket_ref_set(tag_type_t tt, void *ref, tagi_t const value[])
{
*(su_socket_t *)ref = (su_socket_t)value->t_value;
return 1;
}
tag_class_t socket_tag_class[1] =
{{
sizeof(socket_tag_class),
/* tc_next */ NULL,
/* tc_len */ NULL,
/* tc_move */ NULL,
/* tc_xtra */ NULL,
/* tc_dup */ NULL,
/* tc_free */ NULL,
/* tc_find */ NULL,
/* tc_snprintf */ t_socket_snprintf,
/* tc_filter */ NULL,
/* tc_ref_set */ t_socket_ref_set,
/* tc_scan */ NULL,
}};
/* ====================================================================== */
/* str tag - pass string value */
......
......@@ -124,7 +124,7 @@ int su_wait_create(su_wait_t *newwait, su_socket_t socket, int events)
#if SU_HAVE_WINSOCK
HANDLE h = WSACreateEvent();
if (newwait == NULL || events == 0 || socket == INVALID_SOCKET) {
if (newwait == NULL || events == 0 || socket == SOCKET_ERROR) {
su_seterrno(WSAEINVAL);
return -1;
}
......@@ -142,7 +142,7 @@ int su_wait_create(su_wait_t *newwait, su_socket_t socket, int events)
#elif SU_HAVE_POLL
if (newwait == NULL || events == 0 || socket == INVALID_SOCKET) {
if (newwait == NULL || events == 0 || socket == SOCKET_ERROR) {
su_seterrno(EINVAL);
return -1;
}
......
......@@ -46,9 +46,9 @@ typedef struct {
int vst_size;
tport_stun_server_t *(*vst_create)(su_root_t *root, tagi_t const *tags);
void (*vst_destroy)(tport_stun_server_t *);
int (*vst_add_socket)(tport_stun_server_t *, int socket);
int (*vst_remove_socket)(tport_stun_server_t *, int socket);
void (*vst_request)(tport_stun_server_t *server, int socket,
int (*vst_add_socket)(tport_stun_server_t *, su_socket_t socket);
int (*vst_remove_socket)(tport_stun_server_t *, su_socket_t socket);
void (*vst_request)(tport_stun_server_t *server, su_socket_t socket,
void *msg, ssize_t msglen,
void *addr, socklen_t addrlen);
} tport_stun_server_vtable_t;
......
......@@ -3262,7 +3262,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
if (error == EAGAIN || error == EWOULDBLOCK) {
SU_DEBUG_5(("tport_vsend(%p): %s with (s=%d %s/%s:%s%s)\n",
self, "EAGAIN", self->tp_socket,
self, "EAGAIN", (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp));
return 0;
}
......@@ -3271,7 +3271,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
if (self->tp_addrinfo->ai_family == AF_INET) {
SU_DEBUG_3(("tport_vsend(%p): %s with (s=%d %s/%s:%s%s)\n",
self, su_strerror(error), self->tp_socket,
self, su_strerror(error), (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp));
}
#if SU_HAVE_IN6
......@@ -3279,7 +3279,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
su_sockaddr_t const *su = (su_sockaddr_t const *)ai->ai_addr;
SU_DEBUG_3(("tport_vsend(%p): %s with "
"(s=%d, IP6=%s/%s:%s%s (scope=%i) addrlen=%zd)\n",
self, su_strerror(error), self->tp_socket,
self, su_strerror(error), (int)self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp,
su->su_scope_id, ai->ai_addrlen));
}
......@@ -3288,7 +3288,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
SU_DEBUG_3(("\ttport_vsend(%p): %s with "
"(s=%d, AF=%u addrlen=%zd)%s\n",
self, su_strerror(error),
self->tp_socket, ai->ai_family, ai->ai_addrlen, comp));
(int)self->tp_socket, ai->ai_family, ai->ai_addrlen, comp));
}
#if 0
......
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