diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-08-21 10:08:51 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-08-21 10:08:51 +0200 |
commit | fa5f92318e7cc08ac872be18d47387cf83c23cd0 (patch) | |
tree | 118b12cf95b478fd20916f745c0d1a7873e16040 /contrib/Socket.cpp | |
parent | 781c2c69c62a434bed64ff3cfa6d009ed3c479c1 (diff) | |
download | ODR-AudioEnc-fa5f92318e7cc08ac872be18d47387cf83c23cd0.tar.gz ODR-AudioEnc-fa5f92318e7cc08ac872be18d47387cf83c23cd0.tar.bz2 ODR-AudioEnc-fa5f92318e7cc08ac872be18d47387cf83c23cd0.zip |
Add tist support for EDI output, take code from odr-mmbtools-common
Diffstat (limited to 'contrib/Socket.cpp')
-rw-r--r-- | contrib/Socket.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/contrib/Socket.cpp b/contrib/Socket.cpp index c87606a..cd70a8e 100644 --- a/contrib/Socket.cpp +++ b/contrib/Socket.cpp @@ -381,7 +381,7 @@ bool TCPSocket::valid() const return m_sock != -1; } -void TCPSocket::connect(const std::string& hostname, int port, bool nonblock) +void TCPSocket::connect(const std::string& hostname, int port) { if (m_sock != INVALID_SOCKET) { throw std::logic_error("You may only connect an invalid TCPSocket"); @@ -415,16 +415,10 @@ void TCPSocket::connect(const std::string& hostname, int port, bool nonblock) if (sfd == -1) continue; - if (nonblock) { - int flags = fcntl(sfd, F_GETFL); - if (fcntl(sfd, F_SETFL, flags | O_NONBLOCK) == -1) { - std::string errstr(strerror(errno)); - throw std::runtime_error("TCP: Could not set O_NONBLOCK: " + errstr); - } - } - int ret = ::connect(sfd, rp->ai_addr, rp->ai_addrlen); if (ret != -1 or (ret == -1 and errno == EINPROGRESS)) { + // As the TCPClient could set the socket to nonblocking, we + // must handle EINPROGRESS here m_sock = sfd; break; } @@ -699,8 +693,13 @@ ssize_t TCPClient::recv(void *buffer, size_t length, int flags, int timeout_ms) void TCPClient::reconnect() { - const bool nonblock = true; - m_sock.connect(m_hostname, m_port, nonblock); + int flags = fcntl(m_sock.m_sock, F_GETFL); + if (fcntl(m_sock.m_sock, F_SETFL, flags | O_NONBLOCK) == -1) { + std::string errstr(strerror(errno)); + throw std::runtime_error("TCP: Could not set O_NONBLOCK: " + errstr); + } + + m_sock.connect(m_hostname, m_port); } TCPConnection::TCPConnection(TCPSocket&& sock) : |