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

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: Responded to vandebo's review. 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') | net/base/address_tracker_linux.cc » ('J')
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 #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/callback.h"
19 #include "base/message_loop.h"
20 #include "base/synchronization/lock.h"
21 #include "net/base/net_util.h"
22
23 namespace net {
24 namespace internal {
25
26 // Keeps track of network interface addresses using rtnetlink. Used by
27 // NetworkChangeNotifier to provide signals to registered IPAddressObservers.
28 class AddressTrackerLinux : public MessageLoopForIO::Watcher {
29 public:
30 typedef std::map<IPAddressNumber, struct ifaddrmsg> AddressMap;
31
32 // Will run |callback| when the AddressMap changes.
33 AddressTrackerLinux(const base::Closure& callback);
vandebo (ex-Chrome) 2012/06/29 21:01:18 explicit
34 virtual ~AddressTrackerLinux();
35
36 // Starts watching system configuration for changes. The current thread must
37 // have a MessageLoopForIO. The signals will be delivered directly to
38 // the global NetworkChangeNotifier.
39 void Init();
40
41 AddressMap GetMap() const;
42
43 private:
44 // Returns true if |map_| changed while reading messages.
45 bool ReadMessages();
46 bool HandleMessage(char* buf, size_t len);
47
48 // MessageLoopForIO::Watcher:
49 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
50 virtual void OnFileCanWriteWithoutBlocking(int /* fd */) OVERRIDE;
51
52 base::Closure callback_;
53
54 int netlink_fd_;
55 MessageLoopForIO::FileDescriptorWatcher watcher_;
56
57 mutable base::Lock lock_;
58 AddressMap map_;
59 };
60
61 } // namespace internal
62 } // namespace net
63
64 #endif // NET_BASE_ADDRESS_TRACKER_LINUX_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/address_tracker_linux.cc » ('j') | net/base/address_tracker_linux.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698