00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef OS_WRAPPER_HH_
00018 # define OS_WRAPPER_HH_
00019
00030
00031
00032
00033 # include <cstdarg>
00034
00035
00036
00037
00038 # ifdef WIN32
00039
00040 # define NOMINMAX
00041 # include <WinSock2.h>
00042
00043
00044 # define MAX_PATH PATH_MAX
00045 inline char* realpath(const char* pathname, char resolved_path[PATH_MAX])
00046 {
00047
00048 strcpy(resolved_path, pathname);
00049 return resolved_path;
00050 }
00051
00052 inline void sleep(int time)
00053 {
00054 Sleep(time);
00055 }
00056
00057 # define min(A, B) _cpp_min(A, B)
00058 # define max(A, B) _cpp_max(A, B)
00059
00060
00061
00062
00063 typedef int socklen_t;
00064 # define POLLIN 0x0001
00065 struct pollfd {
00066 int fd;
00067 short events;
00068 short revents;
00069 };
00070
00071 int poll(struct pollfd* pollfds, int nfds, int timeout);
00072
00073
00074 # include <process.h>
00075 typedef HANDLE pthread_t;
00076 typedef void* pthread_attr_t;
00077 typedef CRITICAL_SECTION pthread_mutex_t;
00078 typedef void* pthread_mutexattr_t;
00079
00080 inline pthread_t pthread_self()
00081 {
00082 return (pthread_t)GetCurrentThreadId();
00083 }
00084
00085 inline int pthread_create(pthread_t* thread,
00086 pthread_attr_t* attr,
00087 void* (*start_routine)(void *), void* arg)
00088 {
00089 if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine,
00090 arg, 0, NULL) == NULL)
00091 return 1;
00092 return 0;
00093 }
00094
00095 inline int pthread_join(pthread_t thread, void** value_ptr)
00096 {
00097
00098 return 0;
00099 }
00100
00101 inline int pthread_mutex_init(pthread_mutex_t* mutex,
00102 const pthread_mutexattr_t* mutexattr)
00103 {
00104 InitializeCriticalSection(mutex);
00105 return 0;
00106 }
00107
00108 inline int pthread_mutex_lock(pthread_mutex_t* mutex)
00109 {
00110 EnterCriticalSection(mutex);
00111 return 0;
00112 }
00113
00114 inline int pthread_mutex_unlock(pthread_mutex_t* mutex)
00115 {
00116 LeaveCriticalSection(mutex);
00117 return 0;
00118 }
00119
00120 inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
00121 {
00122 DeleteCriticalSection(mutex);
00123 return 0;
00124 }
00125
00126
00127 # define PACKAGE_VERSION "0.7M1"
00128
00129
00130
00131
00132 # else
00133
00134
00135 # include <unistd.h>
00136 # include <sys/socket.h>
00137 # include <sys/poll.h>
00138 # include <sys/time.h>
00139 # include <netinet/in.h>
00140 # include <netinet/tcp.h>
00141 # include <arpa/inet.h>
00142 # include <netdb.h>
00143 # define closesocket close
00144
00145 # include <pthread.h>
00146
00147 # include <config.h>
00148
00149 # endif // !WIN32
00150
00151
00152 #ifndef MSG_NOSIGNAL
00153 # define MSG_NOSIGNAL 0
00154 #endif
00155
00156 void initialize_socket();
00157
00159
00160 #endif