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

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: Remove unrelated changes. Created 8 years, 3 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 TCPSocket(net::TCPClientSocket* tcp_client_socket,
29 ApiResourceEventNotifier* event_notifier,
30 bool is_connected = false);
31
27 virtual ~TCPSocket(); 32 virtual ~TCPSocket();
28 33
29 virtual void Connect(const std::string& address, 34 virtual void Connect(const std::string& address,
30 int port, 35 int port,
31 const CompletionCallback& callback) OVERRIDE; 36 const CompletionCallback& callback) OVERRIDE;
32 virtual void Disconnect() OVERRIDE; 37 virtual void Disconnect() OVERRIDE;
33 virtual int Bind(const std::string& address, int port) OVERRIDE; 38 virtual int Bind(const std::string& address, int port) OVERRIDE;
34 virtual void Read(int count, 39 virtual void Read(int count,
35 const ReadCompletionCallback& callback) OVERRIDE; 40 const ReadCompletionCallback& callback) OVERRIDE;
36 virtual void RecvFrom(int count, 41 virtual void RecvFrom(int count,
37 const RecvFromCompletionCallback& callback) OVERRIDE; 42 const RecvFromCompletionCallback& callback) OVERRIDE;
38 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, 43 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer,
39 int byte_count, 44 int byte_count,
40 const std::string& address, 45 const std::string& address,
41 int port, 46 int port,
42 const CompletionCallback& callback) OVERRIDE; 47 const CompletionCallback& callback) OVERRIDE;
43 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE; 48 virtual bool SetKeepAlive(bool enable, int delay) OVERRIDE;
44 virtual bool SetNoDelay(bool no_delay) OVERRIDE; 49 virtual bool SetNoDelay(bool no_delay) OVERRIDE;
50 virtual int Listen(int backlog, std::string& error_msg) OVERRIDE;
51 virtual void Accept(const AcceptCompletionCallback &callback) OVERRIDE;
52
45 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; 53 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE;
46 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; 54 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE;
47 virtual Socket::SocketType GetSocketType() const OVERRIDE; 55 virtual Socket::SocketType GetSocketType() const OVERRIDE;
48 56
49 static TCPSocket* CreateSocketForTesting( 57 static TCPSocket* CreateSocketForTesting(
50 net::TCPClientSocket* tcp_client_socket, 58 net::TCPClientSocket* tcp_client_socket,
51 ApiResourceEventNotifier* event_notifier); 59 ApiResourceEventNotifier* event_notifier);
60 static TCPSocket* CreateServerSocketForTesting(
61 net::TCPServerSocket* tcp_server_socket);
52 62
53 protected: 63 protected:
54 virtual int WriteImpl(net::IOBuffer* io_buffer, 64 virtual int WriteImpl(net::IOBuffer* io_buffer,
55 int io_buffer_size, 65 int io_buffer_size,
56 const net::CompletionCallback& callback) OVERRIDE; 66 const net::CompletionCallback& callback) OVERRIDE;
57 67
58 private: 68 private:
59 void OnConnectComplete(int result); 69 void OnConnectComplete(int result);
60 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, 70 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer,
61 int result); 71 int result);
72 void OnAccept(int result);
62 73
63 TCPSocket(net::TCPClientSocket* tcp_client_socket, 74 explicit TCPSocket(net::TCPServerSocket*);
64 ApiResourceEventNotifier* event_notifier);
65 75
66 scoped_ptr<net::TCPClientSocket> socket_; 76 scoped_ptr<net::TCPClientSocket> socket_;
77 scoped_ptr<net::TCPServerSocket> server_socket_;
78 scoped_ptr<net::IPEndPoint> bind_address_;
79
80 bool is_client_socket_;
81 bool is_server_socket_;
Peng 2012/09/11 14:01:18 Could we use one variable? Like int socket_mode_,
justinlin 2012/09/12 07:29:42 Done.
67 82
68 CompletionCallback connect_callback_; 83 CompletionCallback connect_callback_;
69 84
70 ReadCompletionCallback read_callback_; 85 ReadCompletionCallback read_callback_;
86
87 scoped_ptr<net::StreamSocket> accept_socket_;
88 AcceptCompletionCallback accept_callback_;
71 }; 89 };
72 90
73 } // namespace extensions 91 } // namespace extensions
74 92
75 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_ 93 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_TCP_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698