diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-08-13 10:29:39 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-08-13 10:29:39 +0200 |
commit | a5c50a4f262f0a880734623f79d4dc2f1aa8a0a2 (patch) | |
tree | 1772ef47d98a68245c3d04d95637e5b9c1040904 /lib/Socket.cpp | |
parent | 69aba72f0883c5effb5c3c2991d0c5257deb7409 (diff) | |
download | dabmod-a5c50a4f262f0a880734623f79d4dc2f1aa8a0a2.tar.gz dabmod-a5c50a4f262f0a880734623f79d4dc2f1aa8a0a2.tar.bz2 dabmod-a5c50a4f262f0a880734623f79d4dc2f1aa8a0a2.zip |
Pull in files from odr-mmbtools-common
Replace ASIO by simpler implementation, meaning that the telnet
RC now only supports a single connection.
Move Log, RC to lib/
Diffstat (limited to 'lib/Socket.cpp')
-rw-r--r-- | lib/Socket.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/Socket.cpp b/lib/Socket.cpp index c87606a..cd70a8e 100644 --- a/lib/Socket.cpp +++ b/lib/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) : |