Chromium Code Reviews| 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 void Send(const scoped_refptr<IOBuffer>& buffer, unsigned size); |
|
Vitaly Buka (NO REVIEWS)
2014/09/22 22:53:49
swithing back to IOBuffer, because comment in IOBu
| |
| 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 void Send(const scoped_refptr<IOBuffer>& buffer, unsigned size); |
| 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<std::pair<scoped_refptr<IOBuffer>, unsigned> > 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 PostOnError(SocketHandler* loop, int rv); |
| 91 void OnError(int rv); | |
| 89 | 92 |
| 90 // Only socket handlers which successfully bound and started are kept. | 93 // Only socket handlers which successfully bound and started are kept. |
| 91 ScopedVector<SocketHandler> socket_handlers_; | 94 ScopedVector<SocketHandler> socket_handlers_; |
| 92 | 95 |
| 93 Delegate* delegate_; | 96 Delegate* delegate_; |
| 94 | 97 |
| 98 base::WeakPtrFactory<MDnsConnection> weak_ptr_factory_; | |
| 99 | |
| 95 DISALLOW_COPY_AND_ASSIGN(MDnsConnection); | 100 DISALLOW_COPY_AND_ASSIGN(MDnsConnection); |
| 96 }; | 101 }; |
| 97 | 102 |
| 98 class MDnsListenerImpl; | 103 class MDnsListenerImpl; |
| 99 | 104 |
| 100 class NET_EXPORT_PRIVATE MDnsClientImpl : public MDnsClient { | 105 class NET_EXPORT_PRIVATE MDnsClientImpl : public MDnsClient { |
| 101 public: | 106 public: |
| 102 // The core object exists while the MDnsClient is listening, and is deleted | 107 // The core object exists while the MDnsClient is listening, and is deleted |
| 103 // whenever the number of listeners reaches zero. The deletion happens | 108 // whenever the number of listeners reaches zero. The deletion happens |
| 104 // asychronously, so destroying the last listener does not immediately | 109 // asychronously, so destroying the last listener does not immediately |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 MDnsClientImpl* client_; | 301 MDnsClientImpl* client_; |
| 297 | 302 |
| 298 bool started_; | 303 bool started_; |
| 299 int flags_; | 304 int flags_; |
| 300 | 305 |
| 301 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); | 306 DISALLOW_COPY_AND_ASSIGN(MDnsTransactionImpl); |
| 302 }; | 307 }; |
| 303 | 308 |
| 304 } // namespace net | 309 } // namespace net |
| 305 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ | 310 #endif // NET_DNS_MDNS_CLIENT_IMPL_H_ |
| OLD | NEW |