summaryrefslogtreecommitdiff
path: root/fastboot/socket.cpp
diff options
context:
space:
mode:
authorDavid Pursell <dpursell@google.com>2016-01-29 08:10:50 -0800
committerDavid Pursell <dpursell@google.com>2016-02-02 11:29:10 -0800
commitc3a466960ff19bbf9b28b4d069dd0b872d4165d8 (patch)
tree97a3483c1c8cb5a57c82633723b9f8a84a2ab9cd /fastboot/socket.cpp
parentd95ecfc432206d5408738bb7cbc6eb15e5827d91 (diff)
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
Diffstat (limited to 'fastboot/socket.cpp')
-rw-r--r--fastboot/socket.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/fastboot/socket.cpp b/fastboot/socket.cpp
index d41f1fe6f..0a3ddfa2f 100644
--- a/fastboot/socket.cpp
+++ b/fastboot/socket.cpp
@@ -28,6 +28,7 @@
#include "socket.h"
+#include <android-base/errors.h>
#include <android-base/stringprintf.h>
Socket::Socket(cutils_socket_t sock) : sock_(sock) {}
@@ -77,6 +78,10 @@ ssize_t Socket::ReceiveAll(void* data, size_t length, int timeout_ms) {
return total;
}
+int Socket::GetLocalPort() {
+ return socket_get_local_port(sock_);
+}
+
// Implements the Socket interface for UDP.
class UdpSocket : public Socket {
public:
@@ -210,3 +215,12 @@ std::unique_ptr<Socket> Socket::NewServer(Protocol protocol, int port) {
return nullptr;
}
+
+std::string Socket::GetErrorMessage() {
+#if defined(_WIN32)
+ DWORD error_code = WSAGetLastError();
+#else
+ int error_code = errno;
+#endif
+ return android::base::SystemErrorCodeToString(error_code);
+}