winlin

Merge branch 'srs.master'

@@ -242,9 +242,10 @@ Supported operating systems and hardware: @@ -242,9 +242,10 @@ Supported operating systems and hardware:
242 * 2013-10-17, Created.<br/> 242 * 2013-10-17, Created.<br/>
243 243
244 ## History 244 ## History
245 -* v2.0, 2014-11-08, fix [#194](https://github.com/winlinvip/simple-rtmp-server/issues/194), writev multiple msgs, support 6k+ 250kbps clients. 2.0.15.  
246 -* v2.0, 2014-11-08, fix [#194](https://github.com/winlinvip/simple-rtmp-server/issues/194), optmized st for timeout recv. pulse to 500ms. 2.0.14.  
247 -* v2.0, 2014-11-08, fix [#195](https://github.com/winlinvip/simple-rtmp-server/issues/195), remove the confuse code st_usleep(0). 2.0.13. 245 +* v2.0, 2014-11-13, fix [#200](https://github.com/winlinvip/simple-rtmp-server/issues/200), deadloop when read/write 0 and ETIME. 2.0.16.
  246 +* v2.0, 2014-11-13, fix [#194](https://github.com/winlinvip/simple-rtmp-server/issues/194), writev multiple msgs, support 6k+ 250kbps clients. 2.0.15.
  247 +* v2.0, 2014-11-12, fix [#194](https://github.com/winlinvip/simple-rtmp-server/issues/194), optmized st for timeout recv. pulse to 500ms. 2.0.14.
  248 +* v2.0, 2014-11-11, fix [#195](https://github.com/winlinvip/simple-rtmp-server/issues/195), remove the confuse code st_usleep(0). 2.0.13.
248 * v2.0, 2014-11-08, fix [#191](https://github.com/winlinvip/simple-rtmp-server/issues/191), configure --export-librtmp-project and --export-librtmp-single. 2.0.11. 249 * v2.0, 2014-11-08, fix [#191](https://github.com/winlinvip/simple-rtmp-server/issues/191), configure --export-librtmp-project and --export-librtmp-single. 2.0.11.
249 * v2.0, 2014-11-08, fix [#66](https://github.com/winlinvip/simple-rtmp-server/issues/66), srs-librtmp support write h264 raw packet. 2.0.9. 250 * v2.0, 2014-11-08, fix [#66](https://github.com/winlinvip/simple-rtmp-server/issues/66), srs-librtmp support write h264 raw packet. 2.0.9.
250 * v2.0, 2014-10-25, fix [#185](https://github.com/winlinvip/simple-rtmp-server/issues/185), AMF0 support 0x0B the date type codec. 2.0.7. 251 * v2.0, 2014-10-25, fix [#185](https://github.com/winlinvip/simple-rtmp-server/issues/185), AMF0 support 0x0B the date type codec. 2.0.7.
@@ -101,7 +101,7 @@ int sleep2_test() @@ -101,7 +101,7 @@ int sleep2_test()
101 st_thread_join(trd1, NULL); 101 st_thread_join(trd1, NULL);
102 102
103 srs_trace("sleep test: end"); 103 srs_trace("sleep test: end");
104 - exit(0); 104 +
105 return 0; 105 return 0;
106 } 106 }
107 107
@@ -431,6 +431,8 @@ int pipe_test() @@ -431,6 +431,8 @@ int pipe_test()
431 431
432 int main(int argc, char** argv) 432 int main(int argc, char** argv)
433 { 433 {
  434 + srs_trace("ETIME=%d", ETIME);
  435 +
434 if (st_set_eventsys(ST_EVENTSYS_ALT) < 0) { 436 if (st_set_eventsys(ST_EVENTSYS_ALT) < 0) {
435 srs_trace("st_set_eventsys failed"); 437 srs_trace("st_set_eventsys failed");
436 return -1; 438 return -1;
@@ -534,10 +534,6 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -534,10 +534,6 @@ int SrsRtmpConn::playing(SrsSource* source)
534 // it's ok, do nothing. 534 // it's ok, do nothing.
535 ret = ERROR_SUCCESS; 535 ret = ERROR_SUCCESS;
536 srs_verbose("recv timeout, ignore. ret=%d", ret); 536 srs_verbose("recv timeout, ignore. ret=%d", ret);
537 -  
538 - // TODO: FIXME: the timeout may caused some dead loop.  
539 - // @see: https://github.com/winlinvip/simple-rtmp-server/issues/161  
540 - st_usleep(0);  
541 } else if (ret != ERROR_SUCCESS) { 537 } else if (ret != ERROR_SUCCESS) {
542 if (!srs_is_client_gracefully_close(ret)) { 538 if (!srs_is_client_gracefully_close(ret)) {
543 srs_error("recv client control message failed. ret=%d", ret); 539 srs_error("recv client control message failed. ret=%d", ret);
@@ -82,8 +82,9 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread) @@ -82,8 +82,9 @@ 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 + if (nb_read < 0 && errno == ETIME) {
87 return ERROR_SOCKET_TIMEOUT; 88 return ERROR_SOCKET_TIMEOUT;
88 } 89 }
89 90
@@ -110,8 +111,9 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread) @@ -110,8 +111,9 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread)
110 111
111 // On success a non-negative integer indicating the number of bytes actually read is returned 112 // 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) 113 // (a value less than nbyte means the network connection is closed or end of file is reached)
  114 + // Otherwise, a value of -1 is returned and errno is set to indicate the error.
113 if (nb_read != (ssize_t)size) { 115 if (nb_read != (ssize_t)size) {
114 - if (errno == ETIME) { 116 + if (nb_read < 0 && errno == ETIME) {
115 return ERROR_SOCKET_TIMEOUT; 117 return ERROR_SOCKET_TIMEOUT;
116 } 118 }
117 119
@@ -136,8 +138,10 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite) @@ -136,8 +138,10 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite)
136 *nwrite = nb_write; 138 *nwrite = nb_write;
137 } 139 }
138 140
  141 + // On success a non-negative integer equal to nbyte is returned.
  142 + // Otherwise, a value of -1 is returned and errno is set to indicate the error.
139 if (nb_write <= 0) { 143 if (nb_write <= 0) {
140 - if (errno == ETIME) { 144 + if (nb_write < 0 && errno == ETIME) {
141 return ERROR_SOCKET_TIMEOUT; 145 return ERROR_SOCKET_TIMEOUT;
142 } 146 }
143 147
@@ -158,8 +162,10 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) @@ -158,8 +162,10 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
158 *nwrite = nb_write; 162 *nwrite = nb_write;
159 } 163 }
160 164
  165 + // On success a non-negative integer equal to nbyte is returned.
  166 + // Otherwise, a value of -1 is returned and errno is set to indicate the error.
161 if (nb_write <= 0) { 167 if (nb_write <= 0) {
162 - if (errno == ETIME) { 168 + if (nb_write < 0 && errno == ETIME) {
163 return ERROR_SOCKET_TIMEOUT; 169 return ERROR_SOCKET_TIMEOUT;
164 } 170 }
165 171
@@ -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 15 34 +#define VERSION_REVISION 16
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 }
@@ -165,21 +169,24 @@ int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread) @@ -165,21 +169,24 @@ int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread)
165 int ret = ERROR_SUCCESS; 169 int ret = ERROR_SUCCESS;
166 170
167 size_t left = size; 171 size_t left = size;
168 - *nread = 0; 172 + ssize_t nb_read = 0;
169 173
170 while (left > 0) { 174 while (left > 0) {
171 - char* this_buf = (char*)buf + *nread; 175 + char* this_buf = (char*)buf + nb_read;
172 ssize_t this_nread; 176 ssize_t this_nread;
173 177
174 if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) { 178 if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) {
175 return ret; 179 return ret;
176 } 180 }
177 181
178 - *nread += this_nread; 182 + nb_read += this_nread;
179 left -= this_nread; 183 left -= this_nread;
180 } 184 }
181 185
182 - recv_bytes += *nread; 186 + if (nread) {
  187 + *nread = nb_read;
  188 + }
  189 + recv_bytes += nb_read;
183 190
184 return ret; 191 return ret;
185 } 192 }
@@ -188,17 +195,21 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) @@ -188,17 +195,21 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite)
188 { 195 {
189 int ret = ERROR_SUCCESS; 196 int ret = ERROR_SUCCESS;
190 197
191 - *nwrite = ::send(fd, (void*)buf, size, 0); 198 + ssize_t nb_write = ::send(fd, (void*)buf, size, 0);
192 199
193 - if (*nwrite <= 0) {  
194 - if (errno == ETIME) { 200 + if (nwrite) {
  201 + *nwrite = nb_write;
  202 + }
  203 +
  204 + if (nb_write <= 0) {
  205 + if (nb_write < 0 && errno == ETIME) {
195 return ERROR_SOCKET_TIMEOUT; 206 return ERROR_SOCKET_TIMEOUT;
196 } 207 }
197 208
198 return ERROR_SOCKET_WRITE; 209 return ERROR_SOCKET_WRITE;
199 } 210 }
200 211
201 - send_bytes += *nwrite; 212 + send_bytes += nb_write;
202 213
203 return ret; 214 return ret;
204 } 215 }