Index: build_tools/debug_server/debug_server/common/debug_socket.h |
=================================================================== |
--- build_tools/debug_server/debug_server/common/debug_socket.h (revision 0) |
+++ build_tools/debug_server/debug_server/common/debug_socket.h (revision 0) |
@@ -0,0 +1,60 @@ |
+#ifndef NACL_SDK_BUILD_TOOLS_DEBUG_SERVER_COMMON_DEBUG_SOCKET_H_ |
+#define NACL_SDK_BUILD_TOOLS_DEBUG_SERVER_COMMON_DEBUG_SOCKET_H_ |
+ |
+#include <winsock.h> |
+#include <string> |
+#include "debug_blob.h" |
+ |
+namespace debug { |
+ |
+// Implements a listening socket. |
+// Example: |
+// ListeningSocket lsn; |
+// lsn.Setup(4014); |
+// Socket conn; |
+// if (lsn.Accept(&conn, 200)) |
+// DoSomethingWithNewConnection(conn); |
+ |
+class Socket; |
+class ListeningSocket { |
+ public: |
+ ListeningSocket(); |
+ ~ListeningSocket(); |
+ |
+ bool Setup(int port); // Listens on port. |
+ bool Accept(Socket* new_connection, long wait_ms); |
+ void Close(); |
+ |
+ protected: |
+ SOCKET sock_; |
+ bool init_success_; |
+}; |
+ |
+// Implements a raw socket interface. |
+// Example: |
+// Socket conn; |
+// if (conn.ConnectTo("172.29.20.175", 4016)) |
+// DoSomethingWithNewConnection(conn); |
+ |
+class Socket { |
+ public: |
+ Socket(); |
+ ~Socket(); |
+ |
+ bool ConnectTo(const std::string& host, int port); |
+ bool IsConnected() const; |
+ void Close(); |
+ size_t Read(void* buff, size_t sz, int wait_ms); |
+ size_t Write(const void* buff, size_t sz, int wait_ms); |
+ void WriteAll(const void* buff, size_t sz); |
+ void WriteAll(const Blob& blob); |
+ |
+ protected: |
+ void AttachTo(SOCKET sock); |
+ |
+ SOCKET sock_; |
+ bool init_success_; |
+ friend class ListeningSocket; |
+}; |
+} // namespace debug |
+#endif // NACL_SDK_BUILD_TOOLS_DEBUG_SERVER_COMMON_DEBUG_SOCKET_H_ |