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

Side by Side Diff: net/base/address_tracker_linux.h

Issue 10689015: [net] Adds AddressTrackerLinux which keeps track of interface addresses using rtnetlink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renamed GetMap to GetAddressMap. Fixed nits. Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
8 #include <sys/socket.h> // Needed to include netlink.
9 // Mask superfluous definition of |struct net|. This is fixed in Linux 2.6.38.
10 #define net net_kernel
11 #include <linux/rtnetlink.h>
12 #undef net
13
14 #include <map>
15
16 #include "base/basictypes.h"
17 #include "base/callback.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 // Will run |callback| when the AddressMap changes.
32 explicit AddressTrackerLinux(const base::Closure& callback);
33 virtual ~AddressTrackerLinux();
34
35 // Starts watching system configuration for changes. The current thread must
36 // have a MessageLoopForIO.
37 void Init();
38
39 AddressMap GetAddressMap() const;
40
41 private:
42 friend class AddressTrackerLinuxTest;
43
44 // Returns true if |map_| changed while reading the message from |buffer|.
45 bool HandleMessage(const char* buffer, size_t length);
vandebo (ex-Chrome) 2012/07/12 19:05:09 Declaration order and implantation order should ma
46
47 // Returns true if |map_| changed while reading messages from |netlink_fd_|.
48 bool ReadMessages();
49
50 // MessageLoopForIO::Watcher:
51 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
52 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
53
54 base::Closure callback_;
55
56 int netlink_fd_;
57 MessageLoopForIO::FileDescriptorWatcher watcher_;
58
59 mutable base::Lock lock_;
60 AddressMap map_;
61 };
62
63 } // namespace internal
64 } // namespace net
65
66 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698