24 #if !defined(WIN32) && !defined(_WIN32_WCE)
30 #include <sys/types.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
46 #if defined(_XOPEN_SOURCE_EXTENDED) || !defined(__hpux)
47 #include <arpa/inet.h>
54 typedef int ortp_socket_t;
55 typedef pthread_t ortp_thread_t;
56 typedef pthread_mutex_t ortp_mutex_t;
57 typedef pthread_cond_t ortp_cond_t;
59 #ifdef __INTEL_COMPILER
60 #pragma warning(disable : 111)
61 #pragma warning(disable : 181)
62 #pragma warning(disable : 188)
63 #pragma warning(disable : 593)
64 #pragma warning(disable : 810)
65 #pragma warning(disable : 869)
66 #pragma warning(disable : 981)
67 #pragma warning(disable : 1418)
68 #pragma warning(disable : 1419)
69 #pragma warning(disable : 1469)
76 int __ortp_thread_join(ortp_thread_t thread,
void **ptr);
77 int __ortp_thread_create(pthread_t *thread, pthread_attr_t *attr,
void *(*routine)(
void *),
void *arg);
78 int __ortp_thread_set_name(pthread_t thread,
const char *name);
84 #define ortp_thread_create __ortp_thread_create
85 #define ortp_thread_join __ortp_thread_join
86 #define ortp_thread_exit pthread_exit
87 #define ortp_thread_set_name __ortp_thread_set_name
88 #define ortp_mutex_init pthread_mutex_init
89 #define ortp_mutex_lock pthread_mutex_lock
90 #define ortp_mutex_unlock pthread_mutex_unlock
91 #define ortp_mutex_destroy pthread_mutex_destroy
92 #define ortp_cond_init pthread_cond_init
93 #define ortp_cond_signal pthread_cond_signal
94 #define ortp_cond_broadcast pthread_cond_broadcast
95 #define ortp_cond_wait pthread_cond_wait
96 #define ortp_cond_destroy pthread_cond_destroy
98 #define SOCKET_OPTION_VALUE void *
99 #define SOCKET_BUFFER void *
101 #define getSocketErrorCode() (errno)
103 #define ortp_log10f(x) log10f(x)
111 #define ORTP_MEMORY_DEBUG
117 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_)
118 #include <winapifamily.h>
121 #include <winsock2.h>
122 #include <ws2tcpip.h>
128 #pragma push_macro("_WINSOCKAPI_")
139 #define vsnprintf _vsnprintf
140 #define srandom srand
143 #if (_MSC_VER >= 1700) && !defined(_USING_V110_SDK71_)
144 #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
145 typedef SOCKET ortp_socket_t;
146 #elif defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP)
147 typedef void *ortp_socket_t;
149 typedef SOCKET ortp_socket_t;
152 typedef SOCKET ortp_socket_t;
155 typedef HANDLE ortp_cond_t;
156 typedef HANDLE ortp_mutex_t;
157 typedef HANDLE ortp_thread_t;
159 #define ortp_thread_create WIN_thread_create
160 #define ortp_thread_join WIN_thread_join
161 #define ortp_thread_exit(arg)
162 #define ortp_thread_set_name WIN_thread_set_name
163 #define ortp_mutex_init WIN_mutex_init
164 #define ortp_mutex_lock WIN_mutex_lock
165 #define ortp_mutex_unlock WIN_mutex_unlock
166 #define ortp_mutex_destroy WIN_mutex_destroy
167 #define ortp_cond_init WIN_cond_init
168 #define ortp_cond_signal WIN_cond_signal
169 #define ortp_cond_broadcast WIN_cond_broadcast
170 #define ortp_cond_wait WIN_cond_wait
171 #define ortp_cond_destroy WIN_cond_destroy
177 int WIN_mutex_init(ortp_mutex_t *m,
void *attr_unused);
178 int WIN_mutex_lock(ortp_mutex_t *mutex);
179 int WIN_mutex_unlock(ortp_mutex_t *mutex);
180 int WIN_mutex_destroy(ortp_mutex_t *mutex);
181 int WIN_thread_create(ortp_thread_t *t,
void *attr_unused,
void *(*func)(
void *),
void *arg);
182 int WIN_thread_join(ortp_thread_t thread,
void **unused);
183 int WIN_thread_set_name(ortp_thread_t thread,
const char *name);
184 int WIN_cond_init(ortp_cond_t *cond,
void *attr_unused);
185 int WIN_cond_wait(ortp_cond_t *cond, ortp_mutex_t *mutex);
186 int WIN_cond_signal(ortp_cond_t *cond);
187 int WIN_cond_broadcast(ortp_cond_t *cond);
188 int WIN_cond_destroy(ortp_cond_t *cond);
194 #define SOCKET_OPTION_VALUE char *
196 #define _ALLOW_KEYWORD_MACROS
197 #define inline __inline
199 #if defined(_WIN32_WCE)
201 #define ortp_log10f(x) (float) log10((double) x)
206 #define assert(exp) ((void) 0)
211 #define errno GetLastError()
218 #define ortp_log10f(x) log10f(x)
222 #define getSocketErrorCode() WSAGetLastError()
224 #if (_MSC_VER < 1900)
225 #define snprintf _snprintf
227 #define strcasecmp _stricmp
239 int gettimeofday(
struct timeval *tv,
void *tz);
246 typedef unsigned char bool_t;
256 #ifdef ORTP_MEMORY_DEBUG
258 void *ortp_malloc(
size_t size,
char *file,
unsigned short line);
259 void *ortp_malloc0(
size_t size,
char *file,
unsigned short line);
260 void ortp_free(
void *ptr);
261 void *ortp_realloc(
void *ptr,
size_t size,
char *file,
unsigned short line);
264 #define ortp_malloc(S) ortp_malloc(S, __FILE__, __LINE__)
267 #define ortp_malloc0(S) ortp_malloc0(S, __FILE__, __LINE__)
270 #define ortp_realloc(P, S) ortp_realloc(P, S, __FILE__, __LINE__)
273 #define ortp_free(P) \
281 void *ortp_malloc(
size_t sz);
282 void *ortp_malloc0(
size_t sz);
283 void ortp_free(
void *ptr);
284 void *ortp_realloc(
void *ptr,
size_t sz);
287 char *ortp_strdup(
const char *tmp);
291 void *(*malloc_fun)(
size_t sz);
292 void *(*realloc_fun)(
void *ptr,
size_t sz);
293 void (*free_fun)(
void *ptr);
298 #define ortp_new(type, count) (type *) ortp_malloc(sizeof(type) * (count))
299 #define ortp_new0(type, count) (type *) ortp_malloc0(sizeof(type) * (count))
301 int set_non_blocking_socket(ortp_socket_t sock);
303 char *ortp_strndup(
const char *str,
int n);
304 char *ortp_strdup_printf(
const char *fmt, ...);
305 char *ortp_strdup_vprintf(
const char *fmt, va_list ap);
307 int ortp_file_exist(
const char *pathname);
310 #if !defined(_WIN32_WCE)
312 typedef HANDLE ortp_pipe_t;
313 #define ORTP_PIPE_INVALID INVALID_HANDLE_VALUE
315 typedef int ortp_pipe_t;
316 #define ORTP_PIPE_INVALID (-1)
319 ortp_pipe_t ortp_server_pipe_create(
const char *name);
325 ortp_pipe_t ortp_server_pipe_accept_client(ortp_pipe_t server);
326 int ortp_server_pipe_close(ortp_pipe_t spipe);
327 int ortp_server_pipe_close_client(ortp_pipe_t client);
329 ortp_pipe_t ortp_client_pipe_connect(
const char *name);
330 int ortp_client_pipe_close(ortp_pipe_t sock);
332 int ortp_pipe_read(ortp_pipe_t p, uint8_t *buf,
int len);
333 int ortp_pipe_write(ortp_pipe_t p,
const uint8_t *buf,
int len);
338 char *ortp_strerror(
int errnum,
char *buf,
size_t buflen);
339 char *ortp_gai_strerror(
int errnum,
char *buf,
size_t buflen);
341 #if defined(WIN32) || defined(_WIN32_WCE)
342 const char *ortp_inet_ntop(
int af,
const void *src,
char *dst,
size_t size);
344 #define ortp_inet_ntop inet_ntop
351 #if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(ORTP_STATIC)
354 #define VAR_DECLSPEC extern "C" __declspec(dllexport)
356 #define VAR_DECLSPEC __declspec(dllexport)
359 #define VAR_DECLSPEC __declspec(dllimport)
362 #define VAR_DECLSPEC extern