OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef EXPERIMENTAL_VISUAL_STUDIO_PLUGIN_SRC_RSP_PROXY_PROXY_SOCKET_H_ | |
6 #define EXPERIMENTAL_VISUAL_STUDIO_PLUGIN_SRC_RSP_PROXY_PROXY_SOCKET_H_ | |
7 | |
8 #include <winsock.h> | |
9 #include <string> | |
10 | |
11 namespace debug { | |
12 | |
13 // Implements a listening socket. | |
14 // Example: | |
15 // ListeningSocket lsn; | |
16 // lsn.Setup(4014); | |
17 // Socket conn; | |
18 // if (lsn.Accept(&conn, 200)) | |
19 // DoSomethingWithNewConnection(conn); | |
20 | |
21 class Socket; | |
22 class ListeningSocket { | |
23 public: | |
24 ListeningSocket(); | |
25 ~ListeningSocket(); | |
26 | |
27 bool Setup(int port); // Listens on port. | |
28 bool Accept(Socket* new_connection, int wait_ms); | |
29 void Close(); | |
30 | |
31 private: | |
32 SOCKET sock_; | |
33 bool init_success_; | |
34 }; | |
35 | |
36 // Implements a raw socket interface. | |
37 // Example: | |
38 // Socket conn; | |
39 // if (conn.ConnectTo("172.29.20.175", 4016)) | |
40 // DoSomethingWithNewConnection(conn); | |
41 | |
42 class Socket { | |
43 public: | |
44 Socket(); | |
45 ~Socket(); | |
46 | |
47 bool ConnectTo(const std::string& host, int port); | |
48 bool IsConnected() const; | |
49 void Close(); | |
50 size_t Read(void* buff, size_t sz, int wait_ms); | |
51 size_t Write(const void* buff, size_t sz, int wait_ms); | |
52 void WriteAll(const void* buff, size_t sz); | |
53 | |
54 private: | |
55 void AttachTo(SOCKET sock); | |
56 | |
57 SOCKET sock_; | |
58 bool init_success_; | |
59 friend class ListeningSocket; | |
60 }; | |
61 } // namespace debug | |
62 #endif // EXPERIMENTAL_VISUAL_STUDIO_PLUGIN_SRC_RSP_PROXY_PROXY_SOCKET_H_ | |
63 | |
64 | |
OLD | NEW |