Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: chrome/browser/extensions/api/socket/tcp_socket.h

Issue 10827390: Implement chrome.socket.bind/listen/accept for TCP server socket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_TCP_SOCKET_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/extensions/api/socket/socket.h" 10 #include "chrome/browser/extensions/api/socket/socket.h"
11 11
12 // This looks like it should be forward-declarable, but it does some tricky 12 // This looks like it should be forward-declarable, but it does some tricky
13 // moves that make it easier to just include it. 13 // moves that make it easier to just include it.
14 #include "net/socket/tcp_client_socket.h" 14 #include "net/socket/tcp_client_socket.h"
15 #include "net/socket/tcp_server_socket.h"
15 16
16 namespace net { 17 namespace net {
17 class Socket; 18 class Socket;
18 } 19 }
19 20
20 namespace extensions { 21 namespace extensions {
21 22
22 class ApiResourceEventNotifier; 23 class ApiResourceEventNotifier;
23 24
24 class TCPSocket : public Socket { 25 class TCPSocket : public Socket {
25 public: 26 public:
26 explicit TCPSocket(ApiResourceEventNotifier* event_notifier); 27 explicit TCPSocket(ApiResourceEventNotifier* event_notifier);
28 explicit TCPSocket(ApiResourceEventNotifier* event_notifier,
29 net::TCPClientSocket* client_socket);
27 virtual ~TCPSocket(); 30 virtual ~TCPSocket();
28 31
29 virtual void Connect(const std::string& address, 32 virtual void Connect(const std::string& address,
30 int port, 33 int port,
31 const CompletionCallback& callback) OVERRIDE; 34 const CompletionCallback& callback) OVERRIDE;
32 virtual void Disconnect() OVERRIDE; 35 virtual void Disconnect() OVERRIDE;
33 virtual int Bind(const std::string& address, int port) OVERRIDE; 36 virtual int Bind(const std::string& address, int port) OVERRIDE;
34 virtual void Read(int count, 37 virtual void Read(int count,
35 const ReadCompletionCallback& callback) OVERRIDE; 38 const ReadCompletionCallback& callback) OVERRIDE;
36 virtual void RecvFrom(int count, 39 virtual void RecvFrom(int count,
37 const RecvFromCompletionCallback& callback) OVERRIDE; 40 const RecvFromCompletionCallback& callback) OVERRIDE;
38 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, 41 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
39 int byte_count, 42 int byte_count,
40 const std::string& address, 43 const std::string& address,
41 int port, 44 int port,
42 const CompletionCallback& callback) OVERRIDE; 45 const CompletionCallback& callback) OVERRIDE;
43 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; 46 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
44 virtual bool SetNoDelay(bool no_delay) OVERRIDE; 47 virtual bool SetNoDelay(bool no_delay) OVERRIDE;
48 virtual bool Listen(int backlog) OVERRIDE;
49 virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE;
50
45 virtual bool IsTCPSocket() OVERRIDE; 51 virtual bool IsTCPSocket() OVERRIDE;
46 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; 52 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
47 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; 53 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
48 54
49 static TCPSocket* CreateSocketForTesting( 55 static TCPSocket* CreateSocketForTesting(
50 net::TCPClientSocket* tcp_client_socket, 56 net::TCPClientSocket* tcp_client_socket,
51 ApiResourceEventNotifier* event_notifier); 57 ApiResourceEventNotifier* event_notifier);
52 58
53 protected: 59 protected:
54 virtual int WriteImpl(net::IOBuffer* io_buffer, 60 virtual int WriteImpl(net::IOBuffer* io_buffer,
55 int io_buffer_size, 61 int io_buffer_size,
56 const net::CompletionCallback& callback) OVERRIDE; 62 const net::CompletionCallback& callback) OVERRIDE;
57 63
58 private: 64 private:
59 void OnConnectComplete(int result); 65 void OnConnectComplete(int result);
60 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, 66 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
61 int result); 67 int result);
68 void OnAccept(int result);
62 69
63 TCPSocket(net::TCPClientSocket* tcp_client_socket, 70 TCPSocket(net::TCPClientSocket* tcp_client_socket,
64 ApiResourceEventNotifier* event_notifier); 71 ApiResourceEventNotifier* event_notifier);
65 72
66 scoped_ptr<net::TCPClientSocket> socket_; 73 scoped_ptr<net::TCPClientSocket> socket_;
74 scoped_ptr<net::TCPServerSocket> server_socket_;
75 scoped_ptr<net::IPEndPoint> bind_address_;
76
77 bool is_client_socket_;
78 bool is_server_socket_;
67 79
68 CompletionCallback connect_callback_; 80 CompletionCallback connect_callback_;
69 81
70 ReadCompletionCallback read_callback_; 82 ReadCompletionCallback read_callback_;
83
84 scoped_ptr<net::StreamSocket> accept_socket_;
85 AcceptCompletionCallback accept_callback_;
71 }; 86 };
72 87
73 } // namespace extensions 88 } // namespace extensions
74 89
75 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 90 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698