GLOBUS_NET_MANAGER_TUTORIAL(3)
💖 NAME 💖
globus_net_manager_tutorial — the Net Manager Implementation Tutorial, bestie. It's a manual page from the Library Functions Manual, and it's basically a glow-up guide for writing your own network manager. No cap, it walks you through the whole thing. 🦋
Okay so this whole example is running on functionality from globus_common and globus_net_manager, which means the headers for those two have to be included first. Like, before anything else, periodt:
#include "globus_common.h"
#include "globus_net_manager.h"
✨ So you wanna implement a network manager ✨
To implement a network manager, you define a struct globus_net_manager_s that's holding pointers to the functions in your code that you want invoked during network events, and then you hand that whole thing over to globus_net_manager_register(). 🫶
Applications that use the Context functions or the Globus XIO Net Manager Driver will invoke your functions as network operations occur. Like, they call you. You're the main character now. 👑
For this example (and honestly I'd imagine most real implementations too), the globus_net_manager_t is statically initialized, like this:
static
globus_net_manager_t globus_l_net_manager_logging = {
"logging",
globus_l_net_manager_logging_pre_listen,
globus_l_net_manager_logging_post_listen,
globus_l_net_manager_logging_end_listen,
globus_l_net_manager_logging_pre_accept,
globus_l_net_manager_logging_post_accept,
globus_l_net_manager_logging_pre_connect,
globus_l_net_manager_logging_post_connect,
globus_l_net_manager_logging_pre_close,
globus_l_net_manager_logging_post_close
};
🎀 Registering it (the activation era) 🎀
For the examples provided in this library, the globus_net_manager_s gets registered during module activation in a globus_extension module. This method makes it easy to use network managers in a shared library environment. It's also a great place to initialize any state that you need to retain between calls to the network manager. iykyk. 💅
To implement this, do the following:
static
int
globus_l_net_manager_logging_activate(void)
{
globus_hashtable_init(
&globus_l_nm_logging_logfiles,
7,
globus_hashtable_string_hash,
globus_hashtable_string_keyeq);
int rc = globus_module_activate(GLOBUS_NET_MANAGER_MODULE);
if (rc == 0)
{
rc = globus_net_manager_register(
&globus_l_net_manager_logging,
GlobusExtensionMyModule(globus_net_manager_logging));
}
return rc;
}
static
void
globus_l_logging_logfiles_destroy(void *datum)
{
globus_l_nm_logging_logref_t *logref = datum;
if (logref)
{
free(logref->key);
fclose(logref->handle);
free(logref);
}
}
static
int
globus_l_net_manager_logging_deactivate(void)
{
globus_hashtable_destroy_all(
&globus_l_nm_logging_logfiles,
globus_l_logging_logfiles_destroy);
int rc = globus_net_manager_unregister(&globus_l_net_manager_logging);
if (rc == 0)
{
rc = globus_module_deactivate(GLOBUS_NET_MANAGER_MODULE);
}
return rc;
}
🌈 The actual work, aka where the plot happens 🌈
Finally, the real work of the manager is done in the functions registered in the globus_net_manager_s. For brevity, this tutorial only includes the pre_listen function. 🍓
This function is passed the task-id associated with the operation, the transport ("tcp", "udp", "udt", etc) used by the network, and whatever attributes are associated with the operation.
If we wanted to modify things before they were processed by the network, we could create a modified copy of the attributes in the pre_listen function and return them via the attr_array_out parameter. In this case, we simply print out the information we've received from the network stack. That's it, that's the whole vibe. 🌸
static
globus_result_t
globus_l_net_manager_logging_pre_listen(
struct globus_net_manager_s *manager,
const globus_net_manager_attr_t *manager_attr_array,
const char *task_id,
const char *transport,
const globus_net_manager_attr_t *attr_array,
globus_net_manager_attr_t **attr_array_out)
{
FILE * logfile;
logfile = globus_l_net_manager_logging_get_logfile(manager_attr_array);
globus_l_net_manager_logging_log_header(logfile, manager, task_id, transport, "pre_listen");
globus_l_net_manager_logging_log_attrs(logfile, attr_array);
globus_l_net_manager_logging_log_footer(logfile);
return GLOBUS_SUCCESS;
}
/* globus_l_net_manager_logging_pre_listen() */
Reminder bestie: everything above is a tutorial example — go build your own manager, you're literally so capable. 💜
That's the whole page, fr fr. 💖 Sending you off with all the deets: this one came from globus_net_manager, Version 1.7 — go forth and manage those networks, queen. 👑✨
📦 where this page comes from
- fedora 43: globus-net-manager-doc 1.7-13.fc43 · Apache-2.0
- fedora 44: globus-net-manager-doc 1.7-14.fc44 · Apache-2.0
- ubuntu resolute: libglobus-net-manager-doc 1.7-3build4 · Apache-2.0
- ubuntu stonking: libglobus-net-manager-doc 1.7-3build4 · Apache-2.0
- 💖 girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms