srs_platform.hpp
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
The MIT License (MIT)
Copyright (c) 2014 allspace
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_WIN_PORTING_H
#define SRS_WIN_PORTING_H
/**
* for linux like,
* for example, not on windows or it's cygwin.
* while the _WIN32 includes both 32-bit and 64-bit
*/
#if !defined(_WIN32) || defined(__CYGWIN__)
#define SOCKET_ETIME ETIME
#define SOCKET_ECONNRESET ECONNRESET
#define SOCKET int
#define SOCKET_ERRNO() errno
#define SOCKET_RESET(fd) fd = -1; (void)0
#define SOCKET_CLOSE(fd) \
if (fd > 0) {\
::close(fd); \
fd = -1; \
} \
(void)0
#define SOCKET_VALID(x) (x > 0)
#define SOCKET_SETUP() (void)0
#define SOCKET_CLEANUP() (void)0
#else /*on windows, but not on cygwin*/
#include <sys/stat.h>
#include <time.h>
#include <winsock2.h>
#include <stdint.h>
#ifdef _MSC_VER //for VS2010
#include <io.h>
#include <fcntl.h>
#define S_IRUSR _S_IREAD
#define S_IWUSR _S_IWRITE
#define open _open
#define close _close
#define lseek _lseek
#define write _write
#define read _read
typedef int ssize_t;
typedef int pid_t;
typedef int mode_t;
typedef int64_t useconds_t;
#endif
#define S_IRGRP 0
#define S_IWGRP 0
#define S_IXGRP 0
#define S_IRWXG 0
#define S_IROTH 0
#define S_IWOTH 0
#define S_IXOTH 0
#define S_IRWXO 0
#define PRId64 "lld"
#define SOCKET_ETIME WSAETIMEDOUT
#define SOCKET_ECONNRESET WSAECONNRESET
#define SOCKET_ERRNO() WSAGetLastError()
#define SOCKET_RESET(x) x=INVALID_SOCKET
#define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;}
#define SOCKET_VALID(x) (x!=INVALID_SOCKET)
#define SOCKET_BUFF(x) ((char*)x)
#define SOCKET_SETUP() socket_setup()
#define SOCKET_CLEANUP() socket_cleanup()
typedef uint32_t u_int32_t;
typedef uint8_t u_int8_t;
typedef int socklen_t;
struct iovec {
void* iov_base; /* Starting address */
size_t iov_len; /* Length in bytes */
};
#define snprintf _snprintf
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
const char* inet_ntop(int af, const void *src, char *dst, socklen_t size);
int gettimeofday(struct timeval* tv, struct timezone* tz);
pid_t getpid(void);
int usleep(useconds_t usec);
int socket_setup();
int socket_cleanup();
#endif
#endif //SRS_WIN_PORTING_H