1globus_net_manager_tutorial(3)globus_net_managerglobus_net_manager_tutorial(3)
2
3
4

NAME

6       globus_net_manager_tutorial - Net Manager Implementation Tutorial
7
8       This example uses functionality from globus_common and
9       globus_net_manager modules, so the headers for those must be included:
10
11       #include "globus_common.h"
12       #include "globus_net_manager.h"
13
14        To implement a network manager, define a struct globus_net_manager_s
15       containing pointers to the functions in your code that you want invoked
16       during network events, and pass that to globus_net_manager_register().
17       Applications which use the Context functions or the Globus XIO Net
18       Manager Driver will invoke your functions as network operations occur.
19       For this example (and I would imagine most real implementations), the
20       globus_net_manager_t is statically initialized, like this:
21
22       static
23       globus_net_manager_t                    globus_l_net_manager_logging = {
24           "logging",
25           globus_l_net_manager_logging_pre_listen,
26           globus_l_net_manager_logging_post_listen,
27           globus_l_net_manager_logging_end_listen,
28           globus_l_net_manager_logging_pre_accept,
29           globus_l_net_manager_logging_post_accept,
30           globus_l_net_manager_logging_pre_connect,
31           globus_l_net_manager_logging_post_connect,
32           globus_l_net_manager_logging_pre_close,
33           globus_l_net_manager_logging_post_close
34       };
35
36        For the examples provided in this library, the globus_net_manager_s is
37       registered during module activation in a globus_extension module. This
38       method makes it easy to use network managers in a shared library
39       environment. This is also a good place to initialize any state that you
40       need to retain between calls to the network manager.
41
42       To implement this, do the following:
43
44       static
45       int
46       globus_l_net_manager_logging_activate(void)
47       {
48           globus_hashtable_init(
49               &globus_l_nm_logging_logfiles,
50               7,
51               globus_hashtable_string_hash,
52               globus_hashtable_string_keyeq);
53           int rc = globus_module_activate(GLOBUS_NET_MANAGER_MODULE);
54           if (rc == 0)
55           {
56               rc = globus_net_manager_register(
57                   &globus_l_net_manager_logging,
58                   GlobusExtensionMyModule(globus_net_manager_logging));
59           }
60           return rc;
61       }
62
63       static
64       void
65       globus_l_logging_logfiles_destroy(void *datum)
66       {
67           globus_l_nm_logging_logref_t        *logref = datum;
68           if (logref)
69           {
70               free(logref->key);
71               fclose(logref->handle);
72               free(logref);
73           }
74       }
75
76       static
77       int
78       globus_l_net_manager_logging_deactivate(void)
79       {
80           globus_hashtable_destroy_all(
81                   &globus_l_nm_logging_logfiles,
82                   globus_l_logging_logfiles_destroy);
83
84           int rc = globus_net_manager_unregister(&globus_l_net_manager_logging);
85           if (rc == 0)
86           {
87               rc = globus_module_deactivate(GLOBUS_NET_MANAGER_MODULE);
88           }
89           return rc;
90       }
91
92
93       Finally, the real work of the manager is done in the functions
94       registered in the globus_net_manager_s. For brevity, I'll just include
95       the pre_listen function in this tutorial. This function is passed the
96       task-id associated with the operation, the transport ('tcp', 'udp',
97       'udt', etc) used by the network, and whatever attributes are associated
98       with the operation. If we wanted to modify things before they were
99       processed by the network, we could create a modified copy of the
100       attributes in the pre_listen function and return them via the
101       attr_array_out parameter. In this case, we simply print out the
102       information we've received from the network stack.
103
104       static
105       globus_result_t
106       globus_l_net_manager_logging_pre_listen(
107           struct globus_net_manager_s        *manager,
108           const globus_net_manager_attr_t    *manager_attr_array,
109           const char                         *task_id,
110           const char                         *transport,
111           const globus_net_manager_attr_t    *attr_array,
112           globus_net_manager_attr_t         **attr_array_out)
113       {
114           FILE *                              logfile;
115           logfile = globus_l_net_manager_logging_get_logfile(manager_attr_array);
116           globus_l_net_manager_logging_log_header(logfile, manager, task_id, transport, "pre_listen");
117           globus_l_net_manager_logging_log_attrs(logfile, attr_array);
118           globus_l_net_manager_logging_log_footer(logfile);
119           return GLOBUS_SUCCESS;
120       }
121       /* globus_l_net_manager_logging_pre_listen() */
122
123Version 1.6                     Tue Aug 17 2021 globus_net_manager_tutorial(3)
Impressum