Chromium Code Reviews| Index: net/base/address_tracker_linux.h |
| diff --git a/net/base/address_tracker_linux.h b/net/base/address_tracker_linux.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fcd4fc47eeb1f75258d319c500bf94e153540ead |
| --- /dev/null |
| +++ b/net/base/address_tracker_linux.h |
| @@ -0,0 +1,59 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_BASE_ADDRESS_TRACKER_LINUX_H_ |
| +#define NET_BASE_ADDRESS_TRACKER_LINUX_H_ |
| +#pragma once |
| + |
| +#include <sys/socket.h> // Needed to include netlink. |
| +// Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38. |
| +#define net net_kernel |
| +#include <linux/rtnetlink.h> |
| +#undef net |
| + |
| +#include <map> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/message_loop.h" |
| +#include "base/synchronization/lock.h" |
| +#include "net/base/net_util.h" |
| + |
| +namespace net { |
| +namespace internal { |
| + |
| +// Keeps track of network interface addresses using rtnetlink. Used by |
| +// NetworkChangeNotifier to provide signals to registered IPAddressObservers. |
| +class AddressTrackerLinux : public MessageLoopForIO::Watcher { |
| + public: |
| + typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap; |
| + |
| + AddressTrackerLinux(); |
| + virtual ~AddressTrackerLinux(); |
| + |
| + // Starts watching system configuration for changes. The current thread must |
| + // have a MessageLoopForIO. The signals will be delivered directly to |
| + // the global NetworkChangeNotifier. |
| + void Init(); |
| + |
| + AddressMap GetMap() const; |
| + |
| + private: |
| + // Returns true if |map_| changed while reading messages. |
| + bool ReadMessages(); |
| + bool HandleMessage(char* buf, size_t len); |
| + // MessageLoopForIO::Watcher: |
| + virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
| + virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE; |
| + |
| + int netlink_fd_; |
| + MessageLoopForIO::FileDescriptorWatcher watcher_; |
| + |
| + 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
|
| + AddressMap map_; |
| +}; |
| + |
| +} // namespace internal |
| +} // namespace net |
| + |
| +#endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_ |