globus_xio  6.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
globus_i_xio_system_common.h
1 
2 #ifndef GLOBUS_I_XIO_SYSTEM_COMMON_INCLUDE
3 #define GLOBUS_I_XIO_SYSTEM_COMMON_INCLUDE
4 
5 #include "globus_i_xio_config.h"
6 #include "globus_common.h"
7 #include "globus_xio_system.h"
8 #include "globus_xio_driver.h"
9 
10 GlobusDebugDeclare(GLOBUS_XIO_SYSTEM);
11 
12 #define GlobusXIOSystemDebugPrintf(level, message) \
13  GlobusDebugPrintf(GLOBUS_XIO_SYSTEM, level, message)
14 
15 #define GlobusXIOSystemDebugFwrite(level, buffer, size, count) \
16  GlobusDebugFwrite(GLOBUS_XIO_SYSTEM, level, buffer, size, count)
17 
18 #define GlobusXIOSystemDebugEnter() \
19  GlobusXIOSystemDebugPrintf( \
20  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE, \
21  ("[%s] Entering\n", _xio_name))
22 
23 #define GlobusXIOSystemDebugExit() \
24  GlobusXIOSystemDebugPrintf( \
25  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE, \
26  ("[%s] Exiting\n", _xio_name))
27 
28 #define GlobusXIOSystemDebugExitWithError() \
29  GlobusXIOSystemDebugPrintf( \
30  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE, \
31  ("[%s] Exiting with error\n", _xio_name))
32 
33 #define GlobusXIOSystemDebugEnterFD(fd) \
34  GlobusXIOSystemDebugPrintf( \
35  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE, \
36  ("[%s] fd=%lu, Entering\n", _xio_name, (unsigned long)(fd)))
37 
38 #define GlobusXIOSystemDebugExitFD(fd) \
39  GlobusXIOSystemDebugPrintf( \
40  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE, \
41  ("[%s] fd=%lu, Exiting\n", _xio_name, (unsigned long)(fd)))
42 
43 #define GlobusXIOSystemDebugExitWithErrorFD(fd) \
44  GlobusXIOSystemDebugPrintf( \
45  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE, \
46  ("[%s] fd=%lu, Exiting with error\n", _xio_name, (unsigned long)(fd)))
47 
48 #ifdef WIN32
49 #include <winsock2.h>
50 #define GlobusXIOSystemUpdateErrno() (errno = WSAGetLastError())
51 #else
52 #define GlobusXIOSystemUpdateErrno()
53 #endif
54 
55 #define GlobusXIOSystemDebugRawBuffer(nbytes, buffer) \
56  do \
57  { \
58  GlobusXIOSystemDebugPrintf( \
59  GLOBUS_I_XIO_SYSTEM_DEBUG_RAW, \
60  ("[%s] Begin RAW data ************\n", _xio_name)); \
61  GlobusXIOSystemDebugFwrite( \
62  GLOBUS_I_XIO_SYSTEM_DEBUG_RAW, buffer, 1, nbytes); \
63  GlobusXIOSystemDebugPrintf( \
64  GLOBUS_I_XIO_SYSTEM_DEBUG_RAW, \
65  ("\n[%s] End RAW data ************\n", _xio_name)); \
66  } while(0)
67 
68 #define GlobusXIOSystemDebugRawIovec(nbytes, iovec) \
69  do \
70  { \
71  if(GlobusDebugTrue( \
72  GLOBUS_XIO_SYSTEM, GLOBUS_I_XIO_SYSTEM_DEBUG_RAW)) \
73  { \
74  globus_size_t _bytes = nbytes; \
75  int _i = 0; \
76  \
77  while(_bytes > 0) \
78  { \
79  globus_size_t _len = (iovec)[_i].iov_len; \
80  \
81  if(_bytes < _len) \
82  { \
83  _len = _bytes; \
84  } \
85  _bytes -= _len; \
86  \
87  GlobusDebugMyPrintf( \
88  GLOBUS_XIO_SYSTEM, \
89  ("[%s] Begin RAW data %i ************\n", \
90  _xio_name, _i)); \
91  GlobusDebugMyFwrite( \
92  GLOBUS_XIO_SYSTEM, \
93  (iovec)[_i].iov_base, 1, _len); \
94  GlobusDebugMyPrintf( \
95  GLOBUS_XIO_SYSTEM, \
96  ("\n[%s] End RAW data %i ************\n", \
97  _xio_name, _i)); \
98  _i++; \
99  } \
100  } \
101  } while(0)
102 
103 #define GlobusIXIOSystemAllocOperation(op_info) \
104  do \
105  { \
106  globus_i_xio_system_op_info_t * _op_info; \
107  \
108  _op_info = (globus_i_xio_system_op_info_t *) \
109  globus_memory_pop_node(&globus_i_xio_system_op_info_memory); \
110  if(_op_info) \
111  { \
112  memset(_op_info, 0, sizeof(globus_i_xio_system_op_info_t)); \
113  } \
114  (op_info) = _op_info; \
115  } while(0)
116 
117 #define GlobusIXIOSystemFreeOperation(op_info) \
118  (globus_memory_push_node(&globus_i_xio_system_op_info_memory, (op_info)))
119 
120 #define GlobusIXIOSystemAllocIovec(count, iov) \
121  do \
122  { \
123  int _count; \
124  \
125  _count = (count); \
126  \
127  if(_count < 10) \
128  { \
129  (iov) = (struct iovec *) \
130  globus_memory_pop_node(&globus_i_xio_system_iov_memory); \
131  } \
132  else \
133  { \
134  (iov) = (struct iovec *) \
135  globus_malloc(sizeof(struct iovec) * _count); \
136  } \
137  } while(0)
138 
139 #define GlobusIXIOSystemFreeIovec(count, iovec) \
140  do \
141  { \
142  int _count = (count); \
143  if(_count < 10) \
144  { \
145  globus_memory_push_node( \
146  &globus_i_xio_system_iov_memory, (iovec)); \
147  } \
148  else \
149  { \
150  globus_free((iovec)); \
151  } \
152  } while(0)
153 
154 extern globus_memory_t globus_i_xio_system_op_info_memory;
155 extern globus_memory_t globus_i_xio_system_iov_memory;
156 
157 enum globus_i_xio_system_error_levels
158 {
159  GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE = 1,
160  GLOBUS_I_XIO_SYSTEM_DEBUG_DATA = 2,
161  GLOBUS_I_XIO_SYSTEM_DEBUG_INFO = 4,
162  GLOBUS_I_XIO_SYSTEM_DEBUG_RAW = 8
163 };
164 
165 typedef enum
166 {
167  GLOBUS_I_XIO_SYSTEM_OP_ACCEPT,
168  GLOBUS_I_XIO_SYSTEM_OP_CONNECT,
169  GLOBUS_I_XIO_SYSTEM_OP_READ,
170  GLOBUS_I_XIO_SYSTEM_OP_WRITE
171 } globus_i_xio_system_op_type_t;
172 
173 typedef enum
174 {
175  /* initial state */
176  GLOBUS_I_XIO_SYSTEM_OP_NEW,
177  /* transition to this requires fdset lock */
178  GLOBUS_I_XIO_SYSTEM_OP_PENDING,
179  /* transition to this requires cancel lock */
180  GLOBUS_I_XIO_SYSTEM_OP_COMPLETE,
181  /* transition to this requires fdset and cancel lock */
182  GLOBUS_I_XIO_SYSTEM_OP_CANCELED
183 } globus_i_xio_system_op_state_t;
184 
185 
186 #if defined(_WIN32)
187 struct msghdr
188 {
189  void * msg_name;
190  int msg_namelen;
191  struct iovec * msg_iov;
192  int msg_iovlen;
193  void * msg_control;
194  int msg_controllen;
195  int msg_flags;
196 };
197 #endif
198 
199 typedef struct
200 {
201  /* common members */
202  globus_i_xio_system_op_type_t type;
203  globus_i_xio_system_op_state_t state;
204  globus_xio_operation_t op;
205 #ifndef WIN32
206  struct globus_l_xio_system_s * handle;
207 #else
208  struct globus_l_xio_win32_socket_s *handle;
209 #endif
210  globus_object_t * error;
211  void * user_arg;
212  /* used for reads/writes, 0 for others. here to simplify some things */
213  globus_size_t nbytes;
214  globus_size_t waitforbytes;
215  globus_off_t offset;
216 
217  union
218  {
219  /* non data ops -- connect, accept */
220  struct
221  {
222  globus_xio_system_callback_t callback;
223  globus_xio_system_socket_t * out_fd;
224  } non_data;
225 
226  /* data ops */
227  struct
228  {
229  globus_xio_system_data_callback_t callback;
230  struct iovec * start_iov;
231  int start_iovc;
232 
233  struct iovec * iov;
234  int iovc;
235  globus_sockaddr_t * addr;
236  int flags;
237  } data;
238  } sop;
239 } globus_i_xio_system_op_info_t;
240 
241 globus_result_t
242 globus_i_xio_system_try_read(
243  globus_xio_system_file_t fd,
244  void * buf,
245  globus_size_t buflen,
246  globus_size_t * nbytes);
247 
248 globus_result_t
249 globus_i_xio_system_try_readv(
250  globus_xio_system_file_t fd,
251  const globus_xio_iovec_t * iov,
252  int iovc,
253  globus_size_t * nbytes);
254 
255 globus_result_t
256 globus_i_xio_system_try_recv(
257  globus_xio_system_socket_t fd,
258  void * buf,
259  globus_size_t buflen,
260  int flags,
261  globus_size_t * nbytes);
262 
263 globus_result_t
264 globus_i_xio_system_try_recvfrom(
265  globus_xio_system_socket_t fd,
266  void * buf,
267  globus_size_t buflen,
268  int flags,
269  globus_sockaddr_t * from,
270  globus_size_t * nbytes);
271 
272 globus_result_t
273 globus_i_xio_system_try_recvmsg(
274  globus_xio_system_socket_t fd,
275  struct msghdr * msghdr,
276  int flags,
277  globus_size_t * nbytes);
278 
279 globus_result_t
280 globus_i_xio_system_try_write(
281  globus_xio_system_file_t fd,
282  void * buf,
283  globus_size_t buflen,
284  globus_size_t * nbytes);
285 
286 globus_result_t
287 globus_i_xio_system_try_writev(
288  globus_xio_system_file_t fd,
289  const globus_xio_iovec_t * iov,
290  int iovc,
291  globus_size_t * nbytes);
292 
293 globus_result_t
294 globus_i_xio_system_try_send(
295  globus_xio_system_socket_t fd,
296  void * buf,
297  globus_size_t buflen,
298  int flags,
299  globus_size_t * nbytes);
300 
301 globus_result_t
302 globus_i_xio_system_try_sendto(
303  globus_xio_system_socket_t fd,
304  void * buf,
305  globus_size_t buflen,
306  int flags,
307  const globus_sockaddr_t * to,
308  globus_size_t * nbytes);
309 
310 globus_result_t
311 globus_i_xio_system_try_sendmsg(
312  globus_xio_system_socket_t fd,
313  struct msghdr * msghdr,
314  int flags,
315  globus_size_t * nbytes);
316 
317 globus_result_t
318 globus_i_xio_system_file_try_read(
319  globus_xio_system_file_t handle,
320  const globus_xio_iovec_t * iov,
321  int iovc,
322  globus_size_t * nbytes);
323 
324 globus_result_t
325 globus_i_xio_system_file_try_write(
326  globus_xio_system_file_t handle,
327  const globus_xio_iovec_t * iov,
328  int iovc,
329  globus_size_t * nbytes);
330 
331 globus_result_t
332 globus_i_xio_system_socket_try_read(
333  globus_xio_system_socket_t handle,
334  const globus_xio_iovec_t * iov,
335  int iovc,
336  int flags,
337  globus_sockaddr_t * from,
338  globus_size_t * nbytes);
339 
340 globus_result_t
341 globus_i_xio_system_socket_try_write(
342  globus_xio_system_socket_t handle,
343  const globus_xio_iovec_t * iov,
344  int iovc,
345  int flags,
346  globus_sockaddr_t * to,
347  globus_size_t * nbytes);
348 
349 int
350 globus_i_xio_system_common_activate(void);
351 
352 int
353 globus_i_xio_system_common_deactivate(void);
354 
355 #endif