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