mirror of
https://github.com/transmission/transmission
synced 2025-02-22 06:00:41 +00:00
fix: unsupported peer socket type 0 assertion failure (#2687)
* refactor: downgrade unsupported socket type from assertion to log warning Fixes #833.
This commit is contained in:
parent
aec1b29e88
commit
46c7a7c47c
1 changed files with 84 additions and 111 deletions
|
@ -314,13 +314,8 @@ static void event_read_cb(evutil_socket_t fd, short /*event*/, void* vio)
|
||||||
}
|
}
|
||||||
|
|
||||||
char errstr[512];
|
char errstr[512];
|
||||||
dbgmsg(
|
tr_net_strerror(errstr, sizeof(errstr), e);
|
||||||
io,
|
dbgmsg(io, "event_read_cb err: res:%d, what:%hd, errno:%d (%s)", res, what, e, errstr);
|
||||||
"event_read_cb got an error. res is %d, what is %hd, errno is %d (%s)",
|
|
||||||
res,
|
|
||||||
what,
|
|
||||||
e,
|
|
||||||
tr_net_strerror(errstr, sizeof(errstr), e));
|
|
||||||
|
|
||||||
if (io->gotError != nullptr)
|
if (io->gotError != nullptr)
|
||||||
{
|
{
|
||||||
|
@ -842,7 +837,7 @@ static void io_close_socket(tr_peerIo* io)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
TR_ASSERT_MSG(false, "unsupported peer socket type %d", io->socket.type);
|
dbgmsg(io, "unsupported peer socket type %d", io->socket.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
io->socket = {};
|
io->socket = {};
|
||||||
|
@ -1232,64 +1227,60 @@ void tr_peerIoDrain(tr_peerIo* io, struct evbuffer* inbuf, size_t byteCount)
|
||||||
|
|
||||||
static int tr_peerIoTryRead(tr_peerIo* io, size_t howmuch)
|
static int tr_peerIoTryRead(tr_peerIo* io, size_t howmuch)
|
||||||
{
|
{
|
||||||
auto res = int{};
|
howmuch = io->bandwidth->clamp(TR_DOWN, howmuch);
|
||||||
|
if (howmuch == 0)
|
||||||
if ((howmuch = io->bandwidth->clamp(TR_DOWN, howmuch)) != 0)
|
|
||||||
{
|
{
|
||||||
switch (io->socket.type)
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res = int{};
|
||||||
|
switch (io->socket.type)
|
||||||
|
{
|
||||||
|
case TR_PEER_SOCKET_TYPE_UTP:
|
||||||
|
/* UTP_RBDrained notifies libutp that your read buffer is emtpy.
|
||||||
|
* It opens up the congestion window by sending an ACK (soonish)
|
||||||
|
* if one was not going to be sent. */
|
||||||
|
if (evbuffer_get_length(io->inbuf) == 0)
|
||||||
{
|
{
|
||||||
case TR_PEER_SOCKET_TYPE_UTP:
|
UTP_RBDrained(io->socket.handle.utp);
|
||||||
/* UTP_RBDrained notifies libutp that your read buffer is emtpy.
|
}
|
||||||
* It opens up the congestion window by sending an ACK (soonish)
|
|
||||||
* if one was not going to be sent. */
|
break;
|
||||||
if (evbuffer_get_length(io->inbuf) == 0)
|
|
||||||
|
case TR_PEER_SOCKET_TYPE_TCP:
|
||||||
|
{
|
||||||
|
EVUTIL_SET_SOCKET_ERROR(0);
|
||||||
|
res = evbuffer_read(io->inbuf, io->socket.handle.tcp, (int)howmuch);
|
||||||
|
int const e = EVUTIL_SOCKET_ERROR();
|
||||||
|
|
||||||
|
char errstr[512];
|
||||||
|
dbgmsg(io, "read %d from peer (%s)", res, res == -1 ? tr_net_strerror(errstr, sizeof(errstr), e) : "");
|
||||||
|
|
||||||
|
if (evbuffer_get_length(io->inbuf) != 0)
|
||||||
{
|
{
|
||||||
UTP_RBDrained(io->socket.handle.utp);
|
canReadWrapper(io);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res <= 0 && io->gotError != nullptr && e != EAGAIN && e != EINTR && e != EINPROGRESS)
|
||||||
|
{
|
||||||
|
short what = BEV_EVENT_READING | BEV_EVENT_ERROR;
|
||||||
|
|
||||||
|
if (res == 0)
|
||||||
|
{
|
||||||
|
what |= BEV_EVENT_EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr_net_strerror(errstr, sizeof(errstr), e);
|
||||||
|
dbgmsg(io, "tr_peerIoTryRead err: res:%d what:%hd, errno:%d (%s)", res, what, e, errstr);
|
||||||
|
|
||||||
|
io->gotError(io, what, io->userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TR_PEER_SOCKET_TYPE_TCP:
|
|
||||||
{
|
|
||||||
char err_buf[512];
|
|
||||||
|
|
||||||
EVUTIL_SET_SOCKET_ERROR(0);
|
|
||||||
res = evbuffer_read(io->inbuf, io->socket.handle.tcp, (int)howmuch);
|
|
||||||
int const e = EVUTIL_SOCKET_ERROR();
|
|
||||||
|
|
||||||
dbgmsg(io, "read %d from peer (%s)", res, res == -1 ? tr_net_strerror(err_buf, sizeof(err_buf), e) : "");
|
|
||||||
|
|
||||||
if (evbuffer_get_length(io->inbuf) != 0)
|
|
||||||
{
|
|
||||||
canReadWrapper(io);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res <= 0 && io->gotError != nullptr && e != EAGAIN && e != EINTR && e != EINPROGRESS)
|
|
||||||
{
|
|
||||||
short what = BEV_EVENT_READING | BEV_EVENT_ERROR;
|
|
||||||
|
|
||||||
if (res == 0)
|
|
||||||
{
|
|
||||||
what |= BEV_EVENT_EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
dbgmsg(
|
|
||||||
io,
|
|
||||||
"tr_peerIoTryRead got an error. res is %d, what is %hd, errno is %d (%s)",
|
|
||||||
res,
|
|
||||||
what,
|
|
||||||
e,
|
|
||||||
tr_net_strerror(err_buf, sizeof(err_buf), e));
|
|
||||||
|
|
||||||
io->gotError(io, what, io->userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
TR_ASSERT_MSG(false, "unsupported peer socket type %d", io->socket.type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
dbgmsg(io, "unsupported peer socket type %d", io->socket.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -1298,57 +1289,49 @@ static int tr_peerIoTryRead(tr_peerIo* io, size_t howmuch)
|
||||||
static int tr_peerIoTryWrite(tr_peerIo* io, size_t howmuch)
|
static int tr_peerIoTryWrite(tr_peerIo* io, size_t howmuch)
|
||||||
{
|
{
|
||||||
auto const old_len = size_t{ evbuffer_get_length(io->outbuf) };
|
auto const old_len = size_t{ evbuffer_get_length(io->outbuf) };
|
||||||
auto n = int{};
|
|
||||||
|
|
||||||
dbgmsg(io, "in tr_peerIoTryWrite %zu", howmuch);
|
dbgmsg(io, "in tr_peerIoTryWrite %zu", howmuch);
|
||||||
|
howmuch = std::min(howmuch, old_len);
|
||||||
if (howmuch > old_len)
|
howmuch = io->bandwidth->clamp(TR_UP, howmuch);
|
||||||
|
if (howmuch == 0)
|
||||||
{
|
{
|
||||||
howmuch = old_len;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((howmuch = io->bandwidth->clamp(TR_UP, howmuch)) != 0)
|
auto n = int{};
|
||||||
|
switch (io->socket.type)
|
||||||
{
|
{
|
||||||
switch (io->socket.type)
|
case TR_PEER_SOCKET_TYPE_UTP:
|
||||||
|
UTP_Write(io->socket.handle.utp, howmuch);
|
||||||
|
n = old_len - evbuffer_get_length(io->outbuf);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TR_PEER_SOCKET_TYPE_TCP:
|
||||||
{
|
{
|
||||||
case TR_PEER_SOCKET_TYPE_UTP:
|
EVUTIL_SET_SOCKET_ERROR(0);
|
||||||
UTP_Write(io->socket.handle.utp, howmuch);
|
n = tr_evbuffer_write(io, io->socket.handle.tcp, howmuch);
|
||||||
n = old_len - evbuffer_get_length(io->outbuf);
|
int const e = EVUTIL_SOCKET_ERROR();
|
||||||
break;
|
|
||||||
|
|
||||||
case TR_PEER_SOCKET_TYPE_TCP:
|
if (n > 0)
|
||||||
{
|
{
|
||||||
EVUTIL_SET_SOCKET_ERROR(0);
|
didWriteWrapper(io, n);
|
||||||
n = tr_evbuffer_write(io, io->socket.handle.tcp, howmuch);
|
|
||||||
int const e = EVUTIL_SOCKET_ERROR();
|
|
||||||
|
|
||||||
if (n > 0)
|
|
||||||
{
|
|
||||||
didWriteWrapper(io, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (n < 0 && io->gotError != nullptr && e != 0 && e != EPIPE && e != EAGAIN && e != EINTR && e != EINPROGRESS)
|
|
||||||
{
|
|
||||||
char errstr[512];
|
|
||||||
short const what = BEV_EVENT_WRITING | BEV_EVENT_ERROR;
|
|
||||||
|
|
||||||
dbgmsg(
|
|
||||||
io,
|
|
||||||
"tr_peerIoTryWrite got an error. res is %d, what is %hd, errno is %d (%s)",
|
|
||||||
n,
|
|
||||||
what,
|
|
||||||
e,
|
|
||||||
tr_net_strerror(errstr, sizeof(errstr), e));
|
|
||||||
|
|
||||||
io->gotError(io, what, io->userData);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
if (n < 0 && io->gotError != nullptr && e != 0 && e != EPIPE && e != EAGAIN && e != EINTR && e != EINPROGRESS)
|
||||||
TR_ASSERT_MSG(false, "unsupported peer socket type %d", io->socket.type);
|
{
|
||||||
|
char errstr[512];
|
||||||
|
short const what = BEV_EVENT_WRITING | BEV_EVENT_ERROR;
|
||||||
|
|
||||||
|
tr_net_strerror(errstr, sizeof(errstr), e);
|
||||||
|
dbgmsg(io, "tr_peerIoTryWrite err: res:%d, what:%hd, errno:%d (%s)", n, what, e, errstr);
|
||||||
|
io->gotError(io, what, io->userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
dbgmsg(io, "unsupported peer socket type %d", io->socket.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
|
@ -1359,19 +1342,9 @@ int tr_peerIoFlush(tr_peerIo* io, tr_direction dir, size_t limit)
|
||||||
TR_ASSERT(tr_isPeerIo(io));
|
TR_ASSERT(tr_isPeerIo(io));
|
||||||
TR_ASSERT(tr_isDirection(dir));
|
TR_ASSERT(tr_isDirection(dir));
|
||||||
|
|
||||||
int bytesUsed = 0;
|
int const bytes_used = dir == TR_DOWN ? tr_peerIoTryRead(io, limit) : tr_peerIoTryWrite(io, limit);
|
||||||
|
dbgmsg(io, "flushing peer-io, direction:%d, limit:%zu, byte_used:%d", (int)dir, limit, bytes_used);
|
||||||
if (dir == TR_DOWN)
|
return bytes_used;
|
||||||
{
|
|
||||||
bytesUsed = tr_peerIoTryRead(io, limit);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bytesUsed = tr_peerIoTryWrite(io, limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
dbgmsg(io, "flushing peer-io, direction %d, limit %zu, notifyBandwidthConsumedBytes %d", (int)dir, limit, bytesUsed);
|
|
||||||
return bytesUsed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int tr_peerIoFlushOutgoingProtocolMsgs(tr_peerIo* io)
|
int tr_peerIoFlushOutgoingProtocolMsgs(tr_peerIo* io)
|
||||||
|
|
Loading…
Reference in a new issue