TcpSocket: Modify existing code for TcpConnectionWaiter
In order for TcpConnections to be initialized on posix systems, we need
to use accept, as documented here:
http://man7.org/linux/man-pages/man2/accept.2.html
Accept uses a polling mechanism, similar to UdpSocket Reads.
Additionally, according to the above documentation, we can use Select to
check if the socket is ready to connect, as documented here:
http://man7.org/linux/man-pages/man2/select.2.html
Because this same mechanism is already used for UdpSocket Reads in the
NetworkReader (via the NetworkWaiter class), we can repurpose the
existing NetworkWaiter to work for both its current NetworkReader use
and a new TcpConnectionWaiter class (in the next CL)
To do so, we need to make the NetworkWaiter work on fds instead of
UdpSocket objects. This CL accomplishes that change.
Change-Id: I69cab5ea9e94ece7016da52b2723ec7bf47a6196
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/1790368
Commit-Queue: Ryan Keane <rwkeane@google.com>
Reviewed-by: Max Yakimakha <yakimakha@chromium.org>
diff --git a/platform/impl/stream_socket.h b/platform/impl/stream_socket.h
index 21cd727..83e3586 100644
--- a/platform/impl/stream_socket.h
+++ b/platform/impl/stream_socket.h
@@ -10,6 +10,7 @@
#include <string>
#include "platform/api/network_interface.h"
+#include "platform/api/socket_handle.h"
#include "platform/base/error.h"
#include "platform/base/ip_address.h"
#include "platform/base/macros.h"
@@ -18,8 +19,6 @@
namespace openscreen {
namespace platform {
-struct FileDescriptor;
-
// StreamSocket is an incomplete abstraction of synchronous platform methods for
// creating, initializing, and closing stream sockets. Callers can use this
// class to define complete TCP and TLS socket classes, both synchronous and
@@ -48,7 +47,7 @@
virtual Error Listen(int max_backlog_size) = 0;
// Returns the file descriptor (e.g. fd or HANDLE pointer) for this socket.
- virtual FileDescriptor file_descriptor() const = 0;
+ virtual SocketHandle socket_handle() const = 0;
// Returns the connected remote address, if socket is connected.
virtual absl::optional<IPEndpoint> remote_address() const = 0;