globus_xio_system.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 
00021 #ifndef GLOBUS_XIO_SYSTEM_INCLUDE
00022 #define GLOBUS_XIO_SYSTEM_INCLUDE
00023 
00024 #include "globus_common.h"
00025 #include "globus_xio_types.h"
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 #define GLOBUS_XIO_SYSTEM_MODULE (&globus_i_xio_system_module)
00032 extern globus_module_descriptor_t       globus_i_xio_system_module;
00033 
00034 #ifdef WIN32
00035 
00036 #include <windows.h>
00037 #include <winsock2.h>
00038 #define GLOBUS_XIO_SYSTEM_INVALID_FILE INVALID_HANDLE_VALUE
00039 #define GLOBUS_XIO_SYSTEM_INVALID_SOCKET INVALID_SOCKET
00040 
00041 typedef struct globus_l_xio_win32_file_s * globus_xio_system_file_handle_t;
00042 typedef struct globus_l_xio_win32_socket_s * globus_xio_system_socket_handle_t;
00043 
00044 typedef SOCKET globus_xio_system_socket_t;
00045 typedef HANDLE globus_xio_system_file_t;
00046 
00047 #else
00048 
00049 #define GLOBUS_XIO_SYSTEM_INVALID_FILE  -1
00050 #define GLOBUS_XIO_SYSTEM_INVALID_SOCKET  -1
00051 
00052 /* these are handles to this interface */
00053 typedef struct globus_l_xio_system_s * globus_xio_system_file_handle_t;
00054 typedef struct globus_l_xio_system_s * globus_xio_system_socket_handle_t;
00055 
00056 /* these are the native descriptor types */
00057 typedef int globus_xio_system_socket_t;
00058 typedef int globus_xio_system_file_t;
00059 
00060 /* deprecated, do not use! */
00061 typedef int globus_xio_system_native_handle_t;
00062 #endif
00063 
00064 typedef enum
00065 {
00066     GLOBUS_XIO_SYSTEM_ERROR_SYSTEM_ERROR = 1024,
00067     GLOBUS_XIO_SYSTEM_ERROR_TOO_MANY_FDS,
00068     GLOBUS_XIO_SYSTEM_ERROR_ALREADY_REGISTERED,
00069     GLOBUS_XIO_SYSTEM_ERROR_OPERATION_CANCELED,
00070     GLOBUS_XIO_SYSTEM_ERROR_NOT_REGISTERED
00071 } globus_xio_system_error_type_t;
00072 
00073 typedef enum
00074 {
00075     GLOBUS_XIO_SYSTEM_FILE = 1,
00076     GLOBUS_XIO_SYSTEM_TCP,
00077     GLOBUS_XIO_SYSTEM_TCP_LISTENER,
00078     GLOBUS_XIO_SYSTEM_UDP
00079 } globus_xio_system_type_t;
00080 
00081 typedef void
00082 (*globus_xio_system_callback_t)(
00083     globus_result_t                     result,
00084     void *                              user_arg);
00085 
00086 typedef void
00087 (*globus_xio_system_data_callback_t)(
00088     globus_result_t                     result,
00089     globus_size_t                       nbytes,
00090     void *                              user_arg);
00091 
00100 globus_result_t
00101 globus_xio_system_file_init(
00102     globus_xio_system_file_handle_t *   handle,
00103     globus_xio_system_file_t            fd);
00104 
00105 /* this does *not* close the native handle.
00106  *  It should remove the non-blocking setting
00107  * 
00108  * do not call this with outstanding operations.  you can call it from with
00109  * a callback
00110  */
00111 void
00112 globus_xio_system_file_destroy(
00113     globus_xio_system_file_handle_t     handle);
00114 
00115 globus_result_t
00116 globus_xio_system_file_register_read(
00117     globus_xio_operation_t              op,
00118     globus_xio_system_file_handle_t     handle,
00119     globus_off_t                        offset,
00120     const globus_xio_iovec_t *          iov,
00121     int                                 iovc,
00122     globus_size_t                       waitforbytes,
00123     globus_xio_system_data_callback_t   callback,
00124     void *                              user_arg);
00125 
00126 globus_result_t
00127 globus_xio_system_file_register_write(
00128     globus_xio_operation_t              op,
00129     globus_xio_system_file_handle_t     handle,
00130     globus_off_t                        offset,
00131     const globus_xio_iovec_t *          iov,
00132     int                                 iovc,
00133     globus_size_t                       waitforbytes,
00134     globus_xio_system_data_callback_t   callback,
00135     void *                              user_arg);
00136 
00137 /* pass 0 for waitforbytes to not block */
00138 globus_result_t
00139 globus_xio_system_file_read(
00140     globus_xio_system_file_handle_t     handle,
00141     globus_off_t                        offset,
00142     const globus_xio_iovec_t *          iov,
00143     int                                 iovc,
00144     globus_size_t                       waitforbytes,
00145     globus_size_t *                     nbytes);
00146 
00147 globus_result_t
00148 globus_xio_system_file_write(
00149     globus_xio_system_file_handle_t     handle,
00150     globus_off_t                        offset,
00151     const globus_xio_iovec_t *          iov,
00152     int                                 iovc,
00153     globus_size_t                       waitforbytes,
00154     globus_size_t *                     nbytes);
00155 
00156 /* syscall abstractions */
00157 globus_off_t
00158 globus_xio_system_file_get_position(
00159     globus_xio_system_file_t            fd);
00160     
00161 globus_off_t
00162 globus_xio_system_file_get_size(
00163     globus_xio_system_file_t            fd);
00164 
00165 globus_xio_system_file_t
00166 globus_xio_system_convert_stdio(
00167     const char *                        stdio);
00168 
00169 globus_result_t
00170 globus_xio_system_file_truncate(
00171     globus_xio_system_file_t            fd,
00172     globus_off_t                        size);
00173 
00174 globus_result_t
00175 globus_xio_system_file_open(
00176     globus_xio_system_file_t *          fd,
00177     const char *                        filename,
00178     int                                 flags,
00179     unsigned long                       mode);
00180 
00181 globus_result_t
00182 globus_xio_system_file_close(
00183     globus_xio_system_file_t            fd);
00184     
00190 globus_result_t
00191 globus_xio_system_socket_init(
00192     globus_xio_system_socket_handle_t * handle,
00193     globus_xio_system_socket_t          socket,
00194     globus_xio_system_type_t            type);
00195 
00196 /* this does *not* close the native handle.
00197  *  It should remove the non-blocking setting
00198  * 
00199  * do not call this with outstanding operations.  you can call it from with
00200  * a callback
00201  */
00202 void
00203 globus_xio_system_socket_destroy(
00204     globus_xio_system_socket_handle_t   handle);
00205     
00206 globus_result_t
00207 globus_xio_system_socket_register_connect(
00208     globus_xio_operation_t              op,
00209     globus_xio_system_socket_handle_t   handle,
00210     globus_sockaddr_t *                 addr,
00211     globus_xio_system_callback_t        callback,
00212     void *                              user_arg);
00213 
00214 globus_result_t
00215 globus_xio_system_socket_register_accept(
00216     globus_xio_operation_t              op,
00217     globus_xio_system_socket_handle_t   listener_handle,
00218     globus_xio_system_socket_t *        out_handle,
00219     globus_xio_system_callback_t        callback,
00220     void *                              user_arg);
00221 
00222 /* if using from, probably want waitforbytes to be 1 */
00223 /* if waitforbytes == 0 and iov[0].iov_len == 0
00224  * behave like select()... ie notify when data ready
00225  */
00226 globus_result_t
00227 globus_xio_system_socket_register_read(
00228     globus_xio_operation_t              op,
00229     globus_xio_system_socket_handle_t   handle,
00230     const globus_xio_iovec_t *          iov,
00231     int                                 iovc,
00232     globus_size_t                       waitforbytes,
00233     int                                 flags,
00234     globus_sockaddr_t *                 out_from,
00235     globus_xio_system_data_callback_t   callback,
00236     void *                              user_arg);
00237 
00238 /* if waitforbytes == 0 and iov[0].iov_len == 0
00239  * behave like select()... ie notify when data ready
00240  */
00241 globus_result_t
00242 globus_xio_system_socket_register_write(
00243     globus_xio_operation_t              op,
00244     globus_xio_system_socket_handle_t   handle,
00245     const globus_xio_iovec_t *          iov,
00246     int                                 iovc,
00247     globus_size_t                       waitforbytes,
00248     int                                 flags,
00249     globus_sockaddr_t *                 to,
00250     globus_xio_system_data_callback_t   callback,
00251     void *                              user_arg);
00252 
00253 /* if waitforbytes == 0, do a non-blocking read */
00254 globus_result_t
00255 globus_xio_system_socket_read(
00256     globus_xio_system_socket_handle_t   handle,
00257     const globus_xio_iovec_t *          iov,
00258     int                                 iovc,
00259     globus_size_t                       waitforbytes,
00260     int                                 flags,
00261     globus_sockaddr_t *                 from,
00262     globus_size_t *                     nbytes);
00263 
00264 /* if waitforbytes == 0, do a non-blocking write */
00265 globus_result_t
00266 globus_xio_system_socket_write(
00267     globus_xio_system_socket_handle_t   handle,
00268     const globus_xio_iovec_t *          iov,
00269     int                                 iovc,
00270     globus_size_t                       waitforbytes,
00271     int                                 flags,
00272     globus_sockaddr_t *                 to,
00273     globus_size_t *                     nbytes);
00274 
00275 /* syscall abstractions */
00276 globus_result_t
00277 globus_xio_system_socket_create(
00278     globus_xio_system_socket_t *        socket,
00279     int                                 domain,
00280     int                                 type,
00281     int                                 protocol);
00282 
00283 globus_result_t
00284 globus_xio_system_socket_setsockopt(
00285     globus_xio_system_socket_t          socket,
00286     int                                 level,
00287     int                                 optname,
00288     const void *                        optval,
00289     globus_socklen_t                    optlen);
00290 
00291 globus_result_t
00292 globus_xio_system_socket_getsockopt(
00293     globus_xio_system_socket_t          socket,
00294     int                                 level,
00295     int                                 optname,
00296     void *                              optval,
00297     globus_socklen_t *                  optlen);
00298     
00299 globus_result_t
00300 globus_xio_system_socket_getsockname(
00301     globus_xio_system_socket_t          socket,
00302     struct sockaddr *                   name,
00303     globus_socklen_t *                  namelen);
00304 
00305 globus_result_t
00306 globus_xio_system_socket_getpeername(
00307     globus_xio_system_socket_t          socket,
00308     struct sockaddr *                   name,
00309     globus_socklen_t *                  namelen);
00310 
00311 globus_result_t
00312 globus_xio_system_socket_bind(
00313     globus_xio_system_socket_t          socket,
00314     struct sockaddr *                   addr,
00315     globus_socklen_t                    addrlen);
00316 
00317 globus_result_t
00318 globus_xio_system_socket_listen(
00319     globus_xio_system_socket_t          socket,
00320     int                                 backlog);
00321     
00322 globus_result_t
00323 globus_xio_system_socket_connect(
00324     globus_xio_system_socket_t          socket,
00325     const struct sockaddr *             addr,
00326     globus_socklen_t                    addrlen);
00327     
00328 globus_result_t
00329 globus_xio_system_socket_close(
00330     globus_xio_system_socket_t          socket);
00331 
00332 #ifdef WIN32
00333 
00340 #undef S_IRWXU
00341 #define S_IRWXU 0
00342 #undef S_IRUSR
00343 #define S_IRUSR 0
00344 #undef S_IWUSR
00345 #define S_IWUSR 0
00346 #undef S_IXUSR
00347 #define S_IXUSR 0
00348 #undef S_IRWXO
00349 #define S_IRWXO 0
00350 #undef S_IROTH
00351 #define S_IROTH 0
00352 #undef S_IWOTH
00353 #define S_IWOTH 0
00354 #undef S_IXOTH
00355 #define S_IXOTH 0
00356 #undef S_IRWXG
00357 #define S_IRWXG 0
00358 #undef S_IRGRP
00359 #define S_IRGRP 0
00360 #undef S_IWGRP
00361 #define S_IWGRP 0
00362 #undef S_IXGRP
00363 #define S_IXGRP 0
00364 
00365 #endif
00366 
00367 #ifdef __cplusplus
00368 }
00369 #endif
00370 
00371 #endif

Generated on 5 Nov 2016 for globus_xio by  doxygen 1.4.7