正在显示
4 个修改的文件
包含
55 行增加
和
24 行删除
@@ -208,10 +208,11 @@ Supported operating systems and hardware: | @@ -208,10 +208,11 @@ Supported operating systems and hardware: | ||
208 | * 2013-10-17, Created.<br/> | 208 | * 2013-10-17, Created.<br/> |
209 | 209 | ||
210 | ## History | 210 | ## History |
211 | +* v2.0, 2014-11-13, hotfix [#200](https://github.com/winlinvip/simple-rtmp-server/issues/200), deadloop when read/write 0 and ETIME. 1.0.6. | ||
211 | * v1.0, 2014-11-06, use number for macro VERSION_MAJOR, VERSION_MINOR and VERSION_REVISION. 1.0.5. | 212 | * v1.0, 2014-11-06, use number for macro VERSION_MAJOR, VERSION_MINOR and VERSION_REVISION. 1.0.5. |
212 | -* v1.0, 2014-10-24, fix [#186](https://github.com/winlinvip/simple-rtmp-server/issues/186), hotfix for bug #186, drop connect args when not object. 1.0.3. | 213 | +* v1.0, 2014-10-24, hotfix [#186](https://github.com/winlinvip/simple-rtmp-server/issues/186), drop connect args when not object. 1.0.3. |
213 | * v1.0, 2014-10-24, rename wiki/xxx to wiki/v1_CN_xxx. 1.0.2. | 214 | * v1.0, 2014-10-24, rename wiki/xxx to wiki/v1_CN_xxx. 1.0.2. |
214 | -* v1.0, 2014-10-19, fix [#183](https://github.com/winlinvip/simple-rtmp-server/issues/183), hotfix for bug #183, donot support AnnexB when decoding RTMP body for HLS. 1.0.1. | 215 | +* v1.0, 2014-10-19, hotfix [#183](https://github.com/winlinvip/simple-rtmp-server/issues/183), donot support AnnexB when decoding RTMP body for HLS. 1.0.1. |
215 | * <strong>v1.0, 2014-10-09, [1.0 beta(1.0.0)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.beta) released. 59316 lines.</strong> | 216 | * <strong>v1.0, 2014-10-09, [1.0 beta(1.0.0)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.beta) released. 59316 lines.</strong> |
216 | * v1.0, 2014-10-08, fix [#151](https://github.com/winlinvip/simple-rtmp-server/issues/151), always reap ts whatever audio or video packet. 0.9.223. | 217 | * v1.0, 2014-10-08, fix [#151](https://github.com/winlinvip/simple-rtmp-server/issues/151), always reap ts whatever audio or video packet. 0.9.223. |
217 | * v1.0, 2014-10-08, fix [#162](https://github.com/winlinvip/simple-rtmp-server/issues/162), failed if no epoll. 0.9.222. | 218 | * v1.0, 2014-10-08, fix [#162](https://github.com/winlinvip/simple-rtmp-server/issues/162), failed if no epoll. 0.9.222. |
@@ -82,8 +82,10 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread) | @@ -82,8 +82,10 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread) | ||
82 | 82 | ||
83 | // On success a non-negative integer indicating the number of bytes actually read is returned | 83 | // On success a non-negative integer indicating the number of bytes actually read is returned |
84 | // (a value of 0 means the network connection is closed or end of file is reached). | 84 | // (a value of 0 means the network connection is closed or end of file is reached). |
85 | + // Otherwise, a value of -1 is returned and errno is set to indicate the error. | ||
85 | if (nb_read <= 0) { | 86 | if (nb_read <= 0) { |
86 | - if (errno == ETIME) { | 87 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
88 | + if (nb_read < 0 && errno == ETIME) { | ||
87 | return ERROR_SOCKET_TIMEOUT; | 89 | return ERROR_SOCKET_TIMEOUT; |
88 | } | 90 | } |
89 | 91 | ||
@@ -110,8 +112,10 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread) | @@ -110,8 +112,10 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread) | ||
110 | 112 | ||
111 | // On success a non-negative integer indicating the number of bytes actually read is returned | 113 | // On success a non-negative integer indicating the number of bytes actually read is returned |
112 | // (a value less than nbyte means the network connection is closed or end of file is reached) | 114 | // (a value less than nbyte means the network connection is closed or end of file is reached) |
115 | + // Otherwise, a value of -1 is returned and errno is set to indicate the error. | ||
113 | if (nb_read != (ssize_t)size) { | 116 | if (nb_read != (ssize_t)size) { |
114 | - if (errno == ETIME) { | 117 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
118 | + if (nb_read < 0 && errno == ETIME) { | ||
115 | return ERROR_SOCKET_TIMEOUT; | 119 | return ERROR_SOCKET_TIMEOUT; |
116 | } | 120 | } |
117 | 121 | ||
@@ -136,8 +140,11 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite) | @@ -136,8 +140,11 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite) | ||
136 | *nwrite = nb_write; | 140 | *nwrite = nb_write; |
137 | } | 141 | } |
138 | 142 | ||
143 | + // On success a non-negative integer equal to nbyte is returned. | ||
144 | + // Otherwise, a value of -1 is returned and errno is set to indicate the error. | ||
139 | if (nb_write <= 0) { | 145 | if (nb_write <= 0) { |
140 | - if (errno == ETIME) { | 146 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
147 | + if (nb_write < 0 && errno == ETIME) { | ||
141 | return ERROR_SOCKET_TIMEOUT; | 148 | return ERROR_SOCKET_TIMEOUT; |
142 | } | 149 | } |
143 | 150 | ||
@@ -158,8 +165,11 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | @@ -158,8 +165,11 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | ||
158 | *nwrite = nb_write; | 165 | *nwrite = nb_write; |
159 | } | 166 | } |
160 | 167 | ||
168 | + // On success a non-negative integer equal to nbyte is returned. | ||
169 | + // Otherwise, a value of -1 is returned and errno is set to indicate the error. | ||
161 | if (nb_write <= 0) { | 170 | if (nb_write <= 0) { |
162 | - if (errno == ETIME) { | 171 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 |
172 | + if (nb_write < 0 && errno == ETIME) { | ||
163 | return ERROR_SOCKET_TIMEOUT; | 173 | return ERROR_SOCKET_TIMEOUT; |
164 | } | 174 | } |
165 | 175 |
@@ -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 1 | 32 | #define VERSION_MAJOR 1 |
33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
34 | -#define VERSION_REVISION 5 | 34 | +#define VERSION_REVISION 6 |
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" |
@@ -82,23 +82,27 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | @@ -82,23 +82,27 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) | ||
82 | { | 82 | { |
83 | int ret = ERROR_SUCCESS; | 83 | int ret = ERROR_SUCCESS; |
84 | 84 | ||
85 | - *nread = ::recv(fd, buf, size, 0); | 85 | + ssize_t nb_read = ::recv(fd, buf, size, 0); |
86 | + | ||
87 | + if (nread) { | ||
88 | + *nread = nb_read; | ||
89 | + } | ||
86 | 90 | ||
87 | // On success a non-negative integer indicating the number of bytes actually read is returned | 91 | // On success a non-negative integer indicating the number of bytes actually read is returned |
88 | // (a value of 0 means the network connection is closed or end of file is reached). | 92 | // (a value of 0 means the network connection is closed or end of file is reached). |
89 | - if (*nread <= 0) { | ||
90 | - if (errno == ETIME) { | 93 | + if (nb_read <= 0) { |
94 | + if (nb_read < 0 && errno == ETIME) { | ||
91 | return ERROR_SOCKET_TIMEOUT; | 95 | return ERROR_SOCKET_TIMEOUT; |
92 | } | 96 | } |
93 | 97 | ||
94 | - if (*nread == 0) { | 98 | + if (nb_read == 0) { |
95 | errno = ECONNRESET; | 99 | errno = ECONNRESET; |
96 | } | 100 | } |
97 | 101 | ||
98 | return ERROR_SOCKET_READ; | 102 | return ERROR_SOCKET_READ; |
99 | } | 103 | } |
100 | 104 | ||
101 | - recv_bytes += *nread; | 105 | + recv_bytes += nb_read; |
102 | 106 | ||
103 | return ret; | 107 | return ret; |
104 | } | 108 | } |
@@ -139,17 +143,25 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | @@ -139,17 +143,25 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) | ||
139 | { | 143 | { |
140 | int ret = ERROR_SUCCESS; | 144 | int ret = ERROR_SUCCESS; |
141 | 145 | ||
142 | - *nwrite = ::writev(fd, iov, iov_size); | 146 | + ssize_t nb_write = ::writev(fd, iov, iov_size); |
147 | + | ||
148 | + if (nwrite) { | ||
149 | + *nwrite = nb_write; | ||
150 | + } | ||
143 | 151 | ||
144 | - if (*nwrite <= 0) { | ||
145 | - if (errno == ETIME) { | 152 | + // On success, the readv() function returns the number of bytes read; |
153 | + // the writev() function returns the number of bytes written. On error, -1 is | ||
154 | + // returned, and errno is set appropriately. | ||
155 | + if (nb_write <= 0) { | ||
156 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 | ||
157 | + if (nb_write < 0 && errno == ETIME) { | ||
146 | return ERROR_SOCKET_TIMEOUT; | 158 | return ERROR_SOCKET_TIMEOUT; |
147 | } | 159 | } |
148 | 160 | ||
149 | return ERROR_SOCKET_WRITE; | 161 | return ERROR_SOCKET_WRITE; |
150 | } | 162 | } |
151 | 163 | ||
152 | - send_bytes += *nwrite; | 164 | + send_bytes += nb_write; |
153 | 165 | ||
154 | return ret; | 166 | return ret; |
155 | } | 167 | } |
@@ -165,21 +177,24 @@ int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread) | @@ -165,21 +177,24 @@ int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread) | ||
165 | int ret = ERROR_SUCCESS; | 177 | int ret = ERROR_SUCCESS; |
166 | 178 | ||
167 | size_t left = size; | 179 | size_t left = size; |
168 | - *nread = 0; | 180 | + ssize_t nb_read = 0; |
169 | 181 | ||
170 | while (left > 0) { | 182 | while (left > 0) { |
171 | - char* this_buf = (char*)buf + *nread; | 183 | + char* this_buf = (char*)buf + nb_read; |
172 | ssize_t this_nread; | 184 | ssize_t this_nread; |
173 | 185 | ||
174 | if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) { | 186 | if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) { |
175 | return ret; | 187 | return ret; |
176 | } | 188 | } |
177 | 189 | ||
178 | - *nread += this_nread; | 190 | + nb_read += this_nread; |
179 | left -= this_nread; | 191 | left -= this_nread; |
180 | } | 192 | } |
181 | 193 | ||
182 | - recv_bytes += *nread; | 194 | + if (nread) { |
195 | + *nread = nb_read; | ||
196 | + } | ||
197 | + recv_bytes += nb_read; | ||
183 | 198 | ||
184 | return ret; | 199 | return ret; |
185 | } | 200 | } |
@@ -188,17 +203,22 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) | @@ -188,17 +203,22 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) | ||
188 | { | 203 | { |
189 | int ret = ERROR_SUCCESS; | 204 | int ret = ERROR_SUCCESS; |
190 | 205 | ||
191 | - *nwrite = ::send(fd, (void*)buf, size, 0); | 206 | + ssize_t nb_write = ::send(fd, (void*)buf, size, 0); |
207 | + | ||
208 | + if (nwrite) { | ||
209 | + *nwrite = nb_write; | ||
210 | + } | ||
192 | 211 | ||
193 | - if (*nwrite <= 0) { | ||
194 | - if (errno == ETIME) { | 212 | + if (nb_write <= 0) { |
213 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 | ||
214 | + if (nb_write < 0 && errno == ETIME) { | ||
195 | return ERROR_SOCKET_TIMEOUT; | 215 | return ERROR_SOCKET_TIMEOUT; |
196 | } | 216 | } |
197 | 217 | ||
198 | return ERROR_SOCKET_WRITE; | 218 | return ERROR_SOCKET_WRITE; |
199 | } | 219 | } |
200 | 220 | ||
201 | - send_bytes += *nwrite; | 221 | + send_bytes += nb_write; |
202 | 222 | ||
203 | return ret; | 223 | return ret; |
204 | } | 224 | } |
-
请 注册 或 登录 后发表评论