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 16 matching lines...) Expand all Loading... |
27 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> | 27 typedef base::Callback<void(int, scoped_refptr<net::IOBuffer> io_buffer)> |
28 ReadCompletionCallback; | 28 ReadCompletionCallback; |
29 typedef base::Callback< | 29 typedef base::Callback< |
30 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> | 30 void(int, scoped_refptr<net::IOBuffer> io_buffer, const std::string&, int)> |
31 RecvFromCompletionCallback; | 31 RecvFromCompletionCallback; |
32 | 32 |
33 // A Socket wraps a low-level socket and includes housekeeping information that | 33 // A Socket wraps a low-level socket and includes housekeeping information that |
34 // we need to manage it in the context of an extension. | 34 // we need to manage it in the context of an extension. |
35 class Socket : public ApiResource { | 35 class Socket : public ApiResource { |
36 public: | 36 public: |
| 37 enum SocketType { |
| 38 TYPE_NONE = 0, |
| 39 TYPE_TCP, |
| 40 TYPE_UDP, |
| 41 }; |
| 42 |
37 virtual ~Socket(); | 43 virtual ~Socket(); |
38 virtual void Connect(const std::string& address, | 44 virtual void Connect(const std::string& address, |
39 int port, | 45 int port, |
40 const CompletionCallback& callback) = 0; | 46 const CompletionCallback& callback) = 0; |
41 virtual void Disconnect() = 0; | 47 virtual void Disconnect() = 0; |
42 virtual int Bind(const std::string& address, int port) = 0; | 48 virtual int Bind(const std::string& address, int port) = 0; |
43 | 49 |
44 // 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 |
45 // buffer, or a negative number if an error occurred. | 51 // buffer, or a negative number if an error occurred. |
46 virtual void Read(int count, | 52 virtual void Read(int count, |
47 const ReadCompletionCallback& callback) = 0; | 53 const ReadCompletionCallback& callback) = 0; |
48 | 54 |
49 // The |callback| will be called with |byte_count| or a negative number if an | 55 // The |callback| will be called with |byte_count| or a negative number if an |
50 // error occurred. | 56 // error occurred. |
51 void Write(scoped_refptr<net::IOBuffer> io_buffer, | 57 void Write(scoped_refptr<net::IOBuffer> io_buffer, |
52 int byte_count, | 58 int byte_count, |
53 const CompletionCallback& callback); | 59 const CompletionCallback& callback); |
54 | 60 |
55 virtual void RecvFrom(int count, | 61 virtual void RecvFrom(int count, |
56 const RecvFromCompletionCallback& callback) = 0; | 62 const RecvFromCompletionCallback& callback) = 0; |
57 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 63 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
58 int byte_count, | 64 int byte_count, |
59 const std::string& address, | 65 const std::string& address, |
60 int port, | 66 int port, |
61 const CompletionCallback& callback) = 0; | 67 const CompletionCallback& callback) = 0; |
62 | 68 |
63 virtual bool SetKeepAlive(bool enable, int delay); | 69 virtual bool SetKeepAlive(bool enable, int delay); |
64 virtual bool SetNoDelay(bool no_delay); | 70 virtual bool SetNoDelay(bool no_delay); |
65 | 71 |
| 72 virtual SocketType socket_type() const = 0; |
| 73 |
66 static bool StringAndPortToAddressList(const std::string& ip_address_str, | 74 static bool StringAndPortToAddressList(const std::string& ip_address_str, |
67 int port, | 75 int port, |
68 net::AddressList* address_list); | 76 net::AddressList* address_list); |
69 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, | 77 static bool StringAndPortToIPEndPoint(const std::string& ip_address_str, |
70 int port, | 78 int port, |
71 net::IPEndPoint* ip_end_point); | 79 net::IPEndPoint* ip_end_point); |
72 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, | 80 static void IPEndPointToStringAndPort(const net::IPEndPoint& address, |
73 std::string* ip_address_str, | 81 std::string* ip_address_str, |
74 int* port); | 82 int* port); |
75 | 83 |
(...skipping 25 matching lines...) Expand all Loading... |
101 CompletionCallback callback; | 109 CompletionCallback callback; |
102 int bytes_written; | 110 int bytes_written; |
103 }; | 111 }; |
104 std::queue<WriteRequest> write_queue_; | 112 std::queue<WriteRequest> write_queue_; |
105 scoped_refptr<net::IOBuffer> io_buffer_write_; | 113 scoped_refptr<net::IOBuffer> io_buffer_write_; |
106 }; | 114 }; |
107 | 115 |
108 } // namespace extensions | 116 } // namespace extensions |
109 | 117 |
110 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ | 118 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_H_ |
OLD | NEW |