Code cleanup

This commit is contained in:
Pierre Pronchery 2015-11-22 16:58:20 +01:00
parent 37ed389b7f
commit 57b4b3d7ea
6 changed files with 26 additions and 26 deletions

View File

@ -44,8 +44,8 @@
#endif #endif
/* for tcp4 and tcp6 */ /* for tcp4 and tcp6 */
#ifndef TCP_FAMILY #ifndef TCP_DOMAIN
# define TCP_FAMILY AF_UNSPEC # define TCP_DOMAIN AF_UNSPEC
#endif #endif
@ -155,8 +155,8 @@ AppTransportPluginDefinition transport =
/* functions */ /* functions */
/* plug-in */ /* plug-in */
/* tcp_init */ /* tcp_init */
static int _init_client(TCP * tcp, char const * name); static int _init_client(TCP * tcp, char const * name, int domain);
static int _init_server(TCP * tcp, char const * name); static int _init_server(TCP * tcp, char const * name, int domain);
static TCP * _tcp_init(AppTransportPluginHelper * helper, AppTransportMode mode, static TCP * _tcp_init(AppTransportPluginHelper * helper, AppTransportMode mode,
char const * name) char const * name)
@ -174,10 +174,10 @@ static TCP * _tcp_init(AppTransportPluginHelper * helper, AppTransportMode mode,
switch((tcp->mode = mode)) switch((tcp->mode = mode))
{ {
case ATM_CLIENT: case ATM_CLIENT:
res = _init_client(tcp, name); res = _init_client(tcp, name, TCP_DOMAIN);
break; break;
case ATM_SERVER: case ATM_SERVER:
res = _init_server(tcp, name); res = _init_server(tcp, name, TCP_DOMAIN);
break; break;
default: default:
res = -error_set_code(-EINVAL, "%s", res = -error_set_code(-EINVAL, "%s",
@ -197,7 +197,7 @@ static TCP * _tcp_init(AppTransportPluginHelper * helper, AppTransportMode mode,
return tcp; return tcp;
} }
static int _init_client(TCP * tcp, char const * name) static int _init_client(TCP * tcp, char const * name, int domain)
{ {
struct addrinfo * aip; struct addrinfo * aip;
#ifdef DEBUG #ifdef DEBUG
@ -207,7 +207,7 @@ static int _init_client(TCP * tcp, char const * name)
tcp->u.client.tcp = tcp; tcp->u.client.tcp = tcp;
tcp->u.client.fd = -1; tcp->u.client.fd = -1;
/* obtain the remote address */ /* obtain the remote address */
if((tcp->ai = _init_address(name, TCP_FAMILY, 0)) == NULL) if((tcp->ai = _init_address(name, domain, 0)) == NULL)
return -1; return -1;
/* connect to the remote host */ /* connect to the remote host */
for(aip = tcp->ai; aip != NULL; aip = aip->ai_next) for(aip = tcp->ai; aip != NULL; aip = aip->ai_next)
@ -257,7 +257,7 @@ static int _init_client(TCP * tcp, char const * name)
return (aip != NULL) ? 0 : -1; return (aip != NULL) ? 0 : -1;
} }
static int _init_server(TCP * tcp, char const * name) static int _init_server(TCP * tcp, char const * name, int domain)
{ {
struct addrinfo * aip; struct addrinfo * aip;
TCPSocket tcpsocket; TCPSocket tcpsocket;
@ -267,7 +267,7 @@ static int _init_server(TCP * tcp, char const * name)
tcp->u.server.fd = -1; tcp->u.server.fd = -1;
/* obtain the local address */ /* obtain the local address */
if((tcp->ai = _init_address(name, TCP_FAMILY, AI_PASSIVE)) == NULL) if((tcp->ai = _init_address(name, domain, AI_PASSIVE)) == NULL)
return -1; return -1;
for(aip = tcp->ai; aip != NULL; aip = aip->ai_next) for(aip = tcp->ai; aip != NULL; aip = aip->ai_next)
{ {

View File

@ -15,5 +15,5 @@
#define TCP_FAMILY AF_INET #define TCP_DOMAIN AF_INET
#include "tcp.c" #include "tcp.c"

View File

@ -15,5 +15,5 @@
#define TCP_FAMILY AF_INET6 #define TCP_DOMAIN AF_INET6
#include "tcp.c" #include "tcp.c"

View File

@ -45,8 +45,8 @@
#endif #endif
/* for udp4 and udp6 */ /* for udp4 and udp6 */
#ifndef UDP_FAMILY #ifndef UDP_DOMAIN
# define UDP_FAMILY AF_UNSPEC # define UDP_DOMAIN AF_UNSPEC
#endif #endif
@ -138,8 +138,8 @@ AppTransportPluginDefinition transport =
/* functions */ /* functions */
/* plug-in */ /* plug-in */
/* udp_init */ /* udp_init */
static int _init_client(UDP * udp, char const * name); static int _init_client(UDP * udp, char const * name, int domain);
static int _init_server(UDP * udp, char const * name); static int _init_server(UDP * udp, char const * name, int domain);
static int _init_socket(UDP * udp); static int _init_socket(UDP * udp);
static UDP * _udp_init(AppTransportPluginHelper * helper, static UDP * _udp_init(AppTransportPluginHelper * helper,
@ -159,10 +159,10 @@ static UDP * _udp_init(AppTransportPluginHelper * helper,
switch((udp->mode) = mode) switch((udp->mode) = mode)
{ {
case ATM_CLIENT: case ATM_CLIENT:
res = _init_client(udp, name); res = _init_client(udp, name, UDP_DOMAIN);
break; break;
case ATM_SERVER: case ATM_SERVER:
res = _init_server(udp, name); res = _init_server(udp, name, UDP_DOMAIN);
break; break;
default: default:
res = -error_set_code(-EINVAL, "%s", res = -error_set_code(-EINVAL, "%s",
@ -178,11 +178,11 @@ static UDP * _udp_init(AppTransportPluginHelper * helper,
return udp; return udp;
} }
static int _init_client(UDP * udp, char const * name) static int _init_client(UDP * udp, char const * name, int domain)
{ {
memset(&udp->u, 0, sizeof(udp->u)); memset(&udp->u, 0, sizeof(udp->u));
/* obtain the remote address */ /* obtain the remote address */
if((udp->ai = _init_address(name, UDP_FAMILY, 0)) == NULL) if((udp->ai = _init_address(name, domain, 0)) == NULL)
return -1; return -1;
for(udp->aip = udp->ai; udp->aip != NULL; udp->aip = udp->aip->ai_next) for(udp->aip = udp->ai; udp->aip != NULL; udp->aip = udp->aip->ai_next)
{ {
@ -203,12 +203,12 @@ static int _init_client(UDP * udp, char const * name)
return 0; return 0;
} }
static int _init_server(UDP * udp, char const * name) static int _init_server(UDP * udp, char const * name, int domain)
{ {
udp->u.server.clients = NULL; udp->u.server.clients = NULL;
udp->u.server.clients_cnt = 0; udp->u.server.clients_cnt = 0;
/* obtain the local address */ /* obtain the local address */
if((udp->ai = _init_address(name, UDP_FAMILY, AI_PASSIVE)) == NULL) if((udp->ai = _init_address(name, domain, AI_PASSIVE)) == NULL)
return -1; return -1;
for(udp->aip = udp->ai; udp->aip != NULL; udp->aip = udp->aip->ai_next) for(udp->aip = udp->ai; udp->aip != NULL; udp->aip = udp->aip->ai_next)
{ {
@ -327,7 +327,7 @@ static int _udp_client_send(UDP * udp, AppTransportClient * client,
ntohs(sa->sin_port), buffer_get_size(buffer)); ntohs(sa->sin_port), buffer_get_size(buffer));
} }
else else
fprintf(stderr, "DEBUG: %s() %s family=%d size=%lu\n", __func__, fprintf(stderr, "DEBUG: %s() %s domain=%d size=%lu\n", __func__,
"sendto()", udp->aip->ai_family, "sendto()", udp->aip->ai_family,
buffer_get_size(buffer)); buffer_get_size(buffer));
#endif #endif
@ -366,7 +366,7 @@ static int _udp_send(UDP * udp, AppMessage * message)
ntohs(sa->sin_port), buffer_get_size(buffer)); ntohs(sa->sin_port), buffer_get_size(buffer));
} }
else else
fprintf(stderr, "DEBUG: %s() %s family=%d size=%lu\n", __func__, fprintf(stderr, "DEBUG: %s() %s domain=%d size=%lu\n", __func__,
"sendto()", udp->aip->ai_family, "sendto()", udp->aip->ai_family,
buffer_get_size(buffer)); buffer_get_size(buffer));
#endif #endif

View File

@ -15,5 +15,5 @@
#define UDP_FAMILY AF_INET #define UDP_DOMAIN AF_INET
#include "udp.c" #include "udp.c"

View File

@ -15,5 +15,5 @@
#define UDP_FAMILY AF_INET6 #define UDP_DOMAIN AF_INET6
#include "udp.c" #include "udp.c"