Partially synchronized with TCP code

This commit is contained in:
Pierre Pronchery 2012-10-18 00:09:58 +00:00
parent 09a113a3b1
commit 06ec462cc7

View File

@ -15,6 +15,12 @@
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <System.h>
#include "App/apptransport.h"
@ -38,6 +44,9 @@ static UDP * _udp_init(AppTransportPluginHelper * helper,
AppTransportMode mode, char const * name);
static void _udp_destroy(UDP * udp);
/* useful */
static int _udp_error(char const * message, int code);
/* public */
/* constants */
@ -56,19 +65,53 @@ AppTransportPluginDefinition definition =
/* functions */
/* plug-in */
/* udp_init */
static int _init_client(UDP * udp, char const * name);
static int _init_server(UDP * udp, char const * name);
static UDP * _udp_init(AppTransportPluginHelper * helper,
AppTransportMode mode, char const * name)
{
UDP * udp;
int res = -1;
if((udp = object_new(sizeof(*udp))) == NULL)
return NULL;
udp->helper = helper;
udp->fd = -1;
/* FIXME really implement */
switch(mode)
{
case ATM_CLIENT:
res = _init_client(udp, name);
break;
case ATM_SERVER:
res = _init_server(udp, name);
break;
}
/* check for errors */
if(res != 0)
{
_udp_destroy(udp);
return NULL;
}
return udp;
}
static int _init_client(UDP * udp, char const * name)
{
if((udp->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return -_udp_error("socket", 1);
/* FIXME really implement */
return -1;
}
static int _init_server(UDP * udp, char const * name)
{
if((udp->fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
return -_udp_error("socket", 1);
/* FIXME really implement */
return -1;
}
/* udp_destroy */
static void _udp_destroy(UDP * udp)
@ -76,3 +119,10 @@ static void _udp_destroy(UDP * udp)
/* FIXME really implement */
object_delete(udp);
}
/* useful */
static int _udp_error(char const * message, int code)
{
return error_set_code(code, "%s%s%s", (message != NULL) ? message : "",
(message != NULL) ? ": " : "", strerror(errno));
}