XIO: User's Guide
Overview
>User Quick Start
XIO Driver Quick Start
User Quick Start Guide
This Guide explains how to use the Globus XIO API for IO operations within C programs. Since Globus XIO is a simple API it is pretty straight forward. The best way to become familiar with it is by looking at an example. Not discussed here is a more complex example that demonstrates the generic use of xio in a fully asynchonous fashion is available here
This guide will examine the case where a user wishes to use Globus XIO for reading data from a file:
| 1 | As in all globus programs the first thing that must be done is to activate the globus module by running: globus_module_activate(GLOBUS_XIO_MODULE); Until activated, no |
|
| 2 | The next step is to load all the drivers needed to complete
the IO operations in which you are interested. Do this with the In order to successfully call this function you must know the name of all the drivers you wish to load. For this example we only want to load the file io driver. The prepackaged file io driver's name is: "file". This driver would be loaded with the following code: globus_result_t res; globus_xio_driver_t driver; res = globus_xio_driver_load(&driver, "file"); The driver was successfully loaded if the above function call: res == GLOBUS_SUCCESS You can now reference the driver with
variable |
|
| 3 | Now that globus_xio is activated and we have a driver load we need to build a driver stack. In our example the stack is very
simple as it consists of only one driver, the The stack is established with the following code (building off of the above code snips): globus_xio_stack_t stack; globus_xio_stack_init(&stack); globus_xio_stack_push_driver(stack, driver); |
|
Opening
Handle using Active Open |
||
| 4 | Now that the stack is created we can open a handle to the file. There are two ways that a handle can be opened.
|
|
a |
Before opening a handle it must be intialized. Initializing client side handles The following illustrates initialization for client side handles: globus_xio_handle_t handle; res = globus_xio_handle_create(&handle, stack); Initializing server side handles Server side handles are a bit more complicated. First we must introduce
the data structure globus_xio_server_t server; globus_xio_handle_t handle; globus_result_t res; res = globus_xio_server_create(&server_handle, NULL, stack); res = globus_xio_server_accept(&handle, server); |
|
b |
Once the handle is initialized, it should be open in order to perform read and write operations upon it. If the handle is a client, then a "contact string" is required. This string represents the target that the user wishes to open: globus_xio_attr_t attr; char * contact_string = "file:/etc/groups"; globus_xio_attr_init(&attr); globus_xio_open(xio_handle, contact_string, attr); globus_xio_attr_destroy(attr); Note: |
|
| 5 | Now that you have an open handle to a file, you can
|
|
| 6 | Once you are finished performing IO operations
on the handle, call globus_xio_close(handle). |
|
This may seem like quite a bit of effort for simple reading a file, and it is. However the advantages become clear when exploring the swapping of other drivers. In the above example it would be trivial to change the IO operations from file IO to TCP, or HTTP, or FTP. All the the user would need to do is change two things:
This can easily be done at runtime as the program globus_xio_example.c demonstrates. So the little program globus_xio_example.c has
the ability to be any reading client, or server, (HTTP, FTP, TCP, file,
etc) as long as the proper drivers are in the |
||