Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
thd_iochan.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef _MCW_IOCHAN_HEADER_
00008 #define _MCW_IOCHAN_HEADER_
00009
00010
00011
00012 #if defined(CYGWIN) && !defined(DONT_USE_SHM)
00013 # define DONT_USE_SHM
00014 #endif
00015
00016 #include <sys/types.h>
00017 #include <sys/wait.h>
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <strings.h>
00021 #include <stdlib.h>
00022 #include <sys/socket.h>
00023 #include <netinet/in.h>
00024 #ifndef TCP_NODELAY
00025 #include <netinet/tcp.h>
00026 #endif
00027 #include <netdb.h>
00028 #include <arpa/inet.h>
00029 #include <sys/time.h>
00030 #include <unistd.h>
00031 #include <fcntl.h>
00032 #include <errno.h>
00033 #include <sys/times.h>
00034 #include <limits.h>
00035 #include <ctype.h>
00036
00037 #ifndef DONT_USE_SHM
00038 # include <sys/ipc.h>
00039 # include <sys/shm.h>
00040 #endif
00041
00042 #ifndef MIN
00043 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
00044 #endif
00045 #ifndef MAX
00046 # define MAX(a,b) (((a)>(b)) ? (a) : (b))
00047 #endif
00048
00049 #define NEXTDMS(dm) MIN(1.1*(dm)+1.01 , 1000.0)
00050
00051 #define BCOPY memcpy
00052
00053 #define TCP_IOCHAN 1
00054 #define SHM_IOCHAN 2
00055
00056 #define SHM_BUFSIZ (2*1024*1024)
00057
00058 #define TCP_WAIT_ACCEPT 7
00059 #define TCP_WAIT_CONNECT 8
00060 #define SHM_WAIT_CREATE 9
00061 #define SHM_WAIT_ACCEPT 10
00062
00063 #define CREATOR 33
00064 #define ACCEPTOR 44
00065
00066 #define SHMIOC_READ(ic) \
00067 ( ((ic)->whoami == CREATOR && (ic)->ioc2 != NULL) ? (ic)->ioc2 : (ic) )
00068
00069 #define SHMIOC_WRITE(ic) \
00070 ( ((ic)->whoami == ACCEPTOR && (ic)->ioc2 != NULL) ? (ic)->ioc2 : (ic) )
00071
00072 #define IOC_BAD(ic) \
00073 ( ((ic)->ioc2 != NULL) ? MAX( (ic)->bad , (ic)->ioc2->bad ) : (ic)->bad )
00074
00075 #define IOC_BIDIR(ic) \
00076 ( ((ic)->type == TCP_IOCHAN) || \
00077 ((ic)->type == SHM_IOCHAN && (ic)->ioc2 != NULL) )
00078
00079 typedef struct IOCHAN {
00080 int type ;
00081 int id ;
00082 int bad ;
00083 int port ;
00084 int whoami ;
00085
00086 char name[128] ;
00087
00088
00089
00090 int bufsize ;
00091 char * buf ;
00092 int * bstart ;
00093 int * bend ;
00094 struct IOCHAN * ioc2 ;
00095
00096
00097
00098 int sendsize ;
00099 } IOCHAN ;
00100
00101
00102
00103 extern int tcp_readcheck( int , int ) ;
00104 extern int tcp_writecheck( int , int ) ;
00105 extern int tcp_connect( char * , int ) ;
00106 extern int tcp_accept( int , char ** , char ** ) ;
00107 extern int tcp_listen( int ) ;
00108 extern int tcp_alivecheck( int ) ;
00109 extern void tcp_set_cutoff( int ) ;
00110
00111 extern char *iochan_error_string(void) ;
00112 extern void iochan_enable_perror( int ) ;
00113
00114 #undef USE_TCP_RECV
00115 #ifdef USE_TCP_RECV
00116 extern int tcp_recv( int , void * , int , unsigned int ) ;
00117 #else
00118 # define tcp_recv recv
00119 #endif
00120
00121 extern key_t string_to_key( char * ) ;
00122 extern int shm_accept( char * ) ;
00123 extern int shm_create( char * , int ) ;
00124 extern int shm_size( int ) ;
00125 extern int shm_nattach( int ) ;
00126 extern char * shm_attach( int ) ;
00127 extern int shm_alivecheck( int ) ;
00128
00129 extern void iochan_sleep( int ) ;
00130 extern IOCHAN * iochan_init( char * , char * ) ;
00131 extern int iochan_goodcheck( IOCHAN * , int ) ;
00132 extern void iochan_close( IOCHAN * ) ;
00133 extern void iochan_set_cutoff( IOCHAN * ) ;
00134 extern int iochan_writecheck( IOCHAN * , int ) ;
00135 extern int iochan_readcheck( IOCHAN * , int ) ;
00136 extern int iochan_clearcheck( IOCHAN * , int ) ;
00137 extern int iochan_send( IOCHAN * , char * , int ) ;
00138 extern int iochan_recv( IOCHAN * , char * , int ) ;
00139 extern int iochan_sendall( IOCHAN * , char * , int ) ;
00140 extern int iochan_recvall( IOCHAN * , char * , int ) ;
00141 extern int iochan_ctl( IOCHAN * , int , int ) ;
00142 extern int iochan_force_clear( IOCHAN * ) ;
00143
00144 extern int iochan_recvloop( IOCHAN *, char *, int );
00145 extern pid_t iochan_fork_relay( char *, char * );
00146
00147
00148
00149 #define IOC_TCP_SENDSIZE 501
00150
00151 #define IOCHAN_CLOSE(ioc) ( iochan_close(ioc) , (ioc)=NULL )
00152
00153 #define IOCHAN_CLOSENOW(ioc) \
00154 ( iochan_set_cutoff(ioc), iochan_sleep(1), iochan_close(ioc), (ioc)=NULL )
00155
00156 extern double COX_clock_time(void) ;
00157 extern double COX_cpu_time(void) ;
00158
00159 #define CLEAR_SHM(ic,ms) \
00160 do{ if( (ic) != NULL && (ic)->type == SHM_IOCHAN ) \
00161 iochan_clearcheck( (ic) , (ms) ) ; \
00162 } while(0)
00163
00164
00165
00166
00167
00168
00169 extern IOCHAN * open_URL_hpf ( char * host, int port, char * file, int msec ) ;
00170 extern IOCHAN * open_URL_http( char * url, int msec ) ;
00171 extern int read_URL_http( char * url, int msec, char ** data ) ;
00172 extern int read_URL_ftp ( char * url, char ** data ) ;
00173 extern int read_URL ( char * url, char ** data ) ;
00174 extern void set_URL_ftp_ident( char * name , char * pwd ) ;
00175 extern void set_URL_progress( int ) ;
00176
00177 extern void set_HTTP_10( int ) ;
00178 extern void set_HTTP_user_agent( char *) ;
00179
00180 #endif