fastboot: socket testing improvements.
(This code was originally part of a huge fastboot CL but has been split
out to try to make the CLs a little more manageable).
More prep for fastboot TCP and UDP implementations. This CL adds a
SocketMock class that makes it easy to mock out network behavior so we
can unit test the TCP and UDP protocols.
Also uses the new libcutils socket_get_local_port() to avoid hardcoding
a server port in unit tests.
Bug: http://b/26157893.
Change-Id: I1ba10f31e98d7349313fc15f240383d63378a8db
diff --git a/fastboot/socket.h b/fastboot/socket.h
index 3e66c27..a7481db 100644
--- a/fastboot/socket.h
+++ b/fastboot/socket.h
@@ -44,6 +44,10 @@
public:
enum class Protocol { kTcp, kUdp };
+ // Returns the socket error message. This must be called immediately after a socket failure
+ // before any other system calls are made.
+ static std::string GetErrorMessage();
+
// Creates a new client connection. Clients are connected to a specific hostname/port and can
// only send to that destination.
// On failure, |error| is filled (if non-null) and nullptr is returned.
@@ -78,6 +82,9 @@
// connected to the client on success, nullptr on failure.
virtual std::unique_ptr<Socket> Accept() { return nullptr; }
+ // Returns the local port the Socket is bound to or -1 on error.
+ int GetLocalPort();
+
protected:
// Protected constructor to force factory function use.
Socket(cutils_socket_t sock);