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_UDP_SOCKET_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/hash_tables.h" | |
10 #include "chrome/browser/extensions/api/socket/socket.h" | 11 #include "chrome/browser/extensions/api/socket/socket.h" |
11 #include "net/udp/udp_socket.h" | 12 #include "net/udp/udp_socket.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 class UDPSocket : public Socket { | 16 class UDPSocket : public Socket { |
16 public: | 17 public: |
17 explicit UDPSocket(const std::string& owner_extension_id); | 18 explicit UDPSocket(const std::string& owner_extension_id); |
18 virtual ~UDPSocket(); | 19 virtual ~UDPSocket(); |
19 | 20 |
20 virtual void Connect(const std::string& address, | 21 virtual void Connect(const std::string& address, |
21 int port, | 22 int port, |
22 const CompletionCallback& callback) OVERRIDE; | 23 const CompletionCallback& callback) OVERRIDE; |
23 virtual void Disconnect() OVERRIDE; | 24 virtual void Disconnect() OVERRIDE; |
24 virtual int Bind(const std::string& address, int port) OVERRIDE; | 25 virtual int Bind(const std::string& address, int port) OVERRIDE; |
25 virtual void Read(int count, | 26 virtual void Read(int count, |
26 const ReadCompletionCallback& callback) OVERRIDE; | 27 const ReadCompletionCallback& callback) OVERRIDE; |
27 virtual void RecvFrom(int count, | 28 virtual void RecvFrom(int count, |
28 const RecvFromCompletionCallback& callback) OVERRIDE; | 29 const RecvFromCompletionCallback& callback) OVERRIDE; |
29 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, | 30 virtual void SendTo(scoped_refptr<net::IOBuffer> io_buffer, |
30 int byte_count, | 31 int byte_count, |
31 const std::string& address, | 32 const std::string& address, |
32 int port, | 33 int port, |
33 const CompletionCallback& callback) OVERRIDE; | 34 const CompletionCallback& callback) OVERRIDE; |
34 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; | 35 virtual bool GetPeerAddress(net::IPEndPoint* address) OVERRIDE; |
35 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; | 36 virtual bool GetLocalAddress(net::IPEndPoint* address) OVERRIDE; |
36 virtual Socket::SocketType GetSocketType() const OVERRIDE; | 37 virtual Socket::SocketType GetSocketType() const OVERRIDE; |
37 | 38 |
39 int JoinGroup(const std::string& address); | |
40 int LeaveGroup(const std::string& address); | |
41 | |
42 int SetMulticastTimeToLive(int ttl); | |
43 int SetMulticastLoopbackMode(bool loopback); | |
44 | |
45 int GetJoinedGroups(base::hash_set<std::string>* groups) const; | |
46 | |
38 protected: | 47 protected: |
39 virtual int WriteImpl(net::IOBuffer* io_buffer, | 48 virtual int WriteImpl(net::IOBuffer* io_buffer, |
40 int io_buffer_size, | 49 int io_buffer_size, |
41 const net::CompletionCallback& callback) OVERRIDE; | 50 const net::CompletionCallback& callback) OVERRIDE; |
42 | 51 |
43 private: | 52 private: |
44 // Make net::IPEndPoint can be refcounted | 53 // Make net::IPEndPoint can be refcounted |
45 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; | 54 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; |
46 | 55 |
47 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, | 56 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, |
48 int result); | 57 int result); |
49 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, | 58 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, |
50 scoped_refptr<IPEndPoint> address, | 59 scoped_refptr<IPEndPoint> address, |
51 int result); | 60 int result); |
52 void OnSendToComplete(int result); | 61 void OnSendToComplete(int result); |
53 | 62 |
54 net::UDPSocket socket_; | 63 net::UDPSocket socket_; |
55 | 64 |
56 ReadCompletionCallback read_callback_; | 65 ReadCompletionCallback read_callback_; |
57 | 66 |
58 RecvFromCompletionCallback recv_from_callback_; | 67 RecvFromCompletionCallback recv_from_callback_; |
59 | 68 |
60 CompletionCallback send_to_callback_; | 69 CompletionCallback send_to_callback_; |
70 | |
71 base::hash_set<std::string> multicast_groups_; | |
miket_OOO
2013/04/25 21:52:12
Why a hash_set and not a set?
Bei Zhang
2013/04/25 23:56:21
hash set is faster for strings. A vector would be
| |
61 }; | 72 }; |
62 | 73 |
63 } // namespace extensions | 74 } // namespace extensions |
64 | 75 |
65 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ | 76 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_UDP_SOCKET_H_ |
OLD | NEW |