25 #if !defined(WIN32) && !defined(_WIN32_WCE)
31 #include <sys/types.h>
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
48 #if defined(_XOPEN_SOURCE_EXTENDED) || !defined(__hpux)
49 #include <arpa/inet.h>
60 typedef int ortp_socket_t;
61 typedef pthread_t ortp_thread_t;
62 typedef pthread_mutex_t ortp_mutex_t;
63 typedef pthread_cond_t ortp_cond_t;
65 #ifdef __INTEL_COMPILER
66 #pragma warning(disable : 111) // statement is unreachable
67 #pragma warning(disable : 181) // argument is incompatible with corresponding format string conversion
68 #pragma warning(disable : 188) // enumerated type mixed with another type
69 #pragma warning(disable : 593) // variable "xxx" was set but never used
70 #pragma warning(disable : 810) // conversion from "int" to "unsigned short" may lose significant bits
71 #pragma warning(disable : 869) // parameter "xxx" was never referenced
72 #pragma warning(disable : 981) // operands are evaluated in unspecified order
73 #pragma warning(disable : 1418) // external function definition with no prior declaration
74 #pragma warning(disable : 1419) // external declaration in primary source file
75 #pragma warning(disable : 1469) // "cc" clobber ignored
78 int __ortp_thread_join(ortp_thread_t thread,
void **ptr);
79 int __ortp_thread_create(pthread_t *thread, pthread_attr_t *attr,
void * (*routine)(
void*),
void *arg);
80 #define ortp_thread_create __ortp_thread_create
81 #define ortp_thread_join __ortp_thread_join
82 #define ortp_thread_exit pthread_exit
83 #define ortp_mutex_init pthread_mutex_init
84 #define ortp_mutex_lock pthread_mutex_lock
85 #define ortp_mutex_unlock pthread_mutex_unlock
86 #define ortp_mutex_destroy pthread_mutex_destroy
87 #define ortp_cond_init pthread_cond_init
88 #define ortp_cond_signal pthread_cond_signal
89 #define ortp_cond_broadcast pthread_cond_broadcast
90 #define ortp_cond_wait pthread_cond_wait
91 #define ortp_cond_destroy pthread_cond_destroy
93 #define SOCKET_OPTION_VALUE void *
94 #define SOCKET_BUFFER void *
96 #define getSocketError() strerror(errno)
97 #define getSocketErrorCode() (errno)
107 #include <winsock2.h>
108 #include <ws2tcpip.h>
112 #pragma push_macro("_WINSOCKAPI_")
117 typedef unsigned __int64 uint64_t;
118 typedef __int64 int64_t;
119 typedef unsigned short uint16_t;
120 typedef unsigned int uint32_t;
122 typedef unsigned char uint8_t;
123 typedef __int16 int16_t;
128 #define vsnprintf _vsnprintf
129 #define srandom srand
133 typedef SOCKET ortp_socket_t;
134 typedef HANDLE ortp_cond_t;
135 typedef HANDLE ortp_mutex_t;
136 typedef HANDLE ortp_thread_t;
138 #define ortp_thread_create WIN_thread_create
139 #define ortp_thread_join WIN_thread_join
140 #define ortp_thread_exit(arg)
141 #define ortp_mutex_init WIN_mutex_init
142 #define ortp_mutex_lock WIN_mutex_lock
143 #define ortp_mutex_unlock WIN_mutex_unlock
144 #define ortp_mutex_destroy WIN_mutex_destroy
145 #define ortp_cond_init WIN_cond_init
146 #define ortp_cond_signal WIN_cond_signal
147 #define ortp_cond_broadcast WIN_cond_broadcast
148 #define ortp_cond_wait WIN_cond_wait
149 #define ortp_cond_destroy WIN_cond_destroy
157 int WIN_mutex_init(ortp_mutex_t *m,
void *attr_unused);
158 int WIN_mutex_lock(ortp_mutex_t *mutex);
159 int WIN_mutex_unlock(ortp_mutex_t *mutex);
160 int WIN_mutex_destroy(ortp_mutex_t *mutex);
161 int WIN_thread_create(ortp_thread_t *t,
void *attr_unused,
void *(*func)(
void*),
void *arg);
162 int WIN_thread_join(ortp_thread_t thread,
void **unused);
163 int WIN_cond_init(ortp_cond_t *cond,
void *attr_unused);
164 int WIN_cond_wait(ortp_cond_t * cond, ortp_mutex_t * mutex);
165 int WIN_cond_signal(ortp_cond_t * cond);
166 int WIN_cond_broadcast(ortp_cond_t * cond);
167 int WIN_cond_destroy(ortp_cond_t * cond);
173 #define SOCKET_OPTION_VALUE char *
174 #define inline __inline
176 const char *getWinSocketError(
int error);
177 #define getSocketErrorCode() WSAGetLastError()
178 #define getSocketError() getWinSocketError(WSAGetLastError())
180 #define snprintf _snprintf
181 #define strcasecmp _stricmp
190 int gettimeofday (
struct timeval *tv,
void* tz);
191 #ifdef _WORKAROUND_MINGW32_BUGS
192 char * WSAAPI gai_strerror(
int errnum);
198 typedef unsigned char bool_t;
208 void* ortp_malloc(
size_t sz);
209 void ortp_free(
void *ptr);
210 void* ortp_realloc(
void *ptr,
size_t sz);
211 void* ortp_malloc0(
size_t sz);
212 char * ortp_strdup(
const char *tmp);
216 void *(*malloc_fun)(
size_t sz);
217 void *(*realloc_fun)(
void *ptr,
size_t sz);
218 void (*free_fun)(
void *ptr);
223 #define ortp_new(type,count) ortp_malloc(sizeof(type)*(count))
224 #define ortp_new0(type,count) ortp_malloc0(sizeof(type)*(count))
226 int close_socket(ortp_socket_t sock);
227 int set_non_blocking_socket(ortp_socket_t sock);
229 char *ortp_strndup(
const char *str,
int n);
230 char *ortp_strdup_printf(
const char *fmt,...);
231 char *ortp_strdup_vprintf(
const char *fmt, va_list ap);
235 typedef HANDLE ortp_pipe_t;
236 #define ORTP_PIPE_INVALID INVALID_HANDLE_VALUE
238 typedef int ortp_pipe_t;
239 #define ORTP_PIPE_INVALID (-1)
242 ortp_pipe_t ortp_server_pipe_create(
const char *name);
248 ortp_pipe_t ortp_server_pipe_accept_client(ortp_pipe_t server);
249 int ortp_server_pipe_close(ortp_pipe_t spipe);
250 int ortp_server_pipe_close_client(ortp_pipe_t client);
252 ortp_pipe_t ortp_client_pipe_connect(
const char *name);
253 int ortp_client_pipe_close(ortp_pipe_t sock);
255 int ortp_pipe_read(ortp_pipe_t p, uint8_t *buf,
int len);
256 int ortp_pipe_write(ortp_pipe_t p,
const uint8_t *buf,
int len);
264 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(ORTP_STATIC)
266 #define VAR_DECLSPEC __declspec(dllexport)
268 #define VAR_DECLSPEC __declspec(dllimport)
271 #define VAR_DECLSPEC extern