src/vfer_api.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2005, 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 /**
00007  *
00008  * @file   vfer_api.h
00009  * @author Ivan Beschastnikh
00010  * @brief  Defines all api functions used by applications.
00011  *
00012  * This is the file that is to be included by applications that would
00013  * like to use VFer.
00014  *
00015  * -    11/10/05        ivan            added reliability function supporting types
00016  * -    10/17/05        ivan            added vfer_debug function prototype
00017  * -    06/29/05        ivan            migration to the api specified in I2's writeup (version 6)
00018  * -    05/18/05        ivan            renamed to api.h
00019  * -    05/18/05        ivan            created
00020  */
00021 
00022 #ifndef VFER_API_H
00023 #define VFER_API_H
00024 
00025 /*
00026  * includes
00027  */
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <unistd.h>
00032 #include <sys/types.h>
00033 #include <sys/socket.h>
00034 #include <sys/un.h>
00035 #include <string.h>
00036 #include <netinet/in.h>
00037 #include <arpa/inet.h>
00038 #include <pthread.h>    /* thread support => compile with -lpthread */
00039 #include <signal.h>
00040 #include <sys/select.h> /* select call */
00041 #include <stdbool.h>
00042 
00043 #include "vfer.h"
00044 #include "vfer_packet.h"
00045 #include "vfer_control.h"
00046 
00047 /* PMTU: Determine best way to set DF bit in IP header */
00048 #ifdef IP_DONTFRAG
00049         #define SET_DF_BIT(SOCKFD, RET){\
00050                 RET = setsockopt(SOCKFD, IPPROTO_IP, IP_DONTFRAG, NULL, 0);}
00051 #else
00052         #ifdef IP_PMTUDISC_DO
00053                 #define SET_DF_BIT(SOCKFD, RET){\
00054                         int dfval = IP_PMTUDISC_DO;\
00055                         RET = setsockopt(SOCKFD, SOL_IP, IP_MTU_DISCOVER, &dfval, sizeof(int));}
00056         #else
00057                 #define SET_DF_BIT(SOCKFD, RET){ RET = -1; }
00058         #endif
00059 #endif
00060 
00061 /*
00062  * types
00063  */
00064 
00065 /* see in globals.h */
00066 
00067 
00068 //! generic transmit function argument
00069 typedef void* vfer_trnsm_arg;
00070 
00071 //! generic transmit function type
00072 /** vfer__recvfile() and vfer__sendfile can both use arbitrary
00073  * function to send and retrieve packets. Because different transmit
00074  * functions work with different sockets, the transmit functions
00075  * are casted to this generic type before they are passed to
00076  * vfer__recvfile() and vfer__sendfile().
00077  *
00078  * Currently this technique is used to prevent code duplication between
00079  * vls_sendfile() and vfer_sendfile() and vls_recvfile() and vfer_recvfile().
00080  **/
00081 typedef int (*vfer_trnsm_fn)(vfer_trnsm_arg sock, void* buf, size_t len);
00082 
00083 
00084 /*
00085  * function prototypes
00086  */
00087 
00088 /* connection setup/teardown functions */
00089 vfer_fd         vfer_socket     (int socktype);
00090 int             vfer_close      (vfer_fd vfd);
00091 int             vfer_connect    (vfer_fd vfd, const struct sockaddr *serv_addr, int addrlen);
00092 int             vfer_bind       (vfer_fd vfd, struct sockaddr *addr, int len);
00093 int             vfer_listen     (vfer_fd vfd, int backlog);
00094 vfer_fd         vfer_accept     (vfer_fd vfd, struct sockaddr *addr, socklen_t *len);
00095 
00096 
00097 /* option handling functions */
00098 int             vfer_setsockopt (vfer_fd vfd, int optname, void *optval, int optlen);
00099 int             vfer_getsockopt (vfer_fd vfd, int optname, void *optval, int *optlen);
00100 
00101 /* data transfer functions */
00102 int             vfer_send       (vfer_fd vfd, const void * buf, size_t len);
00103 int             vfer_recv       (vfer_fd vfd, void *buf, size_t len);
00104 int             vfer__sendfile  (vfer_trnsm_fn fn, vfer_trnsm_arg arg, int frame_size,
00105                                  int fd, off_t offset, size_t size);
00106 int             vfer__recvfile  (vfer_trnsm_fn fn, vfer_trnsm_arg arg, uint32_t frame_size,
00107                                  int fd, off_t offset, size_t size);
00108 int             vfer_sendfile   (vfer_fd vfd, int fd, off_t offset, size_t size);
00109 int             vfer_recvfile   (vfer_fd vfd, int fd, off_t offset, size_t size);
00110 
00111 /* asynchronous IO functions */
00112 int             vfer_selectmark (vfer_fd vfd, int mark);
00113 int             vfer_selecttest (vfer_fd vfd);
00114 int             vfer_select     (int len, vfer_fd *vfds, struct timeval *timeout);
00115 
00116 /* information reporting functions */
00117 vfer_stats      vfer_sockstats  (vfer_fd vfd);
00118 int             vfer_debug      (FILE* debug_file, FILE* error_file, const char* layers);
00119 int             vfer_sockerror  (vfer_fd vfd);
00120 char*           vfer_errortext  (int err);
00121 int             vfer_getsockname(vfer_fd vfd, struct sockaddr *name, socklen_t* len);
00122 bool            vfer_is_stream (vfer_fd fd);
00123 ssize_t         vfer_max_frame_size (vfer_fd fd);
00124 
00125 
00126 #endif /* VFER_API_H */

Generated on Tue Aug 8 16:07:18 2006 for VFER by  doxygen 1.4.7