aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/TcpSocket.cpp10
-rw-r--r--src/TcpSocket.h13
-rw-r--r--src/dabOutput/dabOutputTcp.cpp6
3 files changed, 21 insertions, 8 deletions
diff --git a/src/TcpSocket.cpp b/src/TcpSocket.cpp
index 433e5c1..6791286 100644
--- a/src/TcpSocket.cpp
+++ b/src/TcpSocket.cpp
@@ -116,6 +116,11 @@ TcpSocket::~TcpSocket()
close();
}
+bool TcpSocket::isValid()
+{
+ return m_sock != INVALID_SOCKET;
+}
+
ssize_t TcpSocket::recv(void* data, size_t size)
{
ssize_t ret = ::recv(m_sock, (char*)data, size, 0);
@@ -167,7 +172,7 @@ TcpSocket TcpSocket::accept()
}
}
-boost::optional<TcpSocket> TcpSocket::accept(int timeout_ms)
+TcpSocket TcpSocket::accept(int timeout_ms)
{
struct pollfd fds[1];
fds[0].fd = m_sock;
@@ -184,7 +189,8 @@ boost::optional<TcpSocket> TcpSocket::accept(int timeout_ms)
return accept();
}
else {
- return boost::none;
+ TcpSocket invalidsock(0, "");
+ return invalidsock;
}
}
diff --git a/src/TcpSocket.h b/src/TcpSocket.h
index 8df913f..660515d 100644
--- a/src/TcpSocket.h
+++ b/src/TcpSocket.h
@@ -46,7 +46,7 @@
#include <iostream>
#include <string>
-#include <boost/optional.hpp>
+#include <memory>
/**
* This class represents a TCP socket.
@@ -70,7 +70,9 @@ class TcpSocket
TcpSocket(const TcpSocket& other) = delete;
TcpSocket& operator=(const TcpSocket& other) = delete;
- int close();
+ bool isValid(void);
+
+ int close(void);
/** Send data over the TCP connection.
* @param data The buffer that will be sent.
@@ -88,7 +90,12 @@ class TcpSocket
void listen(void);
TcpSocket accept(void);
- boost::optional<TcpSocket> accept(int timeout_ms);
+
+ /* Returns either valid socket if a connection was
+ * accepted before the timeout expired, or an invalid
+ * socket otherwise.
+ */
+ TcpSocket accept(int timeout_ms);
/** Retrieve address this socket is bound to */
InetAddress getOwnAddress() const;
diff --git a/src/dabOutput/dabOutputTcp.cpp b/src/dabOutput/dabOutputTcp.cpp
index 94d379e..975fdff 100644
--- a/src/dabOutput/dabOutputTcp.cpp
+++ b/src/dabOutput/dabOutputTcp.cpp
@@ -133,9 +133,9 @@ class TCPDataDispatcher
while (m_running) {
// Add a new TCPConnection to the list, constructing it from the client socket
- auto optional_sock = m_listener_socket.accept(timeout_ms);
- if (optional_sock) {
- m_connections.emplace(m_connections.begin(), std::move(*optional_sock));
+ auto sock = m_listener_socket.accept(timeout_ms);
+ if (sock.isValid()) {
+ m_connections.emplace(m_connections.begin(), move(sock));
}
}
}