From 82ead010898ad9156960cc6cf92249f1423d7110 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 23 Mar 2014 01:47:32 +0900 Subject: [PATCH] Attempt to spare transport plug-ins from handling acknowledgements --- include/App/apptransport.h | 5 +++-- src/apptransport.c | 28 +++++++++++++++++++++++++--- src/apptransport.h | 5 ++++- src/transport/tcp.c | 18 +++++++++++++++--- src/transport/template.c | 1 + src/transport/udp.c | 18 +++++++++++++++--- tests/transport.c | 2 +- 7 files changed, 64 insertions(+), 13 deletions(-) diff --git a/include/App/apptransport.h b/include/App/apptransport.h index 20daffb..2b81371 100644 --- a/include/App/apptransport.h +++ b/include/App/apptransport.h @@ -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 */ diff --git a/src/apptransport.c b/src/apptransport.c index 32f21ab..e085f52 100644 --- a/src/apptransport.c +++ b/src/apptransport.c @@ -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; diff --git a/src/apptransport.h b/src/apptransport.h index 633a180..4f09ab6 100644 --- a/src/apptransport.h +++ b/src/apptransport.h @@ -1,5 +1,5 @@ /* $Id$ */ -/* Copyright (c) 2012-2013 Pierre Pronchery */ +/* Copyright (c) 2012-2014 Pierre Pronchery */ /* 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); diff --git a/src/transport/tcp.c b/src/transport/tcp.c index b0f343f..183e3b9 100644 --- a/src/transport/tcp.c +++ b/src/transport/tcp.c @@ -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; diff --git a/src/transport/template.c b/src/transport/template.c index e492f33..c39fac6 100644 --- a/src/transport/template.c +++ b/src/transport/template.c @@ -48,6 +48,7 @@ AppTransportPluginDefinition transport = NULL, _template_init, _template_destroy, + NULL, NULL }; diff --git a/src/transport/udp.c b/src/transport/udp.c index 04e1461..817abf0 100644 --- a/src/transport/udp.c +++ b/src/transport/udp.c @@ -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; diff --git a/tests/transport.c b/tests/transport.c index f65543a..cb8d371 100644 --- a/tests/transport.c +++ b/tests/transport.c @@ -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; }