提交 49824baf authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Should fix #333:

- Do not close RTC::UdpSocket or RTC::TcpConnection when
  uv_udp_try_send() or uv_try_write() fail due to an unexpected error
  other than EAGAIN.
- Otherwise, while reading from a TcpConnection it my happen that there
  are more than a single "packet". If the first packet is a STUN request
  and the IceServer generates a sync response for it, and
  TcpConnection::Write() fails for unknown reason and we delete the
  TcpConnection, the reading process would continue with the second
  "packet", meaning that we are in a deallocated TcpConnection
  instance and BUMP!
上级 48837cbc
...@@ -59,7 +59,7 @@ namespace RTC ...@@ -59,7 +59,7 @@ namespace RTC
// We may receive multiple packets in the same TCP chunk. If one of them is // We may receive multiple packets in the same TCP chunk. If one of them is
// a DTLS Close Alert this would be closed (Close() called) so we cannot call // a DTLS Close Alert this would be closed (Close() called) so we cannot call
// our listeners anymore. // our listeners anymore.
if (::TcpConnection::IsClosed()) if (IsClosed())
return; return;
size_t dataLen = this->bufferDataLen - this->frameStart; size_t dataLen = this->bufferDataLen - this->frameStart;
...@@ -138,7 +138,10 @@ namespace RTC ...@@ -138,7 +138,10 @@ namespace RTC
"connection"); "connection");
// Close the socket. // Close the socket.
::TcpConnection::ErrorReceiving(); ErrorReceiving();
// And exit fast since we are supposed to be deallocated.
return;
} }
} }
// The buffer is not full. // The buffer is not full.
......
...@@ -232,21 +232,10 @@ void TcpConnection::Write(const uint8_t* data, size_t len, TcpConnection::onSend ...@@ -232,21 +232,10 @@ void TcpConnection::Write(const uint8_t* data, size_t len, TcpConnection::onSend
// Error. Should not happen. // Error. Should not happen.
else if (written < 0) else if (written < 0)
{ {
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed, trying uv_write(): %s", uv_strerror(written));
if (cb) // Set written to 0 so pendingLen can be properly calculated.
{ written = 0;
(*cb)(false);
delete cb;
}
Close();
// Notify the listener.
this->listener->OnTcpConnectionClosed(this);
return;
} }
// MS_DEBUG_DEV( // MS_DEBUG_DEV(
...@@ -351,21 +340,10 @@ void TcpConnection::Write( ...@@ -351,21 +340,10 @@ void TcpConnection::Write(
// Error. Should not happen. // Error. Should not happen.
else if (written < 0) else if (written < 0)
{ {
MS_WARN_DEV("uv_try_write() failed, closing the connection: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed, trying uv_write(): %s", uv_strerror(written));
if (cb) // Set written to 0 so pendingLen can be properly calculated.
{ written = 0;
(*cb)(false);
delete cb;
}
Close();
// Notify the listener.
this->listener->OnTcpConnectionClosed(this);
return;
} }
size_t pendingLen = totalLen - written; size_t pendingLen = totalLen - written;
......
...@@ -179,16 +179,7 @@ void UdpSocket::Send( ...@@ -179,16 +179,7 @@ void UdpSocket::Send(
// Error, // Error,
if (sent != UV_EAGAIN) if (sent != UV_EAGAIN)
{ {
MS_WARN_DEV("uv_udp_try_send() failed: %s", uv_strerror(sent)); MS_WARN_DEV("uv_udp_send() failed, trying uv_udp_send(): %s", uv_strerror(sent));
if (cb)
{
(*cb)(false);
delete cb;
}
return;
} }
// MS_DEBUG_DEV("could not send the datagram at first time, using uv_udp_send() now"); // MS_DEBUG_DEV("could not send the datagram at first time, using uv_udp_send() now");
......
...@@ -189,14 +189,10 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len) ...@@ -189,14 +189,10 @@ void UnixStreamSocket::Write(const uint8_t* data, size_t len)
// Error. Should not happen. // Error. Should not happen.
else if (written < 0) else if (written < 0)
{ {
MS_ERROR_STD("uv_try_write() failed, closing the socket: %s", uv_strerror(written)); MS_WARN_DEV("uv_try_write() failed, trying uv_write(): %s", uv_strerror(written));
Close(); // Set written to 0 so pendingLen can be properly calculated.
written = 0;
// Notify the subclass.
UserOnUnixStreamSocketClosed();
return;
} }
size_t pendingLen = len - written; size_t pendingLen = len - written;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论