globus_i_xio_system_common.h

00001 /*
00002  * Copyright 1999-2006 University of Chicago
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef GLOBUS_I_XIO_SYSTEM_COMMON_INCLUDE
00018 #define GLOBUS_I_XIO_SYSTEM_COMMON_INCLUDE
00019 
00020 #include "globus_i_xio_config.h"
00021 #include "globus_common.h"
00022 #include "globus_xio_system.h"
00023 #include "globus_xio_driver.h"
00024 
00025 GlobusDebugDeclare(GLOBUS_XIO_SYSTEM);
00026 
00027 #define GlobusXIOSystemDebugPrintf(level, message)                          \
00028     GlobusDebugPrintf(GLOBUS_XIO_SYSTEM, level, message)
00029 
00030 #define GlobusXIOSystemDebugFwrite(level, buffer, size, count)              \
00031     GlobusDebugFwrite(GLOBUS_XIO_SYSTEM, level, buffer, size, count)
00032 
00033 #define GlobusXIOSystemDebugEnter()                                         \
00034     GlobusXIOSystemDebugPrintf(                                             \
00035         GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE,                                    \
00036         ("[%s] Entering\n", _xio_name))
00037 
00038 #define GlobusXIOSystemDebugExit()                                          \
00039     GlobusXIOSystemDebugPrintf(                                             \
00040         GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE,                                    \
00041         ("[%s] Exiting\n", _xio_name))
00042 
00043 #define GlobusXIOSystemDebugExitWithError()                                 \
00044     GlobusXIOSystemDebugPrintf(                                             \
00045         GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE,                                    \
00046         ("[%s] Exiting with error\n", _xio_name))
00047 
00048 #define GlobusXIOSystemDebugEnterFD(fd)                                     \
00049     GlobusXIOSystemDebugPrintf(                                             \
00050         GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE,                                    \
00051         ("[%s] fd=%lu, Entering\n", _xio_name, (unsigned long)(fd)))
00052 
00053 #define GlobusXIOSystemDebugExitFD(fd)                                      \
00054     GlobusXIOSystemDebugPrintf(                                             \
00055         GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE,                                    \
00056         ("[%s] fd=%lu, Exiting\n", _xio_name, (unsigned long)(fd)))
00057 
00058 #define GlobusXIOSystemDebugExitWithErrorFD(fd)                             \
00059     GlobusXIOSystemDebugPrintf(                                             \
00060         GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE,                                    \
00061         ("[%s] fd=%lu, Exiting with error\n", _xio_name, (unsigned long)(fd)))
00062 
00063 #ifdef WIN32
00064 #include <winsock2.h>
00065 #define GlobusXIOSystemUpdateErrno() (errno = WSAGetLastError())
00066 #else
00067 #define GlobusXIOSystemUpdateErrno()
00068 #endif
00069 
00070 #define GlobusXIOSystemDebugRawBuffer(nbytes, buffer)                       \
00071     do                                                                      \
00072     {                                                                       \
00073         GlobusXIOSystemDebugPrintf(                                         \
00074             GLOBUS_I_XIO_SYSTEM_DEBUG_RAW,                                  \
00075             ("[%s] Begin RAW data ************\n", _xio_name));             \
00076         GlobusXIOSystemDebugFwrite(                                         \
00077             GLOBUS_I_XIO_SYSTEM_DEBUG_RAW, buffer, 1, nbytes);              \
00078         GlobusXIOSystemDebugPrintf(                                         \
00079             GLOBUS_I_XIO_SYSTEM_DEBUG_RAW,                                  \
00080             ("\n[%s] End RAW data ************\n", _xio_name));             \
00081     } while(0)
00082 
00083 #define GlobusXIOSystemDebugRawIovec(nbytes, iovec)                         \
00084     do                                                                      \
00085     {                                                                       \
00086         if(GlobusDebugTrue(                                                 \
00087             GLOBUS_XIO_SYSTEM, GLOBUS_I_XIO_SYSTEM_DEBUG_RAW))              \
00088         {                                                                   \
00089             globus_size_t               _bytes = nbytes;                    \
00090             int                         _i = 0;                             \
00091                                                                             \
00092             while(_bytes > 0)                                               \
00093             {                                                               \
00094                 globus_size_t           _len = (iovec)[_i].iov_len;         \
00095                                                                             \
00096                 if(_bytes < _len)                                           \
00097                 {                                                           \
00098                     _len = _bytes;                                          \
00099                 }                                                           \
00100                 _bytes -= _len;                                             \
00101                                                                             \
00102                 GlobusDebugMyPrintf(                                        \
00103                     GLOBUS_XIO_SYSTEM,                                      \
00104                     ("[%s] Begin RAW data %i ************\n",               \
00105                     _xio_name, _i));                                        \
00106                 GlobusDebugMyFwrite(                                        \
00107                     GLOBUS_XIO_SYSTEM,                                      \
00108                     (iovec)[_i].iov_base, 1, _len);                         \
00109                 GlobusDebugMyPrintf(                                        \
00110                     GLOBUS_XIO_SYSTEM,                                      \
00111                     ("\n[%s] End RAW data %i ************\n",               \
00112                     _xio_name, _i));                                        \
00113                 _i++;                                                       \
00114             }                                                               \
00115         }                                                                   \
00116     } while(0)
00117 
00118 #define GlobusIXIOSystemAllocOperation(op_info)                             \
00119     do                                                                      \
00120     {                                                                       \
00121         globus_i_xio_system_op_info_t * _op_info;                           \
00122                                                                             \
00123         _op_info = (globus_i_xio_system_op_info_t *)                        \
00124             globus_memory_pop_node(&globus_i_xio_system_op_info_memory);    \
00125         if(_op_info)                                                        \
00126         {                                                                   \
00127             memset(_op_info, 0, sizeof(globus_i_xio_system_op_info_t));     \
00128         }                                                                   \
00129         (op_info) = _op_info;                                               \
00130     } while(0)
00131 
00132 #define GlobusIXIOSystemFreeOperation(op_info)                              \
00133     (globus_memory_push_node(&globus_i_xio_system_op_info_memory, (op_info)))
00134 
00135 #define GlobusIXIOSystemAllocIovec(count, iov)                              \
00136     do                                                                      \
00137     {                                                                       \
00138         int                             _count;                             \
00139                                                                             \
00140         _count = (count);                                                   \
00141                                                                             \
00142         if(_count < 10)                                                     \
00143         {                                                                   \
00144             (iov) = (struct iovec *)                                        \
00145                 globus_memory_pop_node(&globus_i_xio_system_iov_memory);    \
00146         }                                                                   \
00147         else                                                                \
00148         {                                                                   \
00149             (iov) = (struct iovec *)                                        \
00150                 globus_malloc(sizeof(struct iovec) * _count);               \
00151         }                                                                   \
00152     } while(0)
00153 
00154 #define GlobusIXIOSystemFreeIovec(count, iovec)                             \
00155     do                                                                      \
00156     {                                                                       \
00157         int                             _count = (count);                   \
00158         if(_count < 10)                                                     \
00159         {                                                                   \
00160             globus_memory_push_node(                                        \
00161                 &globus_i_xio_system_iov_memory, (iovec));                  \
00162         }                                                                   \
00163         else                                                                \
00164         {                                                                   \
00165             globus_free((iovec));                                           \
00166         }                                                                   \
00167     } while(0)
00168 
00169 extern globus_memory_t                  globus_i_xio_system_op_info_memory;
00170 extern globus_memory_t                  globus_i_xio_system_iov_memory;
00171 
00172 enum globus_i_xio_system_error_levels
00173 {
00174     GLOBUS_I_XIO_SYSTEM_DEBUG_TRACE     = 1,
00175     GLOBUS_I_XIO_SYSTEM_DEBUG_DATA      = 2,
00176     GLOBUS_I_XIO_SYSTEM_DEBUG_INFO      = 4,
00177     GLOBUS_I_XIO_SYSTEM_DEBUG_RAW       = 8
00178 };
00179 
00180 typedef enum
00181 {
00182     GLOBUS_I_XIO_SYSTEM_OP_ACCEPT,
00183     GLOBUS_I_XIO_SYSTEM_OP_CONNECT,
00184     GLOBUS_I_XIO_SYSTEM_OP_READ,
00185     GLOBUS_I_XIO_SYSTEM_OP_WRITE
00186 } globus_i_xio_system_op_type_t;
00187 
00188 typedef enum
00189 {
00190     /* initial state */
00191     GLOBUS_I_XIO_SYSTEM_OP_NEW,
00192     /* transition to this requires fdset lock */
00193     GLOBUS_I_XIO_SYSTEM_OP_PENDING,
00194     /* transition to this requires cancel lock */
00195     GLOBUS_I_XIO_SYSTEM_OP_COMPLETE,
00196     /* transition to this requires fdset and cancel lock */
00197     GLOBUS_I_XIO_SYSTEM_OP_CANCELED
00198 } globus_i_xio_system_op_state_t;
00199 
00200 
00201 #if defined(_WIN32)
00202 struct msghdr
00203 {
00204     void *                              msg_name;
00205     int                                 msg_namelen;
00206     struct iovec *                      msg_iov;
00207     int                                 msg_iovlen;
00208     void *                              msg_control;
00209     int                                 msg_controllen;
00210     int                                 msg_flags;
00211 };
00212 #endif
00213 
00214 typedef struct
00215 {
00216     /* common members */
00217     globus_i_xio_system_op_type_t       type;
00218     globus_i_xio_system_op_state_t      state;
00219     globus_xio_operation_t              op;
00220 #ifndef WIN32
00221     struct globus_l_xio_system_s *      handle;
00222 #else
00223     struct globus_l_xio_win32_socket_s *handle;
00224 #endif
00225     globus_object_t *                   error;
00226     void *                              user_arg;
00227     /* used for reads/writes, 0 for others. here to simplify some things */
00228     globus_size_t                       nbytes;
00229     globus_size_t                       waitforbytes;
00230     globus_off_t                        offset;
00231     
00232     union
00233     {
00234         /* non data ops -- connect, accept */
00235         struct
00236         {
00237             globus_xio_system_callback_t callback;
00238             globus_xio_system_socket_t * out_fd;
00239         } non_data;
00240 
00241         /* data ops */
00242         struct
00243         {
00244             globus_xio_system_data_callback_t   callback;
00245             struct iovec *              start_iov;
00246             int                         start_iovc;
00247 
00248             struct iovec *              iov;
00249             int                         iovc;
00250             globus_sockaddr_t *         addr;
00251             int                         flags;
00252         } data;
00253     } sop;
00254 } globus_i_xio_system_op_info_t;
00255 
00256 globus_result_t
00257 globus_i_xio_system_try_read(
00258     globus_xio_system_file_t            fd,
00259     void *                              buf,
00260     globus_size_t                       buflen,
00261     globus_size_t *                     nbytes);
00262 
00263 globus_result_t
00264 globus_i_xio_system_try_readv(
00265     globus_xio_system_file_t            fd,
00266     const globus_xio_iovec_t *          iov,
00267     int                                 iovc,
00268     globus_size_t *                     nbytes);
00269 
00270 globus_result_t
00271 globus_i_xio_system_try_recv(
00272     globus_xio_system_socket_t          fd,
00273     void *                              buf,
00274     globus_size_t                       buflen,
00275     int                                 flags,
00276     globus_size_t *                     nbytes);
00277 
00278 globus_result_t
00279 globus_i_xio_system_try_recvfrom(
00280     globus_xio_system_socket_t          fd,
00281     void *                              buf,
00282     globus_size_t                       buflen,
00283     int                                 flags,
00284     globus_sockaddr_t *                 from,
00285     globus_size_t *                     nbytes);
00286 
00287 globus_result_t
00288 globus_i_xio_system_try_recvmsg(
00289     globus_xio_system_socket_t          fd,
00290     struct msghdr *                     msghdr,
00291     int                                 flags,
00292     globus_size_t *                     nbytes);
00293 
00294 globus_result_t
00295 globus_i_xio_system_try_write(
00296     globus_xio_system_file_t            fd,
00297     void *                              buf,
00298     globus_size_t                       buflen,
00299     globus_size_t *                     nbytes);
00300 
00301 globus_result_t
00302 globus_i_xio_system_try_writev(
00303     globus_xio_system_file_t            fd,
00304     const globus_xio_iovec_t *          iov,
00305     int                                 iovc,
00306     globus_size_t *                     nbytes);
00307 
00308 globus_result_t
00309 globus_i_xio_system_try_send(
00310     globus_xio_system_socket_t          fd,
00311     void *                              buf,
00312     globus_size_t                       buflen,
00313     int                                 flags,
00314     globus_size_t *                     nbytes);
00315 
00316 globus_result_t
00317 globus_i_xio_system_try_sendto(
00318     globus_xio_system_socket_t          fd,
00319     void *                              buf,
00320     globus_size_t                       buflen,
00321     int                                 flags,
00322     const globus_sockaddr_t *           to,
00323     globus_size_t *                     nbytes);
00324 
00325 globus_result_t
00326 globus_i_xio_system_try_sendmsg(
00327     globus_xio_system_socket_t          fd,
00328     struct msghdr *                     msghdr,
00329     int                                 flags,
00330     globus_size_t *                     nbytes);
00331 
00332 globus_result_t
00333 globus_i_xio_system_file_try_read(
00334     globus_xio_system_file_t            handle,
00335     const globus_xio_iovec_t *          iov,
00336     int                                 iovc,
00337     globus_size_t *                     nbytes);
00338     
00339 globus_result_t
00340 globus_i_xio_system_file_try_write(
00341     globus_xio_system_file_t            handle,
00342     const globus_xio_iovec_t *          iov,
00343     int                                 iovc,
00344     globus_size_t *                     nbytes);
00345     
00346 globus_result_t
00347 globus_i_xio_system_socket_try_read(
00348     globus_xio_system_socket_t          handle,
00349     const globus_xio_iovec_t *          iov,
00350     int                                 iovc,
00351     int                                 flags,
00352     globus_sockaddr_t *                 from,
00353     globus_size_t *                     nbytes);
00354     
00355 globus_result_t
00356 globus_i_xio_system_socket_try_write(
00357     globus_xio_system_socket_t          handle,
00358     const globus_xio_iovec_t *          iov,
00359     int                                 iovc,
00360     int                                 flags,
00361     globus_sockaddr_t *                 to,
00362     globus_size_t *                     nbytes);
00363 
00364 int
00365 globus_i_xio_system_common_activate(void);
00366 
00367 int
00368 globus_i_xio_system_common_deactivate(void);
00369 
00370 #endif

Generated on 25 Nov 2015 for globus_xio by  doxygen 1.4.7