OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 17 matching lines...) Expand all Loading... | |
28 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 28 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
29 ReadCompletionCallback; | 29 ReadCompletionCallback; |
30 typedef base::Callback< | 30 typedef base::Callback< |
31 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> | 31 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> |
32 RecvFromCompletionCallback; | 32 RecvFromCompletionCallback; |
33 | 33 |
34 // A Socket wraps a low-level socket and includes housekeeping information that | 34 // A Socket wraps a low-level socket and includes housekeeping information that |
35 // we need to manage it in the context of an extension. | 35 // we need to manage it in the context of an extension. |
36 class Socket : public ApiResource { | 36 class Socket : public ApiResource { |
37 public: | 37 public: |
38 enum SocketType { | |
39 TYPE_TCP, | |
40 TYPE_UDP, | |
41 }; | |
42 | |
38 virtual ~Socket(); | 43 virtual ~Socket(); |
39 virtual void Connect(const std::string& address, | 44 virtual void Connect(const std::string& address, |
40 int port, | 45 int port, |
41 const CompletionCallback& callback) = 0; | 46 const CompletionCallback& callback) = 0; |
42 virtual void Disconnect() = 0; | 47 virtual void Disconnect() = 0; |
43 virtual int Bind(const std::string& address, int port) = 0; | 48 virtual int Bind(const std::string& address, int port) = 0; |
44 | 49 |
45 // The |callback| will be called with the number of bytes read into the | 50 // The |callback| will be called with the number of bytes read into the |
46 // buffer, or a negative number if an error occurred. | 51 // buffer, or a negative number if an error occurred. |
47 virtual void Read(int count, | 52 virtual void Read(int count, |
(...skipping 10 matching lines...) Expand all Loading... | |
58 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 63 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
59 int byte_count, | 64 int byte_count, |
60 const std::string& address, | 65 const std::string& address, |
61 int port, | 66 int port, |
62 const CompletionCallback& callback) = 0; | 67 const CompletionCallback& callback) = 0; |
63 | 68 |
64 virtual bool SetKeepAlive(bool enable, int delay); | 69 virtual bool SetKeepAlive(bool enable, int delay); |
65 virtual bool SetNoDelay(bool no_delay); | 70 virtual bool SetNoDelay(bool no_delay); |
66 | 71 |
67 bool IsConnected(); | 72 bool IsConnected(); |
68 virtual bool IsTCPSocket() = 0; | |
69 | 73 |
70 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; | 74 virtual bool GetPeerAddress(net::IPEndPoint* address) = 0; |
71 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; | 75 virtual bool GetLocalAddress(net::IPEndPoint* address) = 0; |
72 | 76 |
77 virtual SocketType socket_type() const = 0; | |
Mihai Parparita -not on Chrome
2012/08/14 00:53:09
I believe that per the style guide, hacker_style n
Peng
2012/08/14 17:43:31
Done.
| |
78 | |
73 static bool StringAndPortToAddressList(const std::string& ip_address_str, | 79 static bool StringAndPortToAddressList(const std::string& ip_address_str, |
74 int port, | 80 int port, |
75 net::AddressList* address_list); | 81 net::AddressList* address_list); |
76 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, | 82 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, |
77 int port, | 83 int port, |
78 net::IPEndPoint* ip_end_point); | 84 net::IPEndPoint* ip_end_point); |
79 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, | 85 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, |
80 std::string* ip_address_str, | 86 std::string* ip_address_str, |
81 int* port); | 87 int* port); |
82 | 88 |
(...skipping 25 matching lines...) Expand all Loading... | |
108 CompletionCallback callback; | 114 CompletionCallback callback; |
109 int bytes_written; | 115 int bytes_written; |
110 }; | 116 }; |
111 std::queue<WriteRequest> write_queue_; | 117 std::queue<WriteRequest> write_queue_; |
112 scoped_refptr<net::IOBuffer> io_buffer_write_; | 118 scoped_refptr<net::IOBuffer> io_buffer_write_; |
113 }; | 119 }; |
114 | 120 |
115 } // namespace extensions | 121 } // namespace extensions |
116 | 122 |
117 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 123 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
OLD | NEW |