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> 58 typedef int ortp_socket_t;
59 typedef pthread_t ortp_thread_t;
60 typedef pthread_mutex_t ortp_mutex_t;
61 typedef pthread_cond_t ortp_cond_t;
63 #ifdef __INTEL_COMPILER 64 #pragma warning(disable : 111) // statement is unreachable 65 #pragma warning(disable : 181) // argument is incompatible with corresponding format string conversion 66 #pragma warning(disable : 188) // enumerated type mixed with another type 67 #pragma warning(disable : 593) // variable "xxx" was set but never used 68 #pragma warning(disable : 810) // conversion from "int" to "unsigned short" may lose significant bits 69 #pragma warning(disable : 869) // parameter "xxx" was never referenced 70 #pragma warning(disable : 981) // operands are evaluated in unspecified order 71 #pragma warning(disable : 1418) // external function definition with no prior declaration 72 #pragma warning(disable : 1419) // external declaration in primary source file 73 #pragma warning(disable : 1469) // "cc" clobber ignored 77 #define ORTP_INLINE inline 84 int __ortp_thread_join(ortp_thread_t thread,
void **ptr);
85 int __ortp_thread_create(ortp_thread_t *thread, pthread_attr_t *attr,
void * (*routine)(
void*),
void *arg);
86 unsigned long __ortp_thread_self(
void);
92 #define ortp_thread_create __ortp_thread_create 93 #define ortp_thread_join __ortp_thread_join 94 #define ortp_thread_self __ortp_thread_self 95 #define ortp_thread_exit pthread_exit 96 #define ortp_mutex_init pthread_mutex_init 97 #define ortp_mutex_lock pthread_mutex_lock 98 #define ortp_mutex_unlock pthread_mutex_unlock 99 #define ortp_mutex_destroy pthread_mutex_destroy 100 #define ortp_cond_init pthread_cond_init 101 #define ortp_cond_signal pthread_cond_signal 102 #define ortp_cond_broadcast pthread_cond_broadcast 103 #define ortp_cond_wait pthread_cond_wait 104 #define ortp_cond_destroy pthread_cond_destroy 106 #define SOCKET_OPTION_VALUE void * 107 #define SOCKET_BUFFER void * 109 #define getSocketError() strerror(errno) 110 #define getSocketErrorCode() (errno) 111 #define ortp_gettimeofday(tv,tz) gettimeofday(tv,tz) 112 #define ortp_log10f(x) log10f(x) 124 #include <winsock2.h> 125 #include <ws2tcpip.h> 130 #if defined(__MINGW32__) || !defined(WINAPI_FAMILY_PARTITION) || !defined(WINAPI_PARTITION_DESKTOP) 131 #define ORTP_WINDOWS_DESKTOP 1 132 #elif defined(WINAPI_FAMILY_PARTITION) 133 #if defined(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 134 #define ORTP_WINDOWS_DESKTOP 1 135 #elif defined(WINAPI_PARTITION_PHONE_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) 136 #define ORTP_WINDOWS_PHONE 1 137 #elif defined(WINAPI_PARTITION_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 138 #define ORTP_WINDOWS_UNIVERSAL 1 147 #define ORTP_PUBLIC __declspec(dllexport) 149 #define ORTP_PUBLIC __declspec(dllimport) 152 #pragma push_macro("_WINSOCKAPI_") 157 #define strtok_r strtok_s 159 typedef unsigned __int64 uint64_t;
160 typedef __int64 int64_t;
161 typedef unsigned short uint16_t;
162 typedef unsigned int uint32_t;
164 typedef unsigned char uint8_t;
165 typedef __int16 int16_t;
170 ORTP_PUBLIC
char* strtok_r(
char *str,
const char *delim,
char **nextp);
173 #define vsnprintf _vsnprintf 175 typedef SOCKET ortp_socket_t;
176 #ifdef ORTP_WINDOWS_DESKTOP 177 typedef HANDLE ortp_cond_t;
178 typedef HANDLE ortp_mutex_t;
180 typedef CONDITION_VARIABLE ortp_cond_t;
181 typedef SRWLOCK ortp_mutex_t;
183 typedef HANDLE ortp_thread_t;
185 #define ortp_thread_create WIN_thread_create 186 #define ortp_thread_join WIN_thread_join 187 #define ortp_thread_self WIN_thread_self 188 #define ortp_thread_exit(arg) 189 #define ortp_mutex_init WIN_mutex_init 190 #define ortp_mutex_lock WIN_mutex_lock 191 #define ortp_mutex_unlock WIN_mutex_unlock 192 #define ortp_mutex_destroy WIN_mutex_destroy 193 #define ortp_cond_init WIN_cond_init 194 #define ortp_cond_signal WIN_cond_signal 195 #define ortp_cond_broadcast WIN_cond_broadcast 196 #define ortp_cond_wait WIN_cond_wait 197 #define ortp_cond_destroy WIN_cond_destroy 205 ORTP_PUBLIC
int WIN_mutex_init(ortp_mutex_t *m,
void *attr_unused);
206 ORTP_PUBLIC
int WIN_mutex_lock(ortp_mutex_t *mutex);
207 ORTP_PUBLIC
int WIN_mutex_unlock(ortp_mutex_t *mutex);
208 ORTP_PUBLIC
int WIN_mutex_destroy(ortp_mutex_t *mutex);
209 ORTP_PUBLIC
int WIN_thread_create(ortp_thread_t *t,
void *attr_unused,
void *(*func)(
void*),
void *arg);
210 ORTP_PUBLIC
int WIN_thread_join(ortp_thread_t thread,
void **unused);
211 ORTP_PUBLIC
unsigned long WIN_thread_self(
void);
212 ORTP_PUBLIC
int WIN_cond_init(ortp_cond_t *cond,
void *attr_unused);
213 ORTP_PUBLIC
int WIN_cond_wait(ortp_cond_t * cond, ortp_mutex_t * mutex);
214 ORTP_PUBLIC
int WIN_cond_signal(ortp_cond_t * cond);
215 ORTP_PUBLIC
int WIN_cond_broadcast(ortp_cond_t * cond);
216 ORTP_PUBLIC
int WIN_cond_destroy(ortp_cond_t * cond);
222 #define SOCKET_OPTION_VALUE char * 223 #define ORTP_INLINE __inline 225 #if defined(_WIN32_WCE) 227 #define ortp_log10f(x) (float)log10 ((double)x) 232 #define assert(exp) ((void)0) 237 #define errno GetLastError() 241 const char * ortp_strerror(DWORD value);
242 #define strerror ortp_strerror 247 #define ortp_log10f(x) log10f(x) 251 ORTP_PUBLIC
const char *getWinSocketError(
int error);
252 #define getSocketErrorCode() WSAGetLastError() 253 #define getSocketError() getWinSocketError(WSAGetLastError()) 255 #define snprintf _snprintf 256 #define strcasecmp _stricmp 257 #define strncasecmp _strnicmp 267 ORTP_PUBLIC
int ortp_gettimeofday (
struct timeval *tv,
void* tz);
268 #ifdef _WORKAROUND_MINGW32_BUGS 269 char * WSAAPI gai_strerror(
int errnum);
277 typedef unsigned char bool_t;
294 ORTP_PUBLIC
void* ortp_malloc(
size_t sz);
295 ORTP_PUBLIC
void ortp_free(
void *ptr);
296 ORTP_PUBLIC
void* ortp_realloc(
void *ptr,
size_t sz);
297 ORTP_PUBLIC
void* ortp_malloc0(
size_t sz);
298 ORTP_PUBLIC
char * ortp_strdup(
const char *tmp);
302 void *(*malloc_fun)(
size_t sz);
303 void *(*realloc_fun)(
void *ptr,
size_t sz);
304 void (*free_fun)(
void *ptr);
307 void ortp_set_memory_functions(OrtpMemoryFunctions *functions);
309 #define ortp_new(type,count) (type*)ortp_malloc(sizeof(type)*(count)) 310 #define ortp_new0(type,count) (type*)ortp_malloc0(sizeof(type)*(count)) 312 ORTP_PUBLIC
int close_socket(ortp_socket_t sock);
313 ORTP_PUBLIC
int set_non_blocking_socket(ortp_socket_t sock);
315 ORTP_PUBLIC
char *ortp_strndup(
const char *str,
int n);
316 ORTP_PUBLIC
char *ortp_strdup_printf(
const char *fmt,...);
317 ORTP_PUBLIC
char *ortp_strdup_vprintf(
const char *fmt, va_list ap);
318 ORTP_PUBLIC
char *ortp_strcat_printf(
char *dst,
const char *fmt,...);
319 ORTP_PUBLIC
char *ortp_strcat_vprintf(
char *dst,
const char *fmt, va_list ap);
321 ORTP_PUBLIC
int ortp_file_exist(
const char *pathname);
324 void _ortp_get_cur_time(
ortpTimeSpec *ret, bool_t realtime);
325 ORTP_PUBLIC uint64_t ortp_get_cur_time_ms(
void);
326 ORTP_PUBLIC
void ortp_sleep_ms(
int ms);
327 ORTP_PUBLIC
void ortp_sleep_until(
const ortpTimeSpec *ts);
328 ORTP_PUBLIC
unsigned int ortp_random(
void);
331 #if !defined(_WIN32_WCE) 333 typedef HANDLE ortp_pipe_t;
334 #define ORTP_PIPE_INVALID INVALID_HANDLE_VALUE 336 typedef int ortp_pipe_t;
337 #define ORTP_PIPE_INVALID (-1) 340 ORTP_PUBLIC ortp_pipe_t ortp_server_pipe_create(
const char *name);
346 ORTP_PUBLIC ortp_pipe_t ortp_server_pipe_accept_client(ortp_pipe_t server);
347 ORTP_PUBLIC
int ortp_server_pipe_close(ortp_pipe_t spipe);
348 ORTP_PUBLIC
int ortp_server_pipe_close_client(ortp_pipe_t client);
350 ORTP_PUBLIC ortp_pipe_t ortp_client_pipe_connect(
const char *name);
351 ORTP_PUBLIC
int ortp_client_pipe_close(ortp_pipe_t sock);
353 ORTP_PUBLIC
int ortp_pipe_read(ortp_pipe_t p, uint8_t *buf,
int len);
354 ORTP_PUBLIC
int ortp_pipe_write(ortp_pipe_t p,
const uint8_t *buf,
int len);
356 ORTP_PUBLIC
void *ortp_shm_open(
unsigned int keyid,
int size,
int create);
357 ORTP_PUBLIC
void ortp_shm_close(
void *memory);
367 #if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(ORTP_STATIC) 369 #define ORTP_VAR_PUBLIC extern __declspec(dllexport) 371 #define ORTP_VAR_PUBLIC __declspec(dllimport) 374 #define ORTP_VAR_PUBLIC extern 377 #ifndef IN6_IS_ADDR_MULTICAST 378 #define IN6_IS_ADDR_MULTICAST(i) (((uint8_t *) (i))[0] == 0xff) 384 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE==1