3 #include "DataDesc/gs_private.h"
5 //GRAS_LOG_NEW_DEFAULT_CATEGORY(FIXME_net_driver);
8 gras_dict_t *p_net_driver_dict = NULL;
11 gs_net_drivers_init(void) {
14 TRYFAIL(gras_dict_new(&p_net_driver_dict));
15 TRYFAIL(gras_dict_insert(p_net_driver_dict, "fd", gs_fd_net_driver(), NULL));
19 struct s_gs_net_driver *
20 gs_net_driver_init(const char *name) {
22 struct s_gs_net_driver_ops *net_driver_ops = NULL;
23 struct s_gs_net_driver *p_net_driver = NULL;
25 gras_dict_retrieve(p_net_driver_dict, name, (void **)&net_driver_ops);
27 GS_FAILURE("net driver not found");
29 p_net_driver = calloc(1, sizeof (struct s_gs_net_driver));
30 p_net_driver->net_ops = net_driver_ops;
31 p_net_driver->connection_ops = NULL;
32 p_net_driver->specific = NULL;
34 if (net_driver_ops->_init) {
35 net_driver_ops->_init(p_net_driver);
44 gs_net_driver_exit(struct s_gs_net_driver *p_net_driver){
46 struct s_gs_net_driver_ops *net_driver_ops = NULL;
48 net_driver_ops = p_net_driver->net_ops;
49 if (net_driver_ops->_exit) {
50 net_driver_ops->_exit(p_net_driver);
53 p_net_driver->net_ops = NULL;
55 if (p_net_driver->specific) {
56 free(p_net_driver->specific);
57 p_net_driver->specific = NULL;
63 struct s_gs_connection *
64 gs_net_connection_connect(struct s_gs_net_driver *p_net_driver,
67 struct s_gs_connection_ops *connection_ops = p_net_driver->connection_ops;
68 struct s_gs_connection *p_connection = NULL;
70 p_connection = malloc(sizeof (struct s_gs_connection));
71 p_connection->connection_ops = connection_ops;
72 p_connection->p_net_driver = p_net_driver;
73 p_connection->direction = e_gs_connection_direction_outgoing;
75 if (connection_ops->_init) {
76 connection_ops->_init(p_connection, arg);
82 struct s_gs_connection *
83 gs_net_connection_accept(struct s_gs_net_driver *p_net_driver,
86 struct s_gs_connection_ops *connection_ops = p_net_driver->connection_ops;
87 struct s_gs_connection *p_connection = NULL;
89 p_connection = malloc(sizeof (struct s_gs_connection));
90 p_connection->connection_ops = connection_ops;
91 p_connection->p_net_driver = p_net_driver;
92 p_connection->direction = e_gs_connection_direction_incoming;
94 if (connection_ops->_init) {
95 connection_ops->_init(p_connection, arg);
102 gs_net_connection_close(struct s_gs_connection *p_connection) {
103 if (p_connection->connection_ops->_exit) {
104 p_connection->connection_ops->_exit(p_connection);
107 if (p_connection->specific) {
108 free(p_connection->specific);
109 p_connection->specific = NULL;