OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 NET_DNS_MDNS_CLIENT_IMPL_H_ | 5 #ifndef NET_DNS_MDNS_CLIENT_IMPL_H_ |
6 #define NET_DNS_MDNS_CLIENT_IMPL_H_ | 6 #define NET_DNS_MDNS_CLIENT_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 virtual void HandlePacket(DnsResponse* response, int bytes_read) = 0; | 45 virtual void HandlePacket(DnsResponse* response, int bytes_read) = 0; |
46 virtual void OnConnectionError(int error) = 0; | 46 virtual void OnConnectionError(int error) = 0; |
47 virtual ~Delegate() {} | 47 virtual ~Delegate() {} |
48 }; | 48 }; |
49 | 49 |
50 explicit MDnsConnection(MDnsConnection::Delegate* delegate); | 50 explicit MDnsConnection(MDnsConnection::Delegate* delegate); |
51 virtual ~MDnsConnection(); | 51 virtual ~MDnsConnection(); |
52 | 52 |
53 // Both methods return true if at least one of the socket handlers succeeded. | 53 // Both methods return true if at least one of the socket handlers succeeded. |
54 bool Init(MDnsSocketFactory* socket_factory); | 54 bool Init(MDnsSocketFactory* socket_factory); |
55 bool Send(IOBuffer* buffer, unsigned size); | 55 bool Send(const scoped_refptr<IOBufferWithSize>& buffer); |
56 | 56 |
57 private: | 57 private: |
58 class SocketHandler { | 58 class SocketHandler { |
59 public: | 59 public: |
60 SocketHandler(scoped_ptr<DatagramServerSocket> socket, | 60 SocketHandler(scoped_ptr<DatagramServerSocket> socket, |
61 MDnsConnection* connection); | 61 MDnsConnection* connection); |
62 ~SocketHandler(); | 62 ~SocketHandler(); |
63 | 63 |
64 int Start(); | 64 int Start(); |
65 int Send(IOBuffer* buffer, unsigned size); | 65 int Send(const scoped_refptr<IOBufferWithSize>& buffer); |
66 | 66 |
67 private: | 67 private: |
68 int DoLoop(int rv); | 68 int DoLoop(int rv); |
69 void OnDatagramReceived(int rv); | 69 void OnDatagramReceived(int rv); |
70 | 70 |
71 // Callback for when sending a query has finished. | 71 // Callback for when sending a query has finished. |
72 void SendDone(int rv); | 72 void SendDone(int rv); |
73 | 73 |
74 scoped_ptr<DatagramServerSocket> socket_; | 74 scoped_ptr<DatagramServerSocket> socket_; |
75 MDnsConnection* connection_; | 75 MDnsConnection* connection_; |
76 IPEndPoint recv_addr_; | 76 IPEndPoint recv_addr_; |
77 DnsResponse response_; | 77 DnsResponse response_; |
78 IPEndPoint multicast_addr_; | 78 IPEndPoint multicast_addr_; |
| 79 bool send_in_progress_; |
| 80 std::queue<scoped_refptr<IOBufferWithSize> > send_queue_; |
79 | 81 |
80 DISALLOW_COPY_AND_ASSIGN(SocketHandler); | 82 DISALLOW_COPY_AND_ASSIGN(SocketHandler); |
81 }; | 83 }; |
82 | 84 |
83 // Callback for handling a datagram being received on either ipv4 or ipv6. | 85 // Callback for handling a datagram being received on either ipv4 or ipv6. |
84 void OnDatagramReceived(DnsResponse* response, | 86 void OnDatagramReceived(DnsResponse* response, |
85 const IPEndPoint& recv_addr, | 87 const IPEndPoint& recv_addr, |
86 int bytes_read); | 88 int bytes_read); |
87 | 89 |
88 void OnError(SocketHandler* loop, int error); | 90 void OnError(SocketHandler* loop, int error); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 MDnsClientImpl* client_; | 298 MDnsClientImpl* client_; |
297 | 299 |
298 bool started_; | 300 bool started_; |
299 int flags_; | 301 int flags_; |
300 | 302 |
301 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); | 303 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); |
302 }; | 304 }; |
303 | 305 |
304 } // namespace net | 306 } // namespace net |
305 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ | 307 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ |
OLD | NEW |