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

Side by Side Diff: extensions/browser/api/socket/udp_socket.h

Issue 2378763003: Add ability to reuse address in chrome.sockets.udp
Patch Set: Respond to code reviews, clean up tests Created 4 years, 2 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
« no previous file with comments | « no previous file | extensions/browser/api/socket/udp_socket.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_
6 #define EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ 6 #define EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 int JoinGroup(const std::string& address); 42 int JoinGroup(const std::string& address);
43 int LeaveGroup(const std::string& address); 43 int LeaveGroup(const std::string& address);
44 44
45 int SetMulticastTimeToLive(int ttl); 45 int SetMulticastTimeToLive(int ttl);
46 int SetMulticastLoopbackMode(bool loopback); 46 int SetMulticastLoopbackMode(bool loopback);
47 47
48 int SetBroadcast(bool enabled); 48 int SetBroadcast(bool enabled);
49 49
50 const std::vector<std::string>& GetJoinedGroups() const; 50 const std::vector<std::string>& GetJoinedGroups() const;
51 51
52 bool allow_address_reuse() const { return allow_address_reuse_; }
53 void set_allow_address_reuse(bool allow) { allow_address_reuse_ = allow; }
54
52 protected: 55 protected:
53 int WriteImpl(net::IOBuffer* io_buffer, 56 int WriteImpl(net::IOBuffer* io_buffer,
54 int io_buffer_size, 57 int io_buffer_size,
55 const net::CompletionCallback& callback) override; 58 const net::CompletionCallback& callback) override;
56 59
57 private: 60 private:
58 // Make net::IPEndPoint can be refcounted 61 // Make net::IPEndPoint can be refcounted
59 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint; 62 typedef base::RefCountedData<net::IPEndPoint> IPEndPoint;
60 63
61 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result); 64 void OnReadComplete(scoped_refptr<net::IOBuffer> io_buffer, int result);
62 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer, 65 void OnRecvFromComplete(scoped_refptr<net::IOBuffer> io_buffer,
63 scoped_refptr<IPEndPoint> address, 66 scoped_refptr<IPEndPoint> address,
64 int result); 67 int result);
65 void OnSendToComplete(int result); 68 void OnSendToComplete(int result);
66 69
67 net::UDPSocket socket_; 70 net::UDPSocket socket_;
68 71
69 ReadCompletionCallback read_callback_; 72 ReadCompletionCallback read_callback_;
70 73
71 RecvFromCompletionCallback recv_from_callback_; 74 RecvFromCompletionCallback recv_from_callback_;
72 75
73 CompletionCallback send_to_callback_; 76 CompletionCallback send_to_callback_;
74 77
75 std::vector<std::string> multicast_groups_; 78 std::vector<std::string> multicast_groups_;
79
80 // Flag indicating whether the address can be bound by multiple sockets - see
81 // sockets_udp.idl
82 bool allow_address_reuse_;
76 }; 83 };
77 84
78 // UDP Socket instances from the "sockets.udp" namespace. These are regular 85 // UDP Socket instances from the "sockets.udp" namespace. These are regular
79 // socket objects with additional properties related to the behavior defined in 86 // socket objects with additional properties related to the behavior defined in
80 // the "sockets.udp" namespace. 87 // the "sockets.udp" namespace.
81 class ResumableUDPSocket : public UDPSocket { 88 class ResumableUDPSocket : public UDPSocket {
82 public: 89 public:
83 explicit ResumableUDPSocket(const std::string& owner_extension_id); 90 explicit ResumableUDPSocket(const std::string& owner_extension_id);
84 91
85 // Overriden from ApiResource 92 // Overriden from ApiResource
(...skipping 23 matching lines...) Expand all
109 // The size of the buffer used to receive data - see sockets_udp.idl. 116 // The size of the buffer used to receive data - see sockets_udp.idl.
110 int buffer_size_; 117 int buffer_size_;
111 // Flag indicating whether a connected socket blocks its peer from sending 118 // Flag indicating whether a connected socket blocks its peer from sending
112 // more data - see sockets_udp.idl. 119 // more data - see sockets_udp.idl.
113 bool paused_; 120 bool paused_;
114 }; 121 };
115 122
116 } // namespace extensions 123 } // namespace extensions
117 124
118 #endif // EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_ 125 #endif // EXTENSIONS_BROWSER_API_SOCKET_UDP_SOCKET_H_
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/socket/udp_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698