-
Notifications
You must be signed in to change notification settings - Fork 917
Description
As a continuation of the discussion in #510, srtcore/channel.cpp uses both UNIX and unix macros to define conditions to use non-blocking sockets.
- Can we get rid of blocking-mode sockets? ❓
- Use
unixmacro instead ofUNIX. ❗
Refer to void CChannel::setUDPSockOpt().
As @rndi noted,
According to this, unix would be more appropriate and that's what is used in other places in our code, however that will also include BSD which is probably what we want anyway.
I also haven't found, how and when the UNIX macro is defined, and on which OS. Furthermore, we use the lowercase unix definition in other places of the same source file.
According to @ethouris,
UNIX is not defined under the same conditions as unix. For now I think the code should keep consistent the usage of UNIX in all dependent places.
The question is how to properly handle the conditions, when the sockets are still used in the blocking mode with a timeout:
#ifdef UNIX
#elif defined(_WIN32)
#else
timeval tv;
tv.tv_sec = 0;
#if defined (BSD) || defined (OSX) || (TARGET_OS_IOS == 1) || (TARGET_OS_TV == 1)
// Known BSD bug as the day I wrote this code.
// A small time out value will cause the socket to block forever.
tv.tv_usec = 10000;
#else
tv.tv_usec = 100;
#endif
// Set receiving time-out value
if (0 != ::setsockopt(m_iSocket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(timeval)))
throw CUDTException(MJ_SETUP, MN_NORES, NET_ERROR);
#endif
For the sake of code clarity, it might be a good idea to move those platform-dependent marcos into a separate header, and define those features there.