3 #include "gs/gs_private.h"
6 gras_dict_t *p_net_driver_dict = NULL;
9 gs_net_drivers_init(void) {
10 gras_dict_insert(p_net_driver_dict, "fd", gs_fd_net_driver(), NULL);
14 struct s_gs_net_driver *
15 gs_net_driver_init(const char *name) {
17 struct s_gs_net_driver_ops *net_driver_ops = NULL;
18 struct s_gs_net_driver *p_net_driver = NULL;
20 gras_dict_retrieve(p_net_driver_dict, name, (void **)&net_driver_ops);
22 GS_FAILURE("net driver not found");
24 p_net_driver = calloc(1, sizeof (struct s_gs_net_driver));
25 p_net_driver->net_ops = net_driver_ops;
26 p_net_driver->connection_ops = NULL;
27 p_net_driver->specific = NULL;
29 if (net_driver_ops->_init) {
30 net_driver_ops->_init(p_net_driver);
39 gs_net_driver_exit(struct s_gs_net_driver *p_net_driver){
41 struct s_gs_net_driver_ops *net_driver_ops = NULL;
43 net_driver_ops = p_net_driver->net_ops;
44 if (net_driver_ops->_exit) {
45 net_driver_ops->_exit(p_net_driver);
48 p_net_driver->net_ops = NULL;
50 if (p_net_driver->specific) {
51 free(p_net_driver->specific);
52 p_net_driver->specific = NULL;
58 struct s_gs_connection *
59 gs_net_connection_connect(struct s_gs_net_driver *p_net_driver,
62 struct s_gs_connection_ops *connection_ops = p_net_driver->connection_ops;
63 struct s_gs_connection *p_connection = NULL;
65 p_connection = malloc(sizeof (struct s_gs_connection));
66 p_connection->connection_ops = connection_ops;
67 p_connection->p_net_driver = p_net_driver;
68 p_connection->direction = e_gs_connection_direction_outgoing;
70 if (connection_ops->_init) {
71 connection_ops->_init(p_connection, arg);
77 struct s_gs_connection *
78 gs_net_connection_accept(struct s_gs_net_driver *p_net_driver,
81 struct s_gs_connection_ops *connection_ops = p_net_driver->connection_ops;
82 struct s_gs_connection *p_connection = NULL;
84 p_connection = malloc(sizeof (struct s_gs_connection));
85 p_connection->connection_ops = connection_ops;
86 p_connection->p_net_driver = p_net_driver;
87 p_connection->direction = e_gs_connection_direction_incoming;
89 if (connection_ops->_init) {
90 connection_ops->_init(p_connection, arg);
97 gs_net_connection_close(struct s_gs_connection *p_connection) {
98 if (p_connection->connection_ops->_exit) {
99 p_connection->connection_ops->_exit(p_connection);
102 if (p_connection->specific) {
103 free(p_connection->specific);
104 p_connection->specific = NULL;