3 /* transport - low level communication */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2004 Martin Quinson. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
11 #include <time.h> /* time() */
14 #include "Transport/transport_private.h"
17 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(transport,GRAS);
19 static gras_dict_t *_gras_trp_plugins; /* All registered plugins */
20 static void gras_trp_plugin_free(void *p); /* free one of the plugins */
23 gras_dynar_t *_gras_trp_sockets; /* all existing sockets */
24 static void gras_trp_socket_free(void *s); /* free one socket */
31 gras_trp_plugin_t *plug;
33 /* make room for all socket ownership descriptions */
34 TRY(gras_dynar_new(&_gras_trp_sockets, sizeof(gras_socket_t*), NULL));
36 /* We do not ear for any socket for now */
39 /* make room for all plugins */
40 TRY(gras_dict_new(&_gras_trp_plugins));
43 TRY(gras_trp_tcp_init(&plug));
44 TRY(gras_dict_insert(_gras_trp_plugins,plug->name, plug, gras_trp_plugin_free));
51 gras_dict_free(&_gras_trp_plugins);
52 gras_dynar_free(_gras_trp_sockets);
56 void gras_trp_plugin_free(void *p) {
57 gras_trp_plugin_t *plug = p;
60 if (plug->free_specific && plug->specific)
61 plug->free_specific(plug->specific);
68 void gras_socket_close(gras_socket_t *sock) {
69 gras_socket_t *sock_iter;
72 /* FIXME: Issue an event when the socket is closed */
74 gras_dynar_foreach(_gras_trp_sockets,cursor,sock_iter) {
75 if (sock == sock_iter) {
76 gras_dynar_cursor_rm(_gras_trp_sockets,&cursor);
77 if (sock->plugin->socket_close)
78 (*sock->plugin->socket_close)(sock);
85 WARNING0("Ignoring request to free an unknown socket");
90 gras_trp_plugin_get_by_name(const char *name,
91 gras_trp_plugin_t **dst){
93 return gras_dict_retrieve(_gras_trp_plugins,name,(void**)dst);