Attempt to spare transport plug-ins from handling acknowledgements
This commit is contained in:
parent
1cd74f6859
commit
82ead01089
|
@ -73,8 +73,9 @@ struct _AppTransportPluginDefinition
|
|||
AppTransportPlugin * (*init)(AppTransportPluginHelper * helper,
|
||||
AppTransportMode mode, char const * name);
|
||||
void (*destroy)(AppTransportPlugin * transport);
|
||||
int (*send)(AppTransportPlugin * transport, AppMessage * message,
|
||||
int acknowledge);
|
||||
int (*send)(AppTransportPlugin * transport, AppMessage * message);
|
||||
int (*client_send)(AppTransportPlugin * transport,
|
||||
AppTransportClient * client, AppMessage * message);
|
||||
};
|
||||
|
||||
#endif /* !LIBAPP_APP_APPTRANSPORT_H */
|
||||
|
|
|
@ -45,6 +45,9 @@ struct _AppTransport
|
|||
Plugin * plugin;
|
||||
AppTransportPlugin * tplugin;
|
||||
AppTransportPluginDefinition * definition;
|
||||
|
||||
/* acknowledgements */
|
||||
AppMessageID id;
|
||||
};
|
||||
|
||||
struct _AppTransportClient
|
||||
|
@ -129,12 +132,31 @@ void apptransport_delete(AppTransport * transport)
|
|||
|
||||
|
||||
/* useful */
|
||||
/* apptransport_client_send */
|
||||
int apptransport_client_send(AppTransport * transport,
|
||||
AppTransportClient * client, AppMessage * message)
|
||||
{
|
||||
if(transport->mode != ATM_SERVER)
|
||||
return -error_set_code(1, "%s",
|
||||
"Only servers can reply to clients");
|
||||
if(transport->definition->client_send == NULL)
|
||||
return -error_set_code(1, "%s",
|
||||
"This transport does not support replies");
|
||||
return transport->definition->client_send(transport->tplugin, client,
|
||||
message);
|
||||
}
|
||||
|
||||
|
||||
/* apptransport_send */
|
||||
int apptransport_send(AppTransport * transport, AppMessage * message,
|
||||
int acknowledge)
|
||||
{
|
||||
return transport->definition->send(transport->tplugin, message,
|
||||
acknowledge);
|
||||
if(transport->mode == ATM_CLIENT
|
||||
&& appmessage_get_type(message) == AMT_CALL
|
||||
&& acknowledge != 0)
|
||||
/* FIXME will wrap around after 2^32-1 acknowledgements */
|
||||
appmessage_set_id(message, ++transport->id);
|
||||
return transport->definition->send(transport->tplugin, message);
|
||||
}
|
||||
|
||||
|
||||
|
@ -204,7 +226,7 @@ static int _apptransport_helper_client_receive(AppTransport * transport,
|
|||
/* XXX we can ignore errors */
|
||||
if((message = appmessage_new_acknowledgement(id)) != NULL)
|
||||
{
|
||||
apptransport_send(transport, message, 0);
|
||||
apptransport_client_send(transport, client, message);
|
||||
appmessage_delete(message);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012-2013 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2012-2014 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS System libApp */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -39,6 +39,9 @@ AppTransport * apptransport_new(AppTransportMode mode,
|
|||
void apptransport_delete(AppTransport * transport);
|
||||
|
||||
/* useful */
|
||||
int apptransport_client_send(AppTransport * transport,
|
||||
AppTransportClient * client, AppMessage * message);
|
||||
|
||||
int apptransport_send(AppTransport * transport, AppMessage * message,
|
||||
int acknowledge);
|
||||
|
||||
|
|
|
@ -109,7 +109,9 @@ static TCP * _tcp_init(AppTransportPluginHelper * helper, AppTransportMode mode,
|
|||
char const * name);
|
||||
static void _tcp_destroy(TCP * tcp);
|
||||
|
||||
static int _tcp_send(TCP * tcp, AppMessage * message, int acknowledge);
|
||||
static int _tcp_client_send(TCP * tcp, AppTransportClient * client,
|
||||
AppMessage * message);
|
||||
static int _tcp_send(TCP * tcp, AppMessage * message);
|
||||
|
||||
/* useful */
|
||||
static int _tcp_error(char const * message, int code);
|
||||
|
@ -144,7 +146,8 @@ AppTransportPluginDefinition transport =
|
|||
NULL,
|
||||
_tcp_init,
|
||||
_tcp_destroy,
|
||||
_tcp_send
|
||||
_tcp_send,
|
||||
_tcp_client_send
|
||||
};
|
||||
|
||||
|
||||
|
@ -354,8 +357,17 @@ static void _destroy_server(TCP * tcp)
|
|||
}
|
||||
|
||||
|
||||
/* tcp_client_send */
|
||||
static int _tcp_client_send(TCP * tcp, AppTransportClient * client,
|
||||
AppMessage * message)
|
||||
{
|
||||
/* FIXME implement */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* tcp_send */
|
||||
static int _tcp_send(TCP * tcp, AppMessage * message, int acknowledge)
|
||||
static int _tcp_send(TCP * tcp, AppMessage * message)
|
||||
{
|
||||
Buffer * buffer;
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ AppTransportPluginDefinition transport =
|
|||
NULL,
|
||||
_template_init,
|
||||
_template_destroy,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
|
@ -101,7 +101,9 @@ static UDP * _udp_init(AppTransportPluginHelper * helper,
|
|||
AppTransportMode mode, char const * name);
|
||||
static void _udp_destroy(UDP * udp);
|
||||
|
||||
static int _udp_send(UDP * udp, AppMessage * message, int acknowledge);
|
||||
static int _udp_client_send(UDP * udp, AppTransportClient * client,
|
||||
AppMessage * message);
|
||||
static int _udp_send(UDP * udp, AppMessage * message);
|
||||
|
||||
/* useful */
|
||||
static int _udp_error(char const * message, int code);
|
||||
|
@ -123,7 +125,8 @@ AppTransportPluginDefinition transport =
|
|||
NULL,
|
||||
_udp_init,
|
||||
_udp_destroy,
|
||||
_udp_send
|
||||
_udp_send,
|
||||
_udp_client_send
|
||||
};
|
||||
|
||||
|
||||
|
@ -285,8 +288,17 @@ static void _destroy_server(UDP * udp)
|
|||
}
|
||||
|
||||
|
||||
/* udp_client_send */
|
||||
static int _udp_client_send(UDP * udp, AppTransportClient * client,
|
||||
AppMessage * message)
|
||||
{
|
||||
/* FIXME implement */
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* udp_send */
|
||||
static int _udp_send(UDP * udp, AppMessage * message, int acknowledge)
|
||||
static int _udp_send(UDP * udp, AppMessage * message)
|
||||
{
|
||||
int ret;
|
||||
Buffer * buffer;
|
||||
|
|
|
@ -207,7 +207,7 @@ static int _transport_callback_idle(void * data)
|
|||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||
#endif
|
||||
transport->plugind->send(transport->client, transport->message, 0);
|
||||
transport->plugind->send(transport->client, transport->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user