-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring and debug improvements series from group code #1028
Conversation
…s comparison for Mac
…eck in SockaddrToString
@@ -91,7 +91,7 @@ class Medium | |||
template <class DerivedMedium, class SocketType> | |||
static Medium* CreateAcceptor(DerivedMedium* self, const sockaddr_in& sa, SocketType sock, size_t chunk) | |||
{ | |||
string addr = SockaddrToString((sockaddr*)&sa); | |||
string addr = SockaddrToString(sockaddr_any((sockaddr*)&sa, sizeof sa)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix for the safer use of the sockaddr_any
here (involves checking the source object size).
@@ -110,13 +98,63 @@ CUDTSocket::~CUDTSocket() | |||
pthread_cond_destroy(&m_AcceptCond); | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are functions that will be later intermediately used in the socket group code. Some of them are not part of the group code, just they may use other functions that are.
@@ -247,6 +291,95 @@ int CUDTUnited::cleanup() | |||
return 0; | |||
} | |||
|
|||
SRTSOCKET CUDTUnited::generateSocketID() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generation of the socket ID is now widely changed because the socket ID will be also used for groups. Socket ID will now be using less bits as before, as one bit is now reserved to mark that the ID is of a group. New identifiers will come from the same pool, except that for the groups it will get this additional bit.
@@ -309,13 +437,15 @@ int CUDTUnited::newConnection(const SRTSOCKET listen, const sockaddr_any& peer, | |||
|
|||
// Can't manage this error through an exception because this is | |||
// running in the listener loop. | |||
CUDTSocket* ls = locate(listen); | |||
CUDTSocket* ls = locateSocket(listen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See definition for locateSocket
.
@@ -507,13 +659,18 @@ int CUDTUnited::newConnection(const SRTSOCKET listen, const sockaddr_any& peer, | |||
return 1; | |||
} | |||
|
|||
// static forwarder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been just moved out of the header file.
@@ -524,25 +681,12 @@ int CUDTUnited::installAcceptHook(const SRTSOCKET lsn, srt_listen_callback_fn* h | |||
return 0; | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed lookup
: see definition of locateSocket
.
@@ -782,19 +906,45 @@ SRTSOCKET CUDTUnited::accept(const SRTSOCKET listen, sockaddr* pw_addr, int* pw_ | |||
return u; | |||
} | |||
|
|||
int CUDTUnited::connect(const SRTSOCKET u, const sockaddr* name, int namelen, int32_t forced_isn) | |||
int CUDTUnited::connect(SRTSOCKET u, const sockaddr* srcname, int srclen, const sockaddr* tarname, int tarlen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an extra version of connect
that maps to srt_connect_bind
. The latter is used as a combination of bind
and connect
(simple replacement in case of sockets). However this bind-then-connect cannot be used this way for the socket groups, therefore it needs an extra function for it.
@@ -926,7 +1080,7 @@ int CUDTUnited::close(const SRTSOCKET u) | |||
CTimer::triggerEvent(); | |||
} | |||
|
|||
HLOGC(mglog.Debug, log << "%" << u << ": GLOBAL: CLOSING DONE"); | |||
HLOGC(mglog.Debug, log << "@" << u << ": GLOBAL: CLOSING DONE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll find more replacement from %
into @
in the logs. This was a mistake earlier to use the %
as a number prefix here. The %
is meant to be a prefix for a sequence number, while @
is to be a prefix for a socket id.
@@ -1356,16 +1499,20 @@ int CUDTUnited::epoll_release(const int eid) | |||
return m_EPoll.release(eid); | |||
} | |||
|
|||
CUDTSocket* CUDTUnited::locate(const SRTSOCKET u) | |||
CUDTSocket* CUDTUnited::locateSocket(const SRTSOCKET u, ErrorHandling erh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason why locate
was renamed to locateSocket
was first of all because there will be another function added, locateGroup
.
Also the lookup
function has been removed because it duplicates the functionality of locate
and the only difference was the way of informing about the failure: locate
returned error, lookup
threw exception. These two things have been now made common by locateSocket
which's error handling method is selected through the additional parameter.
@@ -1908,6 +2061,18 @@ SRTSOCKET CUDT::socket() | |||
} | |||
} | |||
|
|||
int CUDT::setError(const CUDTException& e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of them has been moved here from the header file - due to the reason of solving the header dependency problem. The other one is useful for quick returning a failure.
} | ||
return s_UDTUnited.bind(u, sa); | ||
CUDTSocket* s = s_UDTUnited.locateSocket(u); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CUDTUnited::bind
has been changed to get the CUDTSocket*
instead of SRTSOCKET
and the socket lookup part was moved out of this. This is because this function will get much wider use, including a situation when the CUDTSocket
object is already at hand.
// a +% b : shift a by b | ||
// a == b : equality is same as for just numbers | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This time this convention IS used in some comments.
@@ -61,18 +61,13 @@ modified by | |||
#include "packet.h" | |||
#include "api.h" // SockaddrToString - possibly move it to somewhere else | |||
#include "logging.h" | |||
#include "netinet_any.h" | |||
#include "utilities.h" | |||
|
|||
#ifdef _WIN32 | |||
typedef int socklen_t; | |||
#endif | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This below is moved to common.h
@@ -5408,6 +5403,9 @@ bool CUDT::close() | |||
m_bConnected = false; | |||
} | |||
|
|||
if (m_pCryptoControl) | |||
m_pCryptoControl->close(); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bugfix for something that has appeared only during testing of the group code. The problem was that sometimes the close
call wasn't done when required, or sometimes it was attempted to be done twice (after the pointer was cleared or before it was set to a valid object).
self->m_pRcvBuffer->skipData(seqlen); | ||
|
||
self->m_iRcvLastSkipAck = skiptoseqno; | ||
|
||
#if ENABLE_LOGGING | ||
int64_t timediff_us = 0; | ||
if (!is_zero(tsbpdtime)) | ||
timediff_us = count_microseconds(tsbpdtime - steady_clock::now()); | ||
timediff_us = count_microseconds(steady_clock::now() - tsbpdtime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug value fix. This was displayed usually when tsbpdtime
was already in the past, so it was practically always displaying a negative value.
num = m_pSndLossList->insert(m_iSndLastAck, losslist_hi); | ||
} | ||
else | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change in the current code that reacts on a situation that wasn't handled before at all. This is a handler for a situation when the lossreport declares a range of packets that as a whole is located behind the current value of m_iSndLastAck
, that is, refers to packets that have been already dismissed from the sender buffer, or weren't ever in the sender buffer at all. This kind of situation is virtually impossible to happen normally in SRT, however the group code introduce some code based on ISN screwup that adds a risk that this could happen.
LOGC(dlog.Error, | ||
log << "IPE: packLostData: LOST packet negative offset: seqoff(m_iSeqNo " << w_packet.m_iSeqNo | ||
<< ", m_iSndLastDataAck " << m_iSndLastDataAck << ")=" << offset << ". Continue"); | ||
// XXX Likely that this will never be executed because if the upper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces only extra logs and variable shortcuts, plus conditional ability to disable key packet sending, for development-testing purposes.
@@ -8017,6 +8185,9 @@ void CUDT::sendLossReport(const std::vector<std::pair<int32_t, int32_t> > &loss_ | |||
|
|||
int CUDT::processData(CUnit *in_unit) | |||
{ | |||
if (m_bClosing) | |||
return -1; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The group code has given it more of a chance to receive a packet and process it while closing has started.
@@ -51,7 +51,12 @@ written by | |||
// LOGC uses an iostream-like syntax, using the special 'log' symbol. | |||
// This symbol isn't visible outside the log macro parameters. | |||
// Usage: LOGC(mglog.Debug, log << param1 << param2 << param3); | |||
#define LOGC(logdes, args) if (logdes.CheckEnabled()) { srt_logging::LogDispatcher::Proxy log(logdes); log.setloc(__FILE__, __LINE__, __FUNCTION__); args; } | |||
#define LOGC(logdes, args) if (logdes.CheckEnabled()) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change improves the compiler error report for a case when someone forgot to pass the log
marker in the call to LOGC
and HLOGC
macros. This enforces the interpretation of args
as convertible to the type of log
so that when someone mistakenly writes LOGC(mglog.Debug, "ACK received")
the compiler will complain about inability to convert the string constant into the type of log
.
@@ -93,6 +93,15 @@ | |||
#include <unistd.h> | |||
#include <fcntl.h> | |||
|
|||
#ifdef __cplusplus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes some problems that appeared with the C API.
HLOGC(mglog.Debug, log << "RID: socket @" << i->m_iID | ||
<< " removed - EXPIRED (" | ||
// The "enforced on FAILURE" is below when processAsyncConnectRequest failed. | ||
<< (is_zero(i->m_tsTTL) ? "enforced on FAILURE" : "passed TTL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix: when i->m_tsTTL
is zero, it means that it was enforced on failure.
#define SRT_ATR_DEPRECATED | ||
#define SRT_ATR_DEPRECATED_PX | ||
|
||
// Nodiscard: issue a warning if the return value was discarded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is introduced because some compilers use prefix-type modifier, others use postfix-type modifier. This provides the attribute support for Microsoft compilers.
inline RefType* AddressOf(RefType& r) | ||
{ | ||
return (RefType*)(&(unsigned char&)(r)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be later used in some extra utilities.
private: | ||
template <class X> | ||
explicit_t(const X& another); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in order to prevent misuse of a changed API, while C++ allows a string constant to be converted to bool without making the developer wiser.
Closed due to merged all dependent PRs. |
NOTE: Treat this thing as a draft and orientation guide. Things submitted here will be split into single PRs:
(others will follow)
Major reasons for changes here:
The code is added with extra comments in the review section.