119
121
#include <stdarg.h>
120
122
#include <winsock2.h>
121
123
#include <ws2tcpip.h>
127
#define ORTP_PUBLIC __declspec(dllexport)
129
#define ORTP_PUBLIC __declspec(dllimport)
125
131
#pragma push_macro("_WINSOCKAPI_")
126
132
#ifndef _WINSOCKAPI_
127
133
#define _WINSOCKAPI_
136
#define strtok_r strtok_s
130
138
typedef unsigned __int64 uint64_t;
131
139
typedef __int64 int64_t;
132
140
typedef unsigned short uint16_t;
136
144
typedef __int16 int16_t;
138
146
#include <stdint.h> /*provided by mingw32*/
149
ORTP_PUBLIC char* strtok_r(char *str, const char *delim, char **nextp);
141
152
#define vsnprintf _vsnprintf
142
153
#define srandom srand
143
154
#define random rand
146
156
typedef SOCKET ortp_socket_t;
157
#ifdef WINAPI_FAMILY_PHONE_APP
158
typedef CONDITION_VARIABLE ortp_cond_t;
159
typedef SRWLOCK ortp_mutex_t;
147
161
typedef HANDLE ortp_cond_t;
148
162
typedef HANDLE ortp_mutex_t;
149
164
typedef HANDLE ortp_thread_t;
151
166
#define ortp_thread_create WIN_thread_create
170
int WIN_mutex_init(ortp_mutex_t *m, void *attr_unused);
171
int WIN_mutex_lock(ortp_mutex_t *mutex);
172
int WIN_mutex_unlock(ortp_mutex_t *mutex);
173
int WIN_mutex_destroy(ortp_mutex_t *mutex);
174
int WIN_thread_create(ortp_thread_t *t, void *attr_unused, void *(*func)(void*), void *arg);
175
int WIN_thread_join(ortp_thread_t thread, void **unused);
176
int WIN_cond_init(ortp_cond_t *cond, void *attr_unused);
177
int WIN_cond_wait(ortp_cond_t * cond, ortp_mutex_t * mutex);
178
int WIN_cond_signal(ortp_cond_t * cond);
179
int WIN_cond_broadcast(ortp_cond_t * cond);
180
int WIN_cond_destroy(ortp_cond_t * cond);
185
ORTP_PUBLIC int WIN_mutex_init(ortp_mutex_t *m, void *attr_unused);
186
ORTP_PUBLIC int WIN_mutex_lock(ortp_mutex_t *mutex);
187
ORTP_PUBLIC int WIN_mutex_unlock(ortp_mutex_t *mutex);
188
ORTP_PUBLIC int WIN_mutex_destroy(ortp_mutex_t *mutex);
189
ORTP_PUBLIC int WIN_thread_create(ortp_thread_t *t, void *attr_unused, void *(*func)(void*), void *arg);
190
ORTP_PUBLIC int WIN_thread_join(ortp_thread_t thread, void **unused);
191
ORTP_PUBLIC int WIN_cond_init(ortp_cond_t *cond, void *attr_unused);
192
ORTP_PUBLIC int WIN_cond_wait(ortp_cond_t * cond, ortp_mutex_t * mutex);
193
ORTP_PUBLIC int WIN_cond_signal(ortp_cond_t * cond);
194
ORTP_PUBLIC int WIN_cond_broadcast(ortp_cond_t * cond);
195
ORTP_PUBLIC int WIN_cond_destroy(ortp_cond_t * cond);
182
197
#ifdef __cplusplus
215
const char *getWinSocketError(int error);
230
ORTP_PUBLIC const char *getWinSocketError(int error);
216
231
#define getSocketErrorCode() WSAGetLastError()
217
232
#define getSocketError() getWinSocketError(WSAGetLastError())
219
234
#define snprintf _snprintf
220
235
#define strcasecmp _stricmp
224
long tv_sec; /* seconds */
225
long tv_usec; /* and microseconds */
236
#define strncasecmp _strnicmp
230
239
#ifdef __cplusplus
233
int gettimeofday (struct timeval *tv, void* tz);
242
ORTP_PUBLIC int gettimeofday (struct timeval *tv, void* tz);
234
243
#ifdef _WORKAROUND_MINGW32_BUGS
235
244
char * WSAAPI gai_strerror(int errnum);
258
typedef struct ortpTimeSpec{
249
263
#ifdef __cplusplus
253
void* ortp_malloc(size_t sz);
254
void ortp_free(void *ptr);
255
void* ortp_realloc(void *ptr, size_t sz);
256
void* ortp_malloc0(size_t sz);
257
char * ortp_strdup(const char *tmp);
267
ORTP_PUBLIC void* ortp_malloc(size_t sz);
268
ORTP_PUBLIC void ortp_free(void *ptr);
269
ORTP_PUBLIC void* ortp_realloc(void *ptr, size_t sz);
270
ORTP_PUBLIC void* ortp_malloc0(size_t sz);
271
ORTP_PUBLIC char * ortp_strdup(const char *tmp);
259
273
/*override the allocator with this method, to be called BEFORE ortp_init()*/
260
274
typedef struct _OrtpMemoryFunctions{
268
282
#define ortp_new(type,count) (type*)ortp_malloc(sizeof(type)*(count))
269
283
#define ortp_new0(type,count) (type*)ortp_malloc0(sizeof(type)*(count))
271
int close_socket(ortp_socket_t sock);
272
int set_non_blocking_socket(ortp_socket_t sock);
274
char *ortp_strndup(const char *str,int n);
275
char *ortp_strdup_printf(const char *fmt,...);
276
char *ortp_strdup_vprintf(const char *fmt, va_list ap);
278
int ortp_file_exist(const char *pathname);
285
ORTP_PUBLIC int close_socket(ortp_socket_t sock);
286
ORTP_PUBLIC int set_non_blocking_socket(ortp_socket_t sock);
288
ORTP_PUBLIC char *ortp_strndup(const char *str,int n);
289
ORTP_PUBLIC char *ortp_strdup_printf(const char *fmt,...);
290
ORTP_PUBLIC char *ortp_strdup_vprintf(const char *fmt, va_list ap);
292
ORTP_PUBLIC int ortp_file_exist(const char *pathname);
294
ORTP_PUBLIC void ortp_get_cur_time(ortpTimeSpec *ret);
280
296
/* portable named pipes and shared memory*/
281
297
#if !defined(_WIN32_WCE)
287
303
#define ORTP_PIPE_INVALID (-1)
290
ortp_pipe_t ortp_server_pipe_create(const char *name);
306
ORTP_PUBLIC ortp_pipe_t ortp_server_pipe_create(const char *name);
292
308
* warning: on win32 ortp_server_pipe_accept_client() might return INVALID_HANDLE_VALUE without
293
309
* any specific error, this happens when ortp_server_pipe_close() is called on another pipe.
294
310
* This pipe api is not thread-safe.
296
ortp_pipe_t ortp_server_pipe_accept_client(ortp_pipe_t server);
297
int ortp_server_pipe_close(ortp_pipe_t spipe);
298
int ortp_server_pipe_close_client(ortp_pipe_t client);
300
ortp_pipe_t ortp_client_pipe_connect(const char *name);
301
int ortp_client_pipe_close(ortp_pipe_t sock);
303
int ortp_pipe_read(ortp_pipe_t p, uint8_t *buf, int len);
304
int ortp_pipe_write(ortp_pipe_t p, const uint8_t *buf, int len);
306
void *ortp_shm_open(unsigned int keyid, int size, int create);
307
void ortp_shm_close(void *memory);
312
ORTP_PUBLIC ortp_pipe_t ortp_server_pipe_accept_client(ortp_pipe_t server);
313
ORTP_PUBLIC int ortp_server_pipe_close(ortp_pipe_t spipe);
314
ORTP_PUBLIC int ortp_server_pipe_close_client(ortp_pipe_t client);
316
ORTP_PUBLIC ortp_pipe_t ortp_client_pipe_connect(const char *name);
317
ORTP_PUBLIC int ortp_client_pipe_close(ortp_pipe_t sock);
319
ORTP_PUBLIC int ortp_pipe_read(ortp_pipe_t p, uint8_t *buf, int len);
320
ORTP_PUBLIC int ortp_pipe_write(ortp_pipe_t p, const uint8_t *buf, int len);
322
ORTP_PUBLIC void *ortp_shm_open(unsigned int keyid, int size, int create);
323
ORTP_PUBLIC void ortp_shm_close(void *memory);
317
333
#if (defined(WIN32) || defined(_WIN32_WCE)) && !defined(ORTP_STATIC)
318
334
#ifdef ORTP_EXPORTS
319
#define VAR_DECLSPEC __declspec(dllexport)
335
#define ORTP_VAR_PUBLIC extern __declspec(dllexport)
321
#define VAR_DECLSPEC __declspec(dllimport)
337
#define ORTP_VAR_PUBLIC __declspec(dllimport)
324
#define VAR_DECLSPEC extern
340
#define ORTP_VAR_PUBLIC extern