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,
|
AppTransportPlugin * (*init)(AppTransportPluginHelper * helper,
|
||||||
AppTransportMode mode, char const * name);
|
AppTransportMode mode, char const * name);
|
||||||
void (*destroy)(AppTransportPlugin * transport);
|
void (*destroy)(AppTransportPlugin * transport);
|
||||||
int (*send)(AppTransportPlugin * transport, AppMessage * message,
|
int (*send)(AppTransportPlugin * transport, AppMessage * message);
|
||||||
int acknowledge);
|
int (*client_send)(AppTransportPlugin * transport,
|
||||||
|
AppTransportClient * client, AppMessage * message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* !LIBAPP_APP_APPTRANSPORT_H */
|
#endif /* !LIBAPP_APP_APPTRANSPORT_H */
|
||||||
|
|
|
@ -45,6 +45,9 @@ struct _AppTransport
|
||||||
Plugin * plugin;
|
Plugin * plugin;
|
||||||
AppTransportPlugin * tplugin;
|
AppTransportPlugin * tplugin;
|
||||||
AppTransportPluginDefinition * definition;
|
AppTransportPluginDefinition * definition;
|
||||||
|
|
||||||
|
/* acknowledgements */
|
||||||
|
AppMessageID id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _AppTransportClient
|
struct _AppTransportClient
|
||||||
|
@ -129,12 +132,31 @@ void apptransport_delete(AppTransport * transport)
|
||||||
|
|
||||||
|
|
||||||
/* useful */
|
/* 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 */
|
/* apptransport_send */
|
||||||
int apptransport_send(AppTransport * transport, AppMessage * message,
|
int apptransport_send(AppTransport * transport, AppMessage * message,
|
||||||
int acknowledge)
|
int acknowledge)
|
||||||
{
|
{
|
||||||
return transport->definition->send(transport->tplugin, message,
|
if(transport->mode == ATM_CLIENT
|
||||||
acknowledge);
|
&& 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 */
|
/* XXX we can ignore errors */
|
||||||
if((message = appmessage_new_acknowledgement(id)) != NULL)
|
if((message = appmessage_new_acknowledgement(id)) != NULL)
|
||||||
{
|
{
|
||||||
apptransport_send(transport, message, 0);
|
apptransport_client_send(transport, client, message);
|
||||||
appmessage_delete(message);
|
appmessage_delete(message);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $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 file is part of DeforaOS System libApp */
|
||||||
/* This program is free software: you can redistribute it and/or modify
|
/* 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
|
* 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);
|
void apptransport_delete(AppTransport * transport);
|
||||||
|
|
||||||
/* useful */
|
/* useful */
|
||||||
|
int apptransport_client_send(AppTransport * transport,
|
||||||
|
AppTransportClient * client, AppMessage * message);
|
||||||
|
|
||||||
int apptransport_send(AppTransport * transport, AppMessage * message,
|
int apptransport_send(AppTransport * transport, AppMessage * message,
|
||||||
int acknowledge);
|
int acknowledge);
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,9 @@ static TCP * _tcp_init(AppTransportPluginHelper * helper, AppTransportMode mode,
|
||||||
char const * name);
|
char const * name);
|
||||||
static void _tcp_destroy(TCP * tcp);
|
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 */
|
/* useful */
|
||||||
static int _tcp_error(char const * message, int code);
|
static int _tcp_error(char const * message, int code);
|
||||||
|
@ -144,7 +146,8 @@ AppTransportPluginDefinition transport =
|
||||||
NULL,
|
NULL,
|
||||||
_tcp_init,
|
_tcp_init,
|
||||||
_tcp_destroy,
|
_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 */
|
/* tcp_send */
|
||||||
static int _tcp_send(TCP * tcp, AppMessage * message, int acknowledge)
|
static int _tcp_send(TCP * tcp, AppMessage * message)
|
||||||
{
|
{
|
||||||
Buffer * buffer;
|
Buffer * buffer;
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ AppTransportPluginDefinition transport =
|
||||||
NULL,
|
NULL,
|
||||||
_template_init,
|
_template_init,
|
||||||
_template_destroy,
|
_template_destroy,
|
||||||
|
NULL,
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,9 @@ static UDP * _udp_init(AppTransportPluginHelper * helper,
|
||||||
AppTransportMode mode, char const * name);
|
AppTransportMode mode, char const * name);
|
||||||
static void _udp_destroy(UDP * udp);
|
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 */
|
/* useful */
|
||||||
static int _udp_error(char const * message, int code);
|
static int _udp_error(char const * message, int code);
|
||||||
|
@ -123,7 +125,8 @@ AppTransportPluginDefinition transport =
|
||||||
NULL,
|
NULL,
|
||||||
_udp_init,
|
_udp_init,
|
||||||
_udp_destroy,
|
_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 */
|
/* udp_send */
|
||||||
static int _udp_send(UDP * udp, AppMessage * message, int acknowledge)
|
static int _udp_send(UDP * udp, AppMessage * message)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
Buffer * buffer;
|
Buffer * buffer;
|
||||||
|
|
|
@ -207,7 +207,7 @@ static int _transport_callback_idle(void * data)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
fprintf(stderr, "DEBUG: %s()\n", __func__);
|
||||||
#endif
|
#endif
|
||||||
transport->plugind->send(transport->client, transport->message, 0);
|
transport->plugind->send(transport->client, transport->message);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user