Commit 7e665bf9 authored by Dafydd Harries's avatar Dafydd Harries

add "nice" prefix to UDP code

darcs-hash:20070201183830-c9803-6e562ea7405a931c59d56fbf67075fcaf90b1ee9.gz
parent aa301c19
...@@ -174,17 +174,17 @@ nice_event_free (Event *ev) ...@@ -174,17 +174,17 @@ nice_event_free (Event *ev)
/** /**
* nice_agent_new: * nice_agent_new:
* *
* @mgr: a UDPSocketManager used for allocating sockets * @factory: a NiceUDPSocketFactory used for allocating sockets
* *
* Create a new NiceAgent. * Create a new NiceAgent.
**/ **/
NiceAgent * NiceAgent *
nice_agent_new (UDPSocketManager *mgr) nice_agent_new (NiceUDPSocketFactory *factory)
{ {
NiceAgent *agent; NiceAgent *agent;
agent = g_slice_new0 (NiceAgent); agent = g_slice_new0 (NiceAgent);
agent->sockmgr = mgr; agent->socket_factory = factory;
agent->next_candidate_id = 1; agent->next_candidate_id = 1;
agent->next_stream_id = 1; agent->next_stream_id = 1;
return agent; return agent;
...@@ -247,7 +247,7 @@ nice_agent_add_local_host_candidate ( ...@@ -247,7 +247,7 @@ nice_agent_add_local_host_candidate (
sin.sin_addr.s_addr = htonl (address->addr_ipv4); sin.sin_addr.s_addr = htonl (address->addr_ipv4);
sin.sin_port = 0; sin.sin_port = 0;
/* XXX: handle error */ /* XXX: handle error */
udp_socket_manager_alloc_socket (agent->sockmgr, &(candidate->sock), &sin); nice_udp_socket_factory_make (agent->socket_factory, &(candidate->sock), &sin);
candidate->port = ntohs (candidate->sock.addr.sin_port); candidate->port = ntohs (candidate->sock.addr.sin_port);
} }
...@@ -496,7 +496,7 @@ RESPOND: ...@@ -496,7 +496,7 @@ RESPOND:
response->attributes[0] = stun_attribute_mapped_address_new ( response->attributes[0] = stun_attribute_mapped_address_new (
ntohl (from.sin_addr.s_addr), ntohs (from.sin_port)); ntohl (from.sin_addr.s_addr), ntohs (from.sin_port));
len = stun_message_pack (response, &packed); len = stun_message_pack (response, &packed);
udp_socket_send (&local->sock, &from, len, packed); nice_udp_socket_send (&local->sock, &from, len, packed);
g_free (packed); g_free (packed);
stun_message_free (response); stun_message_free (response);
...@@ -513,7 +513,7 @@ ERROR: ...@@ -513,7 +513,7 @@ ERROR:
response = stun_message_new (STUN_MESSAGE_BINDING_ERROR_RESPONSE, response = stun_message_new (STUN_MESSAGE_BINDING_ERROR_RESPONSE,
msg->transaction_id, 0); msg->transaction_id, 0);
len = stun_message_pack (response, &packed); len = stun_message_pack (response, &packed);
udp_socket_send (&local->sock, &from, len, packed); nice_udp_socket_send (&local->sock, &from, len, packed);
g_free (packed); g_free (packed);
stun_message_free (response); stun_message_free (response);
...@@ -542,7 +542,7 @@ _nice_agent_recv ( ...@@ -542,7 +542,7 @@ _nice_agent_recv (
gchar buf[1024]; gchar buf[1024];
struct sockaddr_in from; struct sockaddr_in from;
len = udp_socket_recv (&(candidate->sock), &from, len = nice_udp_socket_recv (&(candidate->sock), &from,
sizeof (buf) / sizeof (gchar), buf); sizeof (buf) / sizeof (gchar), buf);
g_assert (len > 0); g_assert (len > 0);
......
...@@ -57,7 +57,7 @@ struct _NiceAgent ...@@ -57,7 +57,7 @@ struct _NiceAgent
{ {
guint next_candidate_id; guint next_candidate_id;
guint next_stream_id; guint next_stream_id;
UDPSocketManager *sockmgr; NiceUDPSocketFactory *socket_factory;
GSList *local_addresses; GSList *local_addresses;
GSList *local_candidates; GSList *local_candidates;
GSList *remote_candidates; GSList *remote_candidates;
...@@ -72,7 +72,7 @@ typedef void (*NiceAgentRecvHandler) ( ...@@ -72,7 +72,7 @@ typedef void (*NiceAgentRecvHandler) (
NiceAgent * NiceAgent *
nice_agent_new (UDPSocketManager *mgr); nice_agent_new (NiceUDPSocketFactory *factory);
Event * Event *
nice_agent_pop_event (NiceAgent *agent); nice_agent_pop_event (NiceAgent *agent);
......
...@@ -29,7 +29,7 @@ struct _NiceCandidate ...@@ -29,7 +29,7 @@ struct _NiceCandidate
guint component_id; guint component_id;
// guint generation; // guint generation;
// gchar *foundation; // gchar *foundation;
UDPSocket sock; NiceUDPSocket sock;
gchar username[128]; gchar username[128];
gchar password[128]; gchar password[128];
}; };
......
...@@ -29,14 +29,14 @@ main (void) ...@@ -29,14 +29,14 @@ main (void)
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr; NiceAddress addr;
NiceCandidate *candidate; NiceCandidate *candidate;
UDPSocketManager mgr; NiceUDPSocketFactory factory;
UDPSocket *sock; NiceUDPSocket *sock;
struct sockaddr_in from = {0,}; struct sockaddr_in from = {0,};
udp_fake_socket_manager_init (&mgr); nice_udp_fake_socket_factory_init (&factory);
/* set up agent */ /* set up agent */
agent = nice_agent_new (&mgr); agent = nice_agent_new (&factory);
nice_address_set_ipv4_from_string (&addr, "192.168.0.1"); nice_address_set_ipv4_from_string (&addr, "192.168.0.1");
nice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
nice_agent_add_stream (agent, handle_recv, NULL); nice_agent_add_stream (agent, handle_recv, NULL);
...@@ -45,13 +45,13 @@ main (void) ...@@ -45,13 +45,13 @@ main (void)
/* recieve an RTP packet */ /* recieve an RTP packet */
candidate = agent->local_candidates->data; candidate = agent->local_candidates->data;
sock = &(candidate->sock); sock = &(candidate->sock);
udp_fake_socket_push_recv (sock, &from, 7, "\x80lalala"); nice_udp_fake_socket_push_recv (sock, &from, 7, "\x80lalala");
nice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
g_assert (cb_called == TRUE); g_assert (cb_called == TRUE);
/* clean up */ /* clean up */
nice_agent_free (agent); nice_agent_free (agent);
udp_socket_manager_close (&mgr); nice_udp_socket_factory_close (&factory);
return 0; return 0;
} }
......
...@@ -23,7 +23,7 @@ test_stun_no_password ( ...@@ -23,7 +23,7 @@ test_stun_no_password (
struct sockaddr_in from) struct sockaddr_in from)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
UDPSocket *sock; NiceUDPSocket *sock;
guint len; guint len;
struct sockaddr_in to = {0,}; struct sockaddr_in to = {0,};
gchar buf[1024]; gchar buf[1024];
...@@ -42,7 +42,7 @@ test_stun_no_password ( ...@@ -42,7 +42,7 @@ test_stun_no_password (
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
"0123456789abcdef", 0); "0123456789abcdef", 0);
packed_len = stun_message_pack (breq, &packed); packed_len = stun_message_pack (breq, &packed);
udp_fake_socket_push_recv (sock, &from, packed_len, packed); nice_udp_fake_socket_push_recv (sock, &from, packed_len, packed);
g_free (packed); g_free (packed);
stun_message_free (breq); stun_message_free (breq);
} }
...@@ -51,7 +51,7 @@ test_stun_no_password ( ...@@ -51,7 +51,7 @@ test_stun_no_password (
nice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
/* error response should have been sent */ /* error response should have been sent */
len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar), len = nice_udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar),
buf); buf);
g_assert (len != 0); g_assert (len != 0);
...@@ -74,7 +74,7 @@ test_stun_invalid_password ( ...@@ -74,7 +74,7 @@ test_stun_invalid_password (
struct sockaddr_in from) struct sockaddr_in from)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
UDPSocket *sock; NiceUDPSocket *sock;
guint len; guint len;
struct sockaddr_in to = {0,}; struct sockaddr_in to = {0,};
gchar buf[1024]; gchar buf[1024];
...@@ -95,7 +95,7 @@ test_stun_invalid_password ( ...@@ -95,7 +95,7 @@ test_stun_invalid_password (
breq->attributes[0] = stun_attribute_username_new ("lala"); breq->attributes[0] = stun_attribute_username_new ("lala");
packed_len = stun_message_pack (breq, &packed); packed_len = stun_message_pack (breq, &packed);
g_assert (packed_len != 0); g_assert (packed_len != 0);
udp_fake_socket_push_recv (sock, &from, packed_len, packed); nice_udp_fake_socket_push_recv (sock, &from, packed_len, packed);
g_free (packed); g_free (packed);
stun_message_free (breq); stun_message_free (breq);
} }
...@@ -104,7 +104,7 @@ test_stun_invalid_password ( ...@@ -104,7 +104,7 @@ test_stun_invalid_password (
nice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
/* error should have been sent */ /* error should have been sent */
len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar), len = nice_udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar),
buf); buf);
g_assert (len != 0); g_assert (len != 0);
...@@ -127,7 +127,7 @@ test_stun_valid_password ( ...@@ -127,7 +127,7 @@ test_stun_valid_password (
struct sockaddr_in from) struct sockaddr_in from)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
UDPSocket *sock; NiceUDPSocket *sock;
guint len; guint len;
guint packed_len; guint packed_len;
struct sockaddr_in to = {0,}; struct sockaddr_in to = {0,};
...@@ -156,7 +156,7 @@ test_stun_valid_password ( ...@@ -156,7 +156,7 @@ test_stun_valid_password (
g_free (username); g_free (username);
packed_len = stun_message_pack (breq, &packed); packed_len = stun_message_pack (breq, &packed);
g_assert (packed_len != 0); g_assert (packed_len != 0);
udp_fake_socket_push_recv (sock, &from, packed_len, packed); nice_udp_fake_socket_push_recv (sock, &from, packed_len, packed);
g_free (packed); g_free (packed);
stun_message_free (breq); stun_message_free (breq);
} }
...@@ -178,7 +178,7 @@ test_stun_valid_password ( ...@@ -178,7 +178,7 @@ test_stun_valid_password (
nice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
/* compare sent packet to expected */ /* compare sent packet to expected */
len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar), len = nice_udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar),
buf); buf);
g_assert (len == packed_len); g_assert (len == packed_len);
g_assert (0 == memcmp (buf, packed, len)); g_assert (0 == memcmp (buf, packed, len));
...@@ -194,11 +194,11 @@ main (void) ...@@ -194,11 +194,11 @@ main (void)
NiceAgent *agent; NiceAgent *agent;
NiceAddress local_addr, remote_addr; NiceAddress local_addr, remote_addr;
NiceCandidate *candidate; NiceCandidate *candidate;
UDPSocketManager mgr; NiceUDPSocketFactory factory;
UDPSocket *sock; NiceUDPSocket *sock;
struct sockaddr_in from = {0,}; struct sockaddr_in from = {0,};
udp_fake_socket_manager_init (&mgr); nice_udp_fake_socket_factory_init (&factory);
nice_address_set_ipv4_from_string (&local_addr, "192.168.0.1"); nice_address_set_ipv4_from_string (&local_addr, "192.168.0.1");
nice_address_set_ipv4_from_string (&remote_addr, "192.168.0.5"); nice_address_set_ipv4_from_string (&remote_addr, "192.168.0.5");
...@@ -208,7 +208,7 @@ main (void) ...@@ -208,7 +208,7 @@ main (void)
from.sin_port = htons (5678); from.sin_port = htons (5678);
/* set up agent */ /* set up agent */
agent = nice_agent_new (&mgr); agent = nice_agent_new (&factory);
nice_agent_add_local_address (agent, &local_addr); nice_agent_add_local_address (agent, &local_addr);
nice_agent_add_stream (agent, handle_recv, NULL); nice_agent_add_stream (agent, handle_recv, NULL);
nice_agent_add_remote_candidate (agent, 1, 1, NICE_CANDIDATE_TYPE_HOST, nice_agent_add_remote_candidate (agent, 1, 1, NICE_CANDIDATE_TYPE_HOST,
...@@ -224,7 +224,7 @@ main (void) ...@@ -224,7 +224,7 @@ main (void)
/* clean up */ /* clean up */
nice_agent_free (agent); nice_agent_free (agent);
udp_socket_manager_close (&mgr); nice_udp_socket_factory_close (&factory);
return 0; return 0;
} }
......
...@@ -22,14 +22,14 @@ main (void) ...@@ -22,14 +22,14 @@ main (void)
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr_local, addr_remote; NiceAddress addr_local, addr_remote;
NiceCandidate *candidate; NiceCandidate *candidate;
UDPSocketManager mgr; NiceUDPSocketFactory factory;
udp_fake_socket_manager_init (&mgr); nice_udp_fake_socket_factory_init (&factory);
nice_address_set_ipv4_from_string (&addr_local, "192.168.0.1"); nice_address_set_ipv4_from_string (&addr_local, "192.168.0.1");
nice_address_set_ipv4_from_string (&addr_remote, "192.168.0.2"); nice_address_set_ipv4_from_string (&addr_remote, "192.168.0.2");
agent = nice_agent_new (&mgr); agent = nice_agent_new (&factory);
g_assert (agent->local_addresses == NULL); g_assert (agent->local_addresses == NULL);
g_assert (agent->local_candidates == NULL); g_assert (agent->local_candidates == NULL);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "stun.h" #include "stun.h"
static void static void
send_stun (UDPSocket *udpsock, struct sockaddr_in sin) send_stun (NiceUDPSocket *udpsock, struct sockaddr_in sin)
{ {
gchar *packed; gchar *packed;
guint packed_len; guint packed_len;
...@@ -27,11 +27,11 @@ send_stun (UDPSocket *udpsock, struct sockaddr_in sin) ...@@ -27,11 +27,11 @@ send_stun (UDPSocket *udpsock, struct sockaddr_in sin)
} }
packed_len = stun_message_pack (msg, &packed); packed_len = stun_message_pack (msg, &packed);
udp_socket_send (udpsock, &sin, packed_len, packed); nice_udp_socket_send (udpsock, &sin, packed_len, packed);
g_free (packed); g_free (packed);
stun_message_free (msg); stun_message_free (msg);
packed_len = udp_socket_recv (udpsock, &sin, 1024, buf); packed_len = nice_udp_socket_recv (udpsock, &sin, 1024, buf);
g_assert (packed_len > 0); g_assert (packed_len > 0);
msg = stun_message_unpack (packed_len, buf); msg = stun_message_unpack (packed_len, buf);
g_assert (msg); g_assert (msg);
...@@ -51,8 +51,8 @@ handle_connection (guint sock) ...@@ -51,8 +51,8 @@ handle_connection (guint sock)
{ {
gchar *line; gchar *line;
struct sockaddr_in sin; struct sockaddr_in sin;
UDPSocketManager man; NiceUDPSocketFactory man;
UDPSocket udpsock; NiceUDPSocket udpsock;
NiceCandidate *candidate; NiceCandidate *candidate;
line = readline (sock); line = readline (sock);
...@@ -67,13 +67,13 @@ handle_connection (guint sock) ...@@ -67,13 +67,13 @@ handle_connection (guint sock)
g_debug ("got candidate"); g_debug ("got candidate");
udp_bsd_socket_manager_init (&man); nice_udp_bsd_socket_factory_init (&man);
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY; sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = 0; sin.sin_port = 0;
if (!udp_socket_manager_alloc_socket (&man, &udpsock, &sin)) if (!nice_udp_socket_factory_make (&man, &udpsock, &sin))
goto OUT; goto OUT;
// copy remote candidate address into sin // copy remote candidate address into sin
...@@ -83,11 +83,11 @@ handle_connection (guint sock) ...@@ -83,11 +83,11 @@ handle_connection (guint sock)
// agent doesn't proactively do STUN, so we have to do it ourselves for now // agent doesn't proactively do STUN, so we have to do it ourselves for now
send_stun (&udpsock, sin); send_stun (&udpsock, sin);
udp_socket_send (&udpsock, &sin, 6, "\x80hello"); nice_udp_socket_send (&udpsock, &sin, 6, "\x80hello");
udp_socket_close (&udpsock); nice_udp_socket_close (&udpsock);
OUT: OUT:
udp_socket_manager_close (&man); nice_udp_socket_factory_close (&man);
nice_candidate_free (candidate); nice_candidate_free (candidate);
} }
......
...@@ -25,15 +25,15 @@ handle_recv ( ...@@ -25,15 +25,15 @@ handle_recv (
static gboolean static gboolean
make_agent ( make_agent (
gchar *ip, gchar *ip,
UDPSocketManager *mgr, NiceUDPSocketFactory *factory,
NiceAgent **ret_agent, NiceAgent **ret_agent,
UDPSocket **ret_sock) NiceUDPSocket **ret_sock)
{ {
NiceAgent *agent; NiceAgent *agent;
NiceAddress addr_local; NiceAddress addr_local;
NiceCandidate *candidate; NiceCandidate *candidate;
agent = nice_agent_new (mgr); agent = nice_agent_new (factory);
nice_address_set_ipv4_from_string (&addr_local, ip); nice_address_set_ipv4_from_string (&addr_local, ip);
nice_agent_add_local_address (agent, &addr_local); nice_agent_add_local_address (agent, &addr_local);
...@@ -70,8 +70,8 @@ static void ...@@ -70,8 +70,8 @@ static void
handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
{ {
NiceAgent *agent; NiceAgent *agent;
UDPSocketManager mgr; NiceUDPSocketFactory factory;
UDPSocket *sock; NiceUDPSocket *sock;
GSList *sockets = NULL; GSList *sockets = NULL;
gchar ip_str[INET_ADDRSTRLEN]; gchar ip_str[INET_ADDRSTRLEN];
fd_set fds; fd_set fds;
...@@ -81,9 +81,9 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -81,9 +81,9 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
inet_ntop (AF_INET, &(sin->sin_addr), ip_str, INET_ADDRSTRLEN); inet_ntop (AF_INET, &(sin->sin_addr), ip_str, INET_ADDRSTRLEN);
g_debug ("got connection from %s:%d", ip_str, ntohs (sin->sin_port)); g_debug ("got connection from %s:%d", ip_str, ntohs (sin->sin_port));
udp_bsd_socket_manager_init (&mgr); nice_udp_bsd_socket_factory_init (&factory);
if (!make_agent ((gchar *) data, &mgr, &agent, &sock)) if (!make_agent ((gchar *) data, &factory, &agent, &sock))
return; return;
sockets = g_slist_append (sockets, sock); sockets = g_slist_append (sockets, sock);
...@@ -141,17 +141,17 @@ END: ...@@ -141,17 +141,17 @@ END:
while (sockets != NULL) while (sockets != NULL)
{ {
GSList *tmp; GSList *tmp;
UDPSocket *sock = sockets->data; NiceUDPSocket *sock = sockets->data;
tmp = sockets; tmp = sockets;
sockets = sockets->next; sockets = sockets->next;
g_slist_free_1 (tmp); g_slist_free_1 (tmp);
udp_socket_close (sock); nice_udp_socket_close (sock);
g_slice_free (UDPSocket, sock); g_slice_free (NiceUDPSocket, sock);
} }
g_slist_free (sockets); g_slist_free (sockets);
udp_socket_manager_close (&mgr); nice_udp_socket_factory_close (&factory);
} }
static gboolean static gboolean
......
...@@ -25,12 +25,12 @@ T nice_rng_generate_bytes ...@@ -25,12 +25,12 @@ T nice_rng_generate_bytes
T nice_rng_generate_bytes_print T nice_rng_generate_bytes_print
T nice_rng_generate_int T nice_rng_generate_int
T nice_rng_new T nice_rng_new
T udp_bsd_socket_manager_init T nice_udp_bsd_socket_factory_init
T udp_fake_socket_manager_init T nice_udp_fake_socket_factory_init
T udp_fake_socket_pop_send T nice_udp_fake_socket_pop_send
T udp_fake_socket_push_recv T nice_udp_fake_socket_push_recv
T udp_socket_close T nice_udp_socket_close
T udp_socket_manager_alloc_socket T nice_udp_socket_factory_close
T udp_socket_manager_close T nice_udp_socket_factory_make
T udp_socket_recv T nice_udp_socket_recv
T udp_socket_send T nice_udp_socket_send
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
int int
main (void) main (void)
{ {
UDPSocketManager man; NiceUDPSocketFactory man;
UDPSocket sock; NiceUDPSocket sock;
struct sockaddr_in sin = {0,}; struct sockaddr_in sin = {0,};
guint len; guint len;
gchar buf[1024]; gchar buf[1024];
udp_fake_socket_manager_init (&man); nice_udp_fake_socket_factory_init (&man);
memset (buf, '\0', 1024); memset (buf, '\0', 1024);
...@@ -21,7 +21,7 @@ main (void) ...@@ -21,7 +21,7 @@ main (void)
sin.sin_addr.s_addr = INADDR_ANY; sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = 0; sin.sin_port = 0;
udp_socket_manager_alloc_socket (&man, &sock, &sin); nice_udp_socket_factory_make (&man, &sock, &sin);
/* test recv */ /* test recv */
...@@ -29,12 +29,12 @@ main (void) ...@@ -29,12 +29,12 @@ main (void)
len = 5; len = 5;
sin.sin_addr.s_addr = htonl (0x01020304); sin.sin_addr.s_addr = htonl (0x01020304);
sin.sin_port = htons (2345); sin.sin_port = htons (2345);
udp_fake_socket_push_recv (&sock, &sin, len, buf); nice_udp_fake_socket_push_recv (&sock, &sin, len, buf);
memset (buf, '\0', 5); memset (buf, '\0', 5);
memset (&sin, '\0', sizeof (sin)); memset (&sin, '\0', sizeof (sin));
len = udp_socket_recv (&sock, &sin, sizeof (buf), buf); len = nice_udp_socket_recv (&sock, &sin, sizeof (buf), buf);
g_assert (len == 5); g_assert (len == 5);
g_assert (memcmp (buf, "he\0lo", 5) == 0); g_assert (memcmp (buf, "he\0lo", 5) == 0);
g_assert (ntohl (sin.sin_addr.s_addr) == 0x01020304); g_assert (ntohl (sin.sin_addr.s_addr) == 0x01020304);
...@@ -44,19 +44,19 @@ main (void) ...@@ -44,19 +44,19 @@ main (void)
memcpy (buf, "la\0la", 5); memcpy (buf, "la\0la", 5);
len = 5; len = 5;
udp_socket_send (&sock, &sin, len, buf); nice_udp_socket_send (&sock, &sin, len, buf);
memset (buf, '\0', len); memset (buf, '\0', len);
memset (&sin, '\0', sizeof (sin)); memset (&sin, '\0', sizeof (sin));
len = udp_fake_socket_pop_send (&sock, &sin, sizeof (buf), buf); len = nice_udp_fake_socket_pop_send (&sock, &sin, sizeof (buf), buf);
g_assert (len == 5); g_assert (len == 5);
g_assert (0 == memcmp (buf, "la\0la", 5)); g_assert (0 == memcmp (buf, "la\0la", 5));
g_assert (ntohl (sin.sin_addr.s_addr) == 0x01020304); g_assert (ntohl (sin.sin_addr.s_addr) == 0x01020304);
g_assert (ntohs (sin.sin_port) == 2345); g_assert (ntohs (sin.sin_port) == 2345);
udp_socket_close (&sock); nice_udp_socket_close (&sock);
udp_socket_manager_close (&man); nice_udp_socket_factory_close (&man);
return 0; return 0;
} }
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
#include "udp-bsd.h" #include "udp-bsd.h"
/*** UDPSocket ***/ /*** NiceUDPSocket ***/
static gint static gint
socket_recv ( socket_recv (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *from, struct sockaddr_in *from,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -28,7 +28,7 @@ socket_recv ( ...@@ -28,7 +28,7 @@ socket_recv (
static gboolean static gboolean
socket_send ( socket_send (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *to, struct sockaddr_in *to,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -39,17 +39,17 @@ socket_send ( ...@@ -39,17 +39,17 @@ socket_send (
} }
static void static void
socket_close (UDPSocket *sock) socket_close (NiceUDPSocket *sock)
{ {
close (sock->fileno); close (sock->fileno);
} }
/*** UDPSocketManager ***/ /*** NiceUDPSocketFactory ***/
static gboolean static gboolean
socket_manager_init_socket ( socket_factory_init_socket (
UDPSocketManager *man, NiceUDPSocketFactory *man,
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin) struct sockaddr_in *sin)
{ {
gint sockfd; gint sockfd;
...@@ -81,21 +81,21 @@ socket_manager_init_socket ( ...@@ -81,21 +81,21 @@ socket_manager_init_socket (
} }
static void static void
socket_manager_select (UDPPacketRecvFunc cb) socket_factory_select (NiceUDPRecvFunc cb)
{ {
g_assert_not_reached (); g_assert_not_reached ();
} }
static void static void
socket_manager_close (UDPSocketManager *man) socket_factory_close (NiceUDPSocketFactory *man)
{ {
} }
void void
udp_bsd_socket_manager_init (UDPSocketManager *man) nice_udp_bsd_socket_factory_init (NiceUDPSocketFactory *man)
{ {
man->init = socket_manager_init_socket; man->init = socket_factory_init_socket;
man->select = socket_manager_select; man->select = socket_factory_select;
man->close = socket_manager_close; man->close = socket_factory_close;
} }
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
void void
udp_bsd_socket_manager_init (UDPSocketManager *man); nice_udp_bsd_socket_factory_init (NiceUDPSocketFactory *man);
G_END_DECLS G_END_DECLS
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
gint gint
main (void) main (void)
{ {
UDPSocketManager man; NiceUDPSocketFactory man;
UDPSocket sock; NiceUDPSocket sock;
struct sockaddr_in sin; struct sockaddr_in sin;
udp_bsd_socket_manager_init (&man); nice_udp_bsd_socket_factory_init (&man);
if (!udp_socket_manager_alloc_socket (&man, &sock, NULL)) if (!nice_udp_socket_factory_make (&man, &sock, NULL))
g_assert_not_reached (); g_assert_not_reached ();
if (inet_pton (AF_INET, "127.0.0.1", &(sin.sin_addr)) < 0) if (inet_pton (AF_INET, "127.0.0.1", &(sin.sin_addr)) < 0)
...@@ -30,13 +30,13 @@ main (void) ...@@ -30,13 +30,13 @@ main (void)
if (fgets (buf, sizeof (buf), stdin) == NULL) if (fgets (buf, sizeof (buf), stdin) == NULL)
break; break;
udp_socket_send (&sock, &sin, strlen (buf), buf); nice_udp_socket_send (&sock, &sin, strlen (buf), buf);
length = udp_socket_recv (&sock, NULL, sizeof (buf), buf); length = nice_udp_socket_recv (&sock, NULL, sizeof (buf), buf);
g_print (buf); g_print (buf);
} }
udp_socket_close (&sock); nice_udp_socket_close (&sock);
udp_socket_manager_close (&man); nice_udp_socket_factory_close (&man);
return 0; return 0;
} }
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
gint gint
main (void) main (void)
{ {
UDPSocketManager man; NiceUDPSocketFactory man;
UDPSocket sock; NiceUDPSocket sock;
struct sockaddr_in sin; struct sockaddr_in sin;
udp_bsd_socket_manager_init (&man); nice_udp_bsd_socket_factory_init (&man);
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY; sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons (9999); sin.sin_port = htons (9999);
......
...@@ -44,7 +44,7 @@ _g_slist_pop (GSList **list) ...@@ -44,7 +44,7 @@ _g_slist_pop (GSList **list)
static gboolean static gboolean
fake_send ( fake_send (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *to, struct sockaddr_in *to,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -65,7 +65,7 @@ fake_send ( ...@@ -65,7 +65,7 @@ fake_send (
static gint static gint
fake_recv ( fake_recv (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *from, struct sockaddr_in *from,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -82,7 +82,7 @@ fake_recv ( ...@@ -82,7 +82,7 @@ fake_recv (
} }
static void static void
fake_close (UDPSocket *sock) fake_close (NiceUDPSocket *sock)
{ {
UDPFakeSocketPriv *priv; UDPFakeSocketPriv *priv;
...@@ -95,8 +95,8 @@ fake_close (UDPSocket *sock) ...@@ -95,8 +95,8 @@ fake_close (UDPSocket *sock)
/* XXX: copied INADDR_ANY to sock->addr rather than using a valid address */ /* XXX: copied INADDR_ANY to sock->addr rather than using a valid address */
static gboolean static gboolean
fake_socket_init ( fake_socket_init (
UDPSocketManager *man, NiceUDPSocketFactory *man,
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin) struct sockaddr_in *sin)
{ {
int fds[2]; int fds[2];
...@@ -127,8 +127,8 @@ fake_socket_init ( ...@@ -127,8 +127,8 @@ fake_socket_init (
} }
void void
udp_fake_socket_push_recv ( nice_udp_fake_socket_push_recv (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *from, struct sockaddr_in *from,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -142,8 +142,8 @@ udp_fake_socket_push_recv ( ...@@ -142,8 +142,8 @@ udp_fake_socket_push_recv (
} }
guint guint
udp_fake_socket_pop_send ( nice_udp_fake_socket_pop_send (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *to, struct sockaddr_in *to,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -165,16 +165,16 @@ udp_fake_socket_pop_send ( ...@@ -165,16 +165,16 @@ udp_fake_socket_pop_send (
} }
static void static void
fake_socket_manager_close (UDPSocketManager *man) fake_socket_factory_close (NiceUDPSocketFactory *man)
{ {
} }
void void
udp_fake_socket_manager_init (UDPSocketManager *man) nice_udp_fake_socket_factory_init (NiceUDPSocketFactory *man)
{ {
man->init = fake_socket_init; man->init = fake_socket_init;
man->select = NULL; man->select = NULL;
man->close = fake_socket_manager_close; man->close = fake_socket_factory_close;
man->priv = NULL; man->priv = NULL;
} }
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
G_BEGIN_DECLS G_BEGIN_DECLS
void void
udp_fake_socket_manager_init (UDPSocketManager *man); nice_udp_fake_socket_factory_init (NiceUDPSocketFactory *man);
void void
udp_fake_socket_push_recv ( nice_udp_fake_socket_push_recv (
UDPSocket *man, NiceUDPSocket *man,
struct sockaddr_in *from, struct sockaddr_in *from,
guint len, guint len,
gchar *buf); gchar *buf);
guint guint
udp_fake_socket_pop_send ( nice_udp_fake_socket_pop_send (
UDPSocket *man, NiceUDPSocket *man,
struct sockaddr_in *to, struct sockaddr_in *to,
guint len, guint len,
gchar *buf); gchar *buf);
......
...@@ -6,23 +6,23 @@ ...@@ -6,23 +6,23 @@
#include <udp.h> #include <udp.h>
gboolean gboolean
udp_socket_manager_alloc_socket ( nice_udp_socket_factory_make (
UDPSocketManager *man, NiceUDPSocketFactory *man,
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin) struct sockaddr_in *sin)
{ {
return man->init (man, sock, sin); return man->init (man, sock, sin);
} }
void void
udp_socket_manager_close (UDPSocketManager *man) nice_udp_socket_factory_close (NiceUDPSocketFactory *man)
{ {
man->close (man); man->close (man);
} }
guint guint
udp_socket_recv ( nice_udp_socket_recv (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin, struct sockaddr_in *sin,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -31,8 +31,8 @@ udp_socket_recv ( ...@@ -31,8 +31,8 @@ udp_socket_recv (
} }
void void
udp_socket_send ( nice_udp_socket_send (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin, struct sockaddr_in *sin,
guint len, guint len,
gchar *buf) gchar *buf)
...@@ -41,7 +41,7 @@ udp_socket_send ( ...@@ -41,7 +41,7 @@ udp_socket_send (
} }
void void
udp_socket_close (UDPSocket *sock) nice_udp_socket_close (NiceUDPSocket *sock)
{ {
sock->close (sock); sock->close (sock);
} }
......
...@@ -8,31 +8,31 @@ ...@@ -8,31 +8,31 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef struct _UDPSocket UDPSocket; typedef struct _UDPSocket NiceUDPSocket;
struct _UDPSocket struct _UDPSocket
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
guint fileno; guint fileno;
gint (*recv) (UDPSocket *sock, struct sockaddr_in *from, guint len, gint (*recv) (NiceUDPSocket *sock, struct sockaddr_in *from, guint len,
gchar *buf); gchar *buf);
gboolean (*send) (UDPSocket *sock, struct sockaddr_in *to, guint len, gboolean (*send) (NiceUDPSocket *sock, struct sockaddr_in *to, guint len,
gchar *buf); gchar *buf);
void (*close) (UDPSocket *sock); void (*close) (NiceUDPSocket *sock);
void *priv; void *priv;
}; };
typedef gboolean (*UDPPacketRecvFunc) (struct sockaddr_in *from, guint len, typedef gboolean (*NiceUDPRecvFunc) (struct sockaddr_in *from, guint len,
gchar *buf); gchar *buf);
typedef struct _UDPSocketManager UDPSocketManager; typedef struct _UDPSocketManager NiceUDPSocketFactory;
struct _UDPSocketManager struct _UDPSocketManager
{ {
gboolean (*init) (UDPSocketManager *man, UDPSocket *sock, gboolean (*init) (NiceUDPSocketFactory *man, NiceUDPSocket *sock,
struct sockaddr_in *sin); struct sockaddr_in *sin);
void (*select) (UDPPacketRecvFunc cb); void (*select) (NiceUDPRecvFunc cb);
void (*close) (UDPSocketManager *man); void (*close) (NiceUDPSocketFactory *man);
void *priv; void *priv;
}; };
...@@ -42,30 +42,30 @@ struct _UDPSocketManager ...@@ -42,30 +42,30 @@ struct _UDPSocketManager
* address bound to will be set in sock->addr. * address bound to will be set in sock->addr.
*/ */
gboolean gboolean
udp_socket_manager_alloc_socket ( nice_udp_socket_factory_make (
UDPSocketManager *man, NiceUDPSocketFactory *man,
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin); struct sockaddr_in *sin);
void void
udp_socket_manager_close (UDPSocketManager *man); nice_udp_socket_factory_close (NiceUDPSocketFactory *man);
guint guint
udp_socket_recv ( nice_udp_socket_recv (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin, struct sockaddr_in *sin,
guint len, guint len,
gchar *buf); gchar *buf);
void void
udp_socket_send ( nice_udp_socket_send (
UDPSocket *sock, NiceUDPSocket *sock,
struct sockaddr_in *sin, struct sockaddr_in *sin,
guint len, guint len,
gchar *buf); gchar *buf);
void void
udp_socket_close (UDPSocket *sock); nice_udp_socket_close (NiceUDPSocket *sock);
G_END_DECLS G_END_DECLS
......
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