Commit f62b9ca9 authored by Dafydd Harries's avatar Dafydd Harries
Browse files

add wrappers for UDP vtable functions

darcs-hash:20070111192418-c9803-e45d7896b9d6a33cde41d8e73d850e940833a804.gz
parent 481e292f
AM_CFLAGS = -Wall -Werror $(GLIB_CFLAGS)
libudp_a_SOURCES = udp.h udp.c
libudp_a_SOURCES = udp.h udp.c udp-generic.c
noinst_LIBRARIES = libudp.a
......
......@@ -17,7 +17,7 @@ main (void)
udp_socket_manager_init (&man);
if (!man.init (&man, &sock, NULL))
if (!udp_socket_manager_alloc_socket (&man, &sock, NULL))
g_assert_not_reached ();
if (inet_pton (AF_INET, "127.0.0.1", &(sin.sin_addr)) < 0)
......@@ -34,12 +34,13 @@ main (void)
if (fgets (buf, sizeof (buf), stdin) == NULL)
break;
sock.send (&sock, &sin, strlen (buf), buf);
length = sock.recv (&sock, NULL, sizeof (buf), buf);
udp_socket_send (&sock, &sin, strlen (buf), buf);
length = udp_socket_recv (&sock, NULL, sizeof (buf), buf);
g_print (buf);
}
sock.close (&sock);
udp_socket_close (&sock);
udp_socket_manager_close (&man);
return 0;
}
#include <arpa/inet.h>
#include <glib.h>
#include <udp.h>
gboolean
udp_socket_manager_alloc_socket (
UDPSocketManager *man,
UDPSocket *sock,
struct sockaddr_in *sin)
{
return man->init (man, sock, sin);
}
void
udp_socket_manager_close (UDPSocketManager *man)
{
man->close (man);
}
guint
udp_socket_recv (
UDPSocket *sock,
struct sockaddr_in *sin,
guint len,
gchar *buf)
{
return sock->recv (sock, sin, len, buf);
}
void
udp_socket_send (
UDPSocket *sock,
struct sockaddr_in *sin,
guint len,
gchar *buf)
{
sock->send (sock, sin, len, buf);
}
void
udp_socket_close (UDPSocket *sock)
{
sock->close (sock);
}
......@@ -30,6 +30,28 @@ struct _UDPSocketManager
void
udp_socket_manager_init (UDPSocketManager *man);
gboolean
udp_socket_manager_alloc_socket (
UDPSocketManager *man,
UDPSocket *sock,
struct sockaddr_in *sin);
void
udp_socket_manager_close (UDPSocketManager *man);
guint
udp_socket_recv (
UDPSocket *sock,
struct sockaddr_in *sin,
guint len,
gchar *buf);
void
udp_socket_send (
UDPSocket *sock,
struct sockaddr_in *sin,
guint len,
gchar *buf);
void
udp_socket_close (UDPSocket *sock);
#endif /* _UDP_H */
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