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 #define _FILE_OFFSET_BITS 64
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <stdarg.h>
00037 #include <string.h>
00038 #include <unistd.h>
00039 #include <errno.h>
00040 #include <fcntl.h>
00041 #include <sys/types.h>
00042 #include <sys/socket.h>
00043 #include <sys/time.h>
00044 #include <sys/timeb.h>
00045 #include <sys/wait.h>
00046 #include <sys/signal.h>
00047 #include <netinet/in.h>
00048 #include <arpa/inet.h>
00049 #include <netdb.h>
00050 #include <pthread.h>
00051
00052 typedef int bool_t;
00053
00054 #define LIBTYPE
00055 #define sock_getlasterror errno
00056 #define sock_getlasterror_socktimeout (errno == EAGAIN)
00057 #define console_vprintf vprintf
00058 #define console_printf printf
00059 #define THREAD_FUNC_PREFIX void *
00060
00061 static inline int msleep(unsigned int ms)
00062 {
00063 usleep(ms * 1000);
00064 return 0;
00065 }
00066
00067 static inline uint64_t getcurrenttime(void)
00068 {
00069 struct timeval t;
00070 gettimeofday(&t, NULL);
00071 return ((uint64_t)t.tv_sec * 1000) + (t.tv_usec / 1000);
00072 }
00073
00074 static inline int setsocktimeout(int s, int level, int optname, uint64_t timeout)
00075 {
00076 struct timeval t;
00077 t.tv_sec = timeout / 1000;
00078 t.tv_usec = (timeout % 1000) * 1000;
00079 return setsockopt(s, level, optname, (char *)&t, sizeof(t));
00080 }