00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef __HOST_H__
00045 #define __HOST_H__
00046
00047 #include <limits.h>
00048
00049 #ifdef __cplusplus
00050 extern "C"
00051 {
00052 #endif
00053
00054
00055
00056
00057
00058
00059 #ifndef __WORDSIZE
00060
00061 #define __WORDSIZE 32
00062 #endif
00063
00064 #if defined(_LINUX) || defined(_DARWIN)
00065 typedef unsigned char uint8;
00066 typedef char int8;
00067 typedef unsigned short uint16;
00068 typedef short int16;
00069 typedef unsigned int uint32;
00070 typedef int int32;
00071 typedef int SOCKET;
00072 #endif
00073
00074 #ifdef WIN32
00075 struct iovec {
00076 void *iov_base;
00077 size_t iov_len;
00078 };
00079
00080 typedef unsigned char uint8;
00081 typedef char int8;
00082 typedef unsigned short uint16;
00083 typedef short int16;
00084 typedef unsigned int uint32;
00085 typedef int int32;
00086 #endif
00087
00088 #ifdef WIN32
00089 typedef int socklen_t;
00090 #endif
00091
00092 #if defined(WIN32)
00093 typedef unsigned long long int uint64;
00094 typedef long long int int64;
00095 #elif (__WORDSIZE == 32)
00096 __extension__
00097 typedef long long int int64;
00098 __extension__
00099 typedef unsigned long long int uint64;
00100 #elif (__WORDSIZE == 64)
00101 typedef unsigned long int uint64;
00102 typedef long int int64;
00103 #endif
00104
00105 #ifdef WIN32
00106 #define UINT8_MAX (UCHAR_MAX)
00107 #define UINT16_MAX (USHRT_MAX)
00108 #define UINT32_MAX (ULONG_MAX)
00109
00110 #if __WORDSIZE == 64
00111 #define SIZE_MAX (18446744073709551615UL)
00112 #else
00113 #ifndef SIZE_MAX
00114 #define SIZE_MAX (4294967295U)
00115 #endif
00116 #endif
00117 #endif
00118
00119 #if defined(WIN32)
00120 #define ssize_t size_t
00121 #endif
00122
00123 #ifndef TRUE
00124 #define TRUE 1
00125 #endif
00126
00127 #ifndef FALSE
00128 #define FALSE 0
00129 #endif
00130
00131 #ifndef htonll
00132 #ifdef _BIG_ENDIAN
00133 #define htonll(x) (x)
00134 #define ntohll(x) (x)
00135 #else
00136 #define htonll(x) ((((uint64)htonl(x)) << 32) + htonl(x >> 32))
00137 #define ntohll(x) ((((uint64)ntohl(x)) << 32) + ntohl(x >> 32))
00138 #endif
00139 #endif
00140
00141
00142
00143
00144
00145
00146 #ifdef WIN32
00147 #define SHUT_RD 0
00148 #define SHUT_WR 1
00149 #define SHUT_RDWR 2
00150 #define ACCEPT(a,b,c) accept(a,b,c)
00151 #define CONNECT(a,b,c) connect(a,b,c)
00152 #define CLOSE(a) closesocket(a)
00153 #define READ(a,b,c) read(a,b,c)
00154 #define RECV(a,b,c,d) recv(a, (char *)b, c, d)
00155 #define RECVFROM(a,b,c,d,e,f) recvfrom(a, (char *)b, c, d, (sockaddr *)e, (int *)f)
00156 #define RECV_FLAGS MSG_WAITALL
00157 #define SELECT(a,b,c,d,e) select((int32)a,b,c,d,e)
00158 #define SEND(a,b,c,d) send(a, (const char *)b, (int)c, d)
00159 #define SENDTO(a,b,c,d,e,f) sendto(a, (const char *)b, (int)c, d, e, f)
00160 #define SEND_FLAGS 0
00161 #define SENDFILE(a,b,c,d) sendfile(a, b, c, d)
00162 #define SET_SOCKET_ERROR(x,y) errno=y
00163 #define SOCKET_ERROR_INTERUPT EINTR
00164 #define SOCKET_ERROR_TIMEDOUT EAGAIN
00165 #define WRITE(a,b,c) write(a,b,c)
00166 #define WRITEV(a,b,c) Writev(b, c)
00167 #define GETSOCKOPT(a,b,c,d,e) getsockopt(a,b,c,(char *)d, (int *)e)
00168 #define SETSOCKOPT(a,b,c,d,e) setsockopt(a,b,c,(char *)d, (int)e)
00169 #define GETHOSTBYNAME(a) gethostbyname((const char *)a)
00170 #endif
00171
00172 #if defined(_LINUX) || defined(_DARWIN)
00173 #define ACCEPT(a,b,c) accept(a,b,c)
00174 #define CONNECT(a,b,c) connect(a,b,c)
00175 #define CLOSE(a) close(a)
00176 #define READ(a,b,c) read(a,b,c)
00177 #define RECV(a,b,c,d) recv(a, (void *)b, c, d)
00178 #define RECVFROM(a,b,c,d,e,f) recvfrom(a, (char *)b, c, d, (sockaddr *)e, f)
00179 #define RECV_FLAGS MSG_WAITALL
00180 #define SELECT(a,b,c,d,e) select(a,b,c,d,e)
00181 #define SEND(a,b,c,d) send(a, (const int8 *)b, c, d)
00182 #define SENDTO(a,b,c,d,e,f) sendto(a, (const int8 *)b, c, d, e, f)
00183 #define SEND_FLAGS 0
00184 #define SENDFILE(a,b,c,d) sendfile(a, b, c, d)
00185 #define SET_SOCKET_ERROR(x,y) errno=y
00186 #define SOCKET_ERROR_INTERUPT EINTR
00187 #define SOCKET_ERROR_TIMEDOUT EAGAIN
00188 #define WRITE(a,b,c) write(a,b,c)
00189 #define WRITEV(a,b,c) writev(a, b, c)
00190 #define GETSOCKOPT(a,b,c,d,e) getsockopt((int)a,(int)b,(int)c,(void *)d,(socklen_t *)e)
00191 #define SETSOCKOPT(a,b,c,d,e) setsockopt((int)a,(int)b,(int)c,(const void *)d,(int)e)
00192 #define GETHOSTBYNAME(a) gethostbyname((const char *)a)
00193 #endif
00194
00195
00196
00197
00198
00199
00200
00201 #define STRUCT_STAT struct stat
00202 #define LSTAT(x,y) lstat(x,y)
00203 #define FILE_HANDLE FILE *
00204 #define CLEARERR(x) clearerr(x)
00205 #define FCLOSE(x) fclose(x)
00206 #define FEOF(x) feof(x)
00207 #define FERROR(x) ferror(x)
00208 #define FFLUSH(x) fflush(x)
00209 #define FILENO(s) fileno(s)
00210 #define FOPEN(x,y) fopen(x, y)
00211
00212 #define FSTAT(s, st) fstat(FILENO(s), st)
00213
00214 #define STAT_BLK_SIZE(x) ((x).st_blksize)
00215
00216
00217
00218
00219
00220
00221
00222 #if defined(WIN32)
00223 #define GET_CLOCK_COUNT(x) QueryPerformanceCounter((LARGE_INTEGER *)x)
00224 #else
00225 #define GET_CLOCK_COUNT(x) gettimeofday(x, NULL)
00226 #endif
00227
00228 #if defined(WIN32)
00229 #define STRTOULL(x) _atoi64(x)
00230 #else
00231 #define STRTOULL(x) strtoull(x, NULL, 10)
00232 #endif
00233
00234 #if defined(WIN32)
00235 #define SNPRINTF _snprintf
00236 #define PRINTF printf
00237 #define VPRINTF vprintf
00238 #define FPRINTF fprintf
00239 #else
00240 #define SNPRINTF snprintf
00241 #define PRINTF printf
00242 #define VPRINTF vprintf
00243 #define FPRINTF fprintf
00244 #endif
00245
00246 #ifdef __cplusplus
00247 }
00248 #endif
00249
00250 #endif
00251