Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_ADDRESS_TRACKER_LINUX_H_ | |
| 6 #define NET_BASE_ADDRESS_TRACKER_LINUX_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <sys/socket.h> // Needed to include netlink. | |
| 10 // Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38. | |
| 11 #define net net_kernel | |
| 12 #include <linux/rtnetlink.h> | |
| 13 #undef net | |
| 14 | |
| 15 #include <map> | |
| 16 | |
| 17 #include "base/basictypes.h" | |
| 18 #include "base/message_loop.h" | |
| 19 #include "base/synchronization/lock.h" | |
| 20 #include "net/base/net_util.h" | |
| 21 | |
| 22 namespace net { | |
| 23 namespace internal { | |
| 24 | |
| 25 // Keeps track of network interface addresses using rtnetlink. Used by | |
| 26 // NetworkChangeNotifier to provide signals to registered IPAddressObservers. | |
| 27 class AddressTrackerLinux : public MessageLoopForIO::Watcher { | |
| 28 public: | |
| 29 typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap; | |
| 30 | |
| 31 AddressTrackerLinux(); | |
| 32 virtual ~AddressTrackerLinux(); | |
| 33 | |
| 34 // Starts watching system configuration for changes. The current thread must | |
| 35 // have a MessageLoopForIO. The signals will be delivered directly to | |
| 36 // the global NetworkChangeNotifier. | |
| 37 void Init(); | |
| 38 | |
| 39 AddressMap GetMap() const; | |
| 40 | |
| 41 private: | |
| 42 // Returns true if |map_| changed while reading messages. | |
| 43 bool ReadMessages(); | |
| 44 bool HandleMessage(char* buf, size_t len); | |
| 45 // MessageLoopForIO::Watcher: | |
| 46 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | |
| 47 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE; | |
| 48 | |
| 49 int netlink_fd_; | |
| 50 MessageLoopForIO::FileDescriptorWatcher watcher_; | |
| 51 | |
| 52 mutable base::Lock lock_; | |
|
willchan no longer on Chromium
2012/06/29 01:53:41
Why is the lock necessary? What threads are access
szym
2012/06/29 03:06:09
AddressTrackerLinux will live on the NetworkChange
| |
| 53 AddressMap map_; | |
| 54 }; | |
| 55 | |
| 56 } // namespace internal | |
| 57 } // namespace net | |
| 58 | |
| 59 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ | |
| OLD | NEW |