diff --git a/README.md b/README.md index 6aaffca38..2ae2b9435 100755 --- a/README.md +++ b/README.md @@ -208,10 +208,11 @@ Supported operating systems and hardware: * 2013-10-17, Created.
## History +* 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. * v1.0, 2014-11-06, use number for macro VERSION_MAJOR, VERSION_MINOR and VERSION_REVISION. 1.0.5. -* 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. +* 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. * v1.0, 2014-10-24, rename wiki/xxx to wiki/v1_CN_xxx. 1.0.2. -* 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. +* 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. * 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. * 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. * v1.0, 2014-10-08, fix [#162](https://github.com/winlinvip/simple-rtmp-server/issues/162), failed if no epoll. 0.9.222. diff --git a/trunk/src/app/srs_app_st_socket.cpp b/trunk/src/app/srs_app_st_socket.cpp index e1c8e63cf..92618fdfc 100644 --- a/trunk/src/app/srs_app_st_socket.cpp +++ b/trunk/src/app/srs_app_st_socket.cpp @@ -82,8 +82,10 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread) // On success a non-negative integer indicating the number of bytes actually read is returned // (a value of 0 means the network connection is closed or end of file is reached). + // Otherwise, a value of -1 is returned and errno is set to indicate the error. if (nb_read <= 0) { - if (errno == ETIME) { + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 + if (nb_read < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } @@ -110,8 +112,10 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread) // On success a non-negative integer indicating the number of bytes actually read is returned // (a value less than nbyte means the network connection is closed or end of file is reached) + // Otherwise, a value of -1 is returned and errno is set to indicate the error. if (nb_read != (ssize_t)size) { - if (errno == ETIME) { + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 + if (nb_read < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } @@ -136,8 +140,11 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite) *nwrite = nb_write; } + // On success a non-negative integer equal to nbyte is returned. + // Otherwise, a value of -1 is returned and errno is set to indicate the error. if (nb_write <= 0) { - if (errno == ETIME) { + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 + if (nb_write < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } @@ -158,8 +165,11 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) *nwrite = nb_write; } + // On success a non-negative integer equal to nbyte is returned. + // Otherwise, a value of -1 is returned and errno is set to indicate the error. if (nb_write <= 0) { - if (errno == ETIME) { + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 + if (nb_write < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 1b0fb3e60..bd339e733 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 1 #define VERSION_MINOR 0 -#define VERSION_REVISION 5 +#define VERSION_REVISION 6 // server info. #define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_ROLE "origin/edge server" diff --git a/trunk/src/libs/srs_lib_simple_socket.cpp b/trunk/src/libs/srs_lib_simple_socket.cpp index 202155503..cc8476778 100644 --- a/trunk/src/libs/srs_lib_simple_socket.cpp +++ b/trunk/src/libs/srs_lib_simple_socket.cpp @@ -82,23 +82,27 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) { int ret = ERROR_SUCCESS; - *nread = ::recv(fd, buf, size, 0); + ssize_t nb_read = ::recv(fd, buf, size, 0); + + if (nread) { + *nread = nb_read; + } // On success a non-negative integer indicating the number of bytes actually read is returned // (a value of 0 means the network connection is closed or end of file is reached). - if (*nread <= 0) { - if (errno == ETIME) { + if (nb_read <= 0) { + if (nb_read < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } - if (*nread == 0) { + if (nb_read == 0) { errno = ECONNRESET; } return ERROR_SOCKET_READ; } - recv_bytes += *nread; + recv_bytes += nb_read; return ret; } @@ -139,17 +143,25 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) { int ret = ERROR_SUCCESS; - *nwrite = ::writev(fd, iov, iov_size); + ssize_t nb_write = ::writev(fd, iov, iov_size); + + if (nwrite) { + *nwrite = nb_write; + } - if (*nwrite <= 0) { - if (errno == ETIME) { + // On success, the readv() function returns the number of bytes read; + // the writev() function returns the number of bytes written. On error, -1 is + // returned, and errno is set appropriately. + if (nb_write <= 0) { + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 + if (nb_write < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } return ERROR_SOCKET_WRITE; } - send_bytes += *nwrite; + send_bytes += nb_write; return ret; } @@ -165,21 +177,24 @@ int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread) int ret = ERROR_SUCCESS; size_t left = size; - *nread = 0; + ssize_t nb_read = 0; while (left > 0) { - char* this_buf = (char*)buf + *nread; + char* this_buf = (char*)buf + nb_read; ssize_t this_nread; if ((ret = this->read(this_buf, left, &this_nread)) != ERROR_SUCCESS) { return ret; } - *nread += this_nread; + nb_read += this_nread; left -= this_nread; } - recv_bytes += *nread; + if (nread) { + *nread = nb_read; + } + recv_bytes += nb_read; return ret; } @@ -188,17 +203,22 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite) { int ret = ERROR_SUCCESS; - *nwrite = ::send(fd, (void*)buf, size, 0); + ssize_t nb_write = ::send(fd, (void*)buf, size, 0); + + if (nwrite) { + *nwrite = nb_write; + } - if (*nwrite <= 0) { - if (errno == ETIME) { + if (nb_write <= 0) { + // @see https://github.com/winlinvip/simple-rtmp-server/issues/200 + if (nb_write < 0 && errno == ETIME) { return ERROR_SOCKET_TIMEOUT; } return ERROR_SOCKET_WRITE; } - send_bytes += *nwrite; + send_bytes += nb_write; return ret; }