mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for bug #200, deadloop when read/write 0 and ETIME. 2.0.16.
This commit is contained in:
parent
77cf885d8c
commit
0bc35e093c
6 changed files with 42 additions and 26 deletions
|
@ -534,10 +534,6 @@ int SrsRtmpConn::playing(SrsSource* source)
|
|||
// it's ok, do nothing.
|
||||
ret = ERROR_SUCCESS;
|
||||
srs_verbose("recv timeout, ignore. ret=%d", ret);
|
||||
|
||||
// TODO: FIXME: the timeout may caused some dead loop.
|
||||
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/161
|
||||
st_usleep(0);
|
||||
} else if (ret != ERROR_SUCCESS) {
|
||||
if (!srs_is_client_gracefully_close(ret)) {
|
||||
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)
|
|||
|
||||
// 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) {
|
||||
if (nb_read < 0 && errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
|
@ -110,8 +111,9 @@ 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) {
|
||||
if (nb_read < 0 && errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
|
@ -136,8 +138,10 @@ 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) {
|
||||
if (nb_write < 0 && errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
|
@ -158,8 +162,10 @@ 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) {
|
||||
if (nb_write < 0 && errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// current release version
|
||||
#define VERSION_MAJOR 2
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 15
|
||||
#define VERSION_REVISION 16
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "SRS"
|
||||
#define RTMP_SIG_SRS_ROLE "origin/edge server"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -165,21 +169,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 +195,21 @@ 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 <= 0) {
|
||||
if (errno == ETIME) {
|
||||
if (nwrite) {
|
||||
*nwrite = nb_write;
|
||||
}
|
||||
|
||||
if (nb_write <= 0) {
|
||||
if (nb_write < 0 && errno == ETIME) {
|
||||
return ERROR_SOCKET_TIMEOUT;
|
||||
}
|
||||
|
||||
return ERROR_SOCKET_WRITE;
|
||||
}
|
||||
|
||||
send_bytes += *nwrite;
|
||||
send_bytes += nb_write;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue