Skip to content

Commit

Permalink
[core] Added more logs around accept errors (#1883)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris authored Apr 15, 2021
1 parent aa51e2d commit b9d568e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1067,16 +1067,25 @@ SRTSOCKET CUDTUnited::accept_bond(const SRTSOCKET listeners [], int lsize, int64
SRTSOCKET CUDTUnited::accept(const SRTSOCKET listen, sockaddr* pw_addr, int* pw_addrlen)
{
if (pw_addr && !pw_addrlen)
{
LOGC(cnlog.Error, log << "srt_accept: provided address, but address length parameter is missing");
throw CUDTException(MJ_NOTSUP, MN_INVAL, 0);
}

CUDTSocket* ls = locateSocket(listen);

if (ls == NULL)
{
LOGC(cnlog.Error, log << "srt_accept: invalid listener socket ID value: " << listen);
throw CUDTException(MJ_NOTSUP, MN_SIDINVAL, 0);
}

// the "listen" socket must be in LISTENING status
if (ls->m_Status != SRTS_LISTENING)
{
LOGC(cnlog.Error, log << "srt_accept: socket @" << listen << " is not in listening state (forgot srt_listen?)");
throw CUDTException(MJ_NOTSUP, MN_NOLISTEN, 0);
}

// no "accept" in rendezvous connection setup
if (ls->m_pUDT->m_config.bRendezvous)
Expand Down Expand Up @@ -1125,15 +1134,22 @@ SRTSOCKET CUDTUnited::accept(const SRTSOCKET listen, sockaddr* pw_addr, int* pw_
{
// non-blocking receiving, no connection available
if (!ls->m_pUDT->m_config.bSynRecving)
{
LOGC(cnlog.Error, log << "srt_accept: no pending connection available at the moment");
throw CUDTException(MJ_AGAIN, MN_RDAVAIL, 0);
}

LOGC(cnlog.Error, log << "srt_accept: listener socket @" << listen << " is already closed");
// listening socket is closed
throw CUDTException(MJ_SETUP, MN_CLOSED, 0);
}

CUDTSocket* s = locateSocket(u);
if (s == NULL)
{
LOGC(cnlog.Error, log << "srt_accept: pending connection has unexpectedly closed");
throw CUDTException(MJ_SETUP, MN_CLOSED, 0);
}

// Set properly the SRTO_GROUPCONNECT flag
s->core().m_config.iGroupConnect = 0;
Expand Down Expand Up @@ -1166,7 +1182,7 @@ SRTSOCKET CUDTUnited::accept(const SRTSOCKET listen, sockaddr* pw_addr, int* pw_
#endif

ScopedLock cg(s->m_ControlLock);

if (pw_addr != NULL && pw_addrlen != NULL)
{
// Check if the length of the buffer to fill the name in
Expand Down

0 comments on commit b9d568e

Please sign in to comment.