正在显示
6 个修改的文件
包含
70 行增加
和
55 行删除
@@ -112,7 +112,7 @@ int main(int argc, char** argv) | @@ -112,7 +112,7 @@ int main(int argc, char** argv) | ||
112 | printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); | 112 | printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); |
113 | 113 | ||
114 | rtmp = srs_rtmp_create("rtmp://ossrs.net/live/livestream"); | 114 | rtmp = srs_rtmp_create("rtmp://ossrs.net/live/livestream"); |
115 | - srs_lib_trace("create rtmp success"); | 115 | + srs_human_trace("create rtmp success"); |
116 | srs_rtmp_destroy(rtmp); | 116 | srs_rtmp_destroy(rtmp); |
117 | 117 | ||
118 | return 0; | 118 | return 0; |
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | // current release version | 31 | // current release version |
32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
34 | -#define VERSION_REVISION 35 | 34 | +#define VERSION_REVISION 36 |
35 | // server info. | 35 | // server info. |
36 | #define RTMP_SIG_SRS_KEY "SRS" | 36 | #define RTMP_SIG_SRS_KEY "SRS" |
37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" | 37 | #define RTMP_SIG_SRS_ROLE "origin/edge server" |
@@ -45,22 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -45,22 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
45 | 45 | ||
46 | SimpleSocketStream::SimpleSocketStream() | 46 | SimpleSocketStream::SimpleSocketStream() |
47 | { | 47 | { |
48 | - fd = -1; | 48 | + SOCKET_RESET(fd); |
49 | send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; | 49 | send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; |
50 | recv_bytes = send_bytes = 0; | 50 | recv_bytes = send_bytes = 0; |
51 | + SOCKET_SETUP(); | ||
51 | } | 52 | } |
52 | 53 | ||
53 | SimpleSocketStream::~SimpleSocketStream() | 54 | SimpleSocketStream::~SimpleSocketStream() |
54 | { | 55 | { |
55 | - if (fd != -1) { | ||
56 | - ::close(fd); | ||
57 | - fd = -1; | ||
58 | - } | 56 | + SOCKET_CLOSE(fd); |
57 | + SOCKET_CLEANUP(); | ||
59 | } | 58 | } |
60 | 59 | ||
61 | int SimpleSocketStream::create_socket() | 60 | int SimpleSocketStream::create_socket() |
62 | { | 61 | { |
63 | - if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ | 62 | + fd = ::socket(AF_INET, SOCK_STREAM, 0); |
63 | + if (!SOCKET_VALID(fd)) { | ||
64 | return ERROR_SOCKET_CREATE; | 64 | return ERROR_SOCKET_CREATE; |
65 | } | 65 | } |
66 | 66 | ||
@@ -95,12 +95,12 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | @@ -95,12 +95,12 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | ||
95 | // On success a non-negative integer indicating the number of bytes actually read is returned | 95 | // On success a non-negative integer indicating the number of bytes actually read is returned |
96 | // (a value of 0 means the network connection is closed or end of file is reached). | 96 | // (a value of 0 means the network connection is closed or end of file is reached). |
97 | if (nb_read <= 0) { | 97 | if (nb_read <= 0) { |
98 | - if (nb_read < 0 && errno == ETIME) { | 98 | + if (nb_read < 0 && SOCKET_ERRNO() == SOCKET_ETIME) { |
99 | return ERROR_SOCKET_TIMEOUT; | 99 | return ERROR_SOCKET_TIMEOUT; |
100 | } | 100 | } |
101 | 101 | ||
102 | if (nb_read == 0) { | 102 | if (nb_read == 0) { |
103 | - errno = ECONNRESET; | 103 | + errno = SOCKET_ECONNRESET; |
104 | } | 104 | } |
105 | 105 | ||
106 | return ERROR_SOCKET_READ; | 106 | return ERROR_SOCKET_READ; |
@@ -158,7 +158,7 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | @@ -158,7 +158,7 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | ||
158 | // returned, and errno is set appropriately. | 158 | // returned, and errno is set appropriately. |
159 | if (nb_write <= 0) { | 159 | if (nb_write <= 0) { |
160 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 | 160 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
161 | - if (nb_write < 0 && errno == ETIME) { | 161 | + if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) { |
162 | return ERROR_SOCKET_TIMEOUT; | 162 | return ERROR_SOCKET_TIMEOUT; |
163 | } | 163 | } |
164 | 164 | ||
@@ -215,7 +215,7 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) | @@ -215,7 +215,7 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) | ||
215 | 215 | ||
216 | if (nb_write <= 0) { | 216 | if (nb_write <= 0) { |
217 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 | 217 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
218 | - if (nb_write < 0 && errno == ETIME) { | 218 | + if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) { |
219 | return ERROR_SOCKET_TIMEOUT; | 219 | return ERROR_SOCKET_TIMEOUT; |
220 | } | 220 | } |
221 | 221 |
@@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
32 | 32 | ||
33 | #include <srs_protocol_io.hpp> | 33 | #include <srs_protocol_io.hpp> |
34 | +#include <srs_librtmp.hpp> | ||
34 | 35 | ||
35 | /** | 36 | /** |
36 | * simple socket stream, | 37 | * simple socket stream, |
@@ -43,7 +44,7 @@ private: | @@ -43,7 +44,7 @@ private: | ||
43 | int64_t send_timeout; | 44 | int64_t send_timeout; |
44 | int64_t recv_bytes; | 45 | int64_t recv_bytes; |
45 | int64_t send_bytes; | 46 | int64_t send_bytes; |
46 | - int fd; | 47 | + SOCKET fd; |
47 | public: | 48 | public: |
48 | SimpleSocketStream(); | 49 | SimpleSocketStream(); |
49 | virtual ~SimpleSocketStream(); | 50 | virtual ~SimpleSocketStream(); |
@@ -133,47 +133,29 @@ struct Context | @@ -133,47 +133,29 @@ struct Context | ||
133 | return 0; | 133 | return 0; |
134 | } | 134 | } |
135 | 135 | ||
136 | - int open(const char *pathname, int flags) | 136 | + int socket_setup() |
137 | { | 137 | { |
138 | - return open(pathname, flags, 0); | ||
139 | - } | ||
140 | - | ||
141 | - int open(const char *pathname, int flags, mode_t mode) | ||
142 | - { | ||
143 | - FILE* file = NULL; | ||
144 | - | ||
145 | - if ((flags & O_RDONLY) == O_RDONLY) { | ||
146 | - file = fopen(pathname, "r"); | ||
147 | - } else { | ||
148 | - file = fopen(pathname, "w+"); | ||
149 | - } | ||
150 | - | ||
151 | - if (file == NULL) { | 138 | + WORD wVersionRequested; |
139 | + WSADATA wsaData; | ||
140 | + int err; | ||
141 | + | ||
142 | + /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ | ||
143 | + wVersionRequested = MAKEWORD(2, 2); | ||
144 | + | ||
145 | + err = WSAStartup(wVersionRequested, &wsaData); | ||
146 | + if (err != 0) { | ||
147 | + /* Tell the user that we could not find a usable */ | ||
148 | + /* Winsock DLL. */ | ||
149 | + //printf("WSAStartup failed with error: %d\n", err); | ||
152 | return -1; | 150 | return -1; |
153 | } | 151 | } |
154 | - | ||
155 | - return (int)file; | ||
156 | - } | ||
157 | - | ||
158 | - int close(int fd) | ||
159 | - { | ||
160 | - FILE* file = (FILE*)fd; | ||
161 | - return fclose(file); | ||
162 | - } | ||
163 | - | ||
164 | - off_t lseek(int fd, off_t offset, int whence) | ||
165 | - { | ||
166 | - return (off_t)fseek((FILE*)fd, offset, whence); | ||
167 | - } | ||
168 | - | ||
169 | - ssize_t write(int fd, const void *buf, size_t count) | ||
170 | - { | ||
171 | - return (ssize_t)fwrite(buf, count, 1, (FILE*)fd); | 152 | + return 0; |
172 | } | 153 | } |
173 | 154 | ||
174 | - ssize_t read(int fd, void *buf, size_t count) | 155 | + int socket_cleanup() |
175 | { | 156 | { |
176 | - return (ssize_t)fread(buf, count, 1, (FILE*)fd); | 157 | + WSACleanup(); |
158 | + return 0; | ||
177 | } | 159 | } |
178 | 160 | ||
179 | pid_t getpid(void) | 161 | pid_t getpid(void) |
@@ -31,7 +31,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
31 | #include <sys/types.h> | 31 | #include <sys/types.h> |
32 | 32 | ||
33 | // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 | 33 | // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 |
34 | -#ifdef _WIN32 | 34 | +#ifndef _WIN32 |
35 | + #define SOCKET_ETIME ETIME | ||
36 | + #define SOCKET_ECONNRESET ECONNRESET | ||
37 | + | ||
38 | + #define SOCKET int | ||
39 | + #define SOCKET_ERRNO() errno | ||
40 | + #define SOCKET_RESET(fd) fd = -1; (void)0 | ||
41 | + #define SOCKET_CLOSE(fd) \ | ||
42 | + if (fd > 0) {\ | ||
43 | + ::close(fd); \ | ||
44 | + fd = -1; \ | ||
45 | + } \ | ||
46 | + (void)0 | ||
47 | + #define SOCKET_VALID(x) (x > 0) | ||
48 | + #define SOCKET_SETUP() (void)0 | ||
49 | + #define SOCKET_CLEANUP() (void)0 | ||
50 | +#else | ||
35 | #define _CRT_SECURE_NO_WARNINGS | 51 | #define _CRT_SECURE_NO_WARNINGS |
36 | typedef unsigned long long u_int64_t; | 52 | typedef unsigned long long u_int64_t; |
37 | typedef long long int64_t; | 53 | typedef long long int64_t; |
@@ -50,6 +66,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -50,6 +66,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
50 | #include <windows.h> | 66 | #include <windows.h> |
51 | int gettimeofday(struct timeval* tv, struct timezone* tz); | 67 | int gettimeofday(struct timeval* tv, struct timezone* tz); |
52 | #define PRId64 "lld" | 68 | #define PRId64 "lld" |
69 | + | ||
70 | + #define SOCKET_ETIME WSAETIMEDOUT | ||
71 | + #define SOCKET_ECONNRESET WSAECONNRESET | ||
72 | + #define SOCKET_ERRNO() WSAGetLastError() | ||
73 | + #define SOCKET_RESET(x) x=INVALID_SOCKET | ||
74 | + #define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;} | ||
75 | + #define SOCKET_VALID(x) (x!=INVALID_SOCKET) | ||
76 | + #define SOCKET_BUFF(x) ((char*)x) | ||
77 | + #define SOCKET_SETUP() socket_setup() | ||
78 | + #define SOCKET_CLEANUP() socket_cleanup() | ||
79 | + | ||
53 | typedef int socklen_t; | 80 | typedef int socklen_t; |
54 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); | 81 | const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); |
55 | typedef int mode_t; | 82 | typedef int mode_t; |
@@ -58,18 +85,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -58,18 +85,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
58 | #define S_IRGRP 0 | 85 | #define S_IRGRP 0 |
59 | #define S_IWGRP 0 | 86 | #define S_IWGRP 0 |
60 | #define S_IROTH 0 | 87 | #define S_IROTH 0 |
61 | - int open(const char *pathname, int flags); | ||
62 | - int open(const char *pathname, int flags, mode_t mode); | ||
63 | - int close(int fd); | ||
64 | - off_t lseek(int fd, off_t offset, int whence); | ||
65 | - ssize_t write(int fd, const void *buf, size_t count); | ||
66 | - ssize_t read(int fd, void *buf, size_t count); | 88 | + |
89 | + #include <io.h> | ||
90 | + #include <fcntl.h> | ||
91 | + #define open _open | ||
92 | + #define close _close | ||
93 | + #define lseek _lseek | ||
94 | + #define write _write | ||
95 | + #define read _read | ||
96 | + | ||
67 | typedef int pid_t; | 97 | typedef int pid_t; |
68 | pid_t getpid(void); | 98 | pid_t getpid(void); |
69 | #define snprintf _snprintf | 99 | #define snprintf _snprintf |
70 | ssize_t writev(int fd, const struct iovec *iov, int iovcnt); | 100 | ssize_t writev(int fd, const struct iovec *iov, int iovcnt); |
71 | typedef int64_t useconds_t; | 101 | typedef int64_t useconds_t; |
72 | int usleep(useconds_t usec); | 102 | int usleep(useconds_t usec); |
103 | + int socket_setup(); | ||
104 | + int socket_cleanup(); | ||
73 | #endif | 105 | #endif |
74 | 106 | ||
75 | /** | 107 | /** |
-
请 注册 或 登录 后发表评论