summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-12 23:54:34 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-12 23:54:34 +0000
commit72de04b7687ea518ffb339a74ff449661b5b7346 (patch)
tree0d525bec36700cd80bea36d06438c5f3a9945ab6 /net
parent8cd33545fefdd93d51e8a1f71f18b78f4fc6885f (diff)
downloadchromium_src-72de04b7687ea518ffb339a74ff449661b5b7346.zip
chromium_src-72de04b7687ea518ffb339a74ff449661b5b7346.tar.gz
chromium_src-72de04b7687ea518ffb339a74ff449661b5b7346.tar.bz2
Stop watching the netlink file descriptor before the message pump is destroyed.
A better fix is to make FileDescriptorWatcher handle this internally, will track that as a follow-up issue. BUG=39932 Review URL: http://codereview.chromium.org/1550003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44296 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/network_change_notifier_linux.cc26
-rw-r--r--net/base/network_change_notifier_linux.h13
2 files changed, 31 insertions, 8 deletions
diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc
index e6f5453..f5f9bf5 100644
--- a/net/base/network_change_notifier_linux.cc
+++ b/net/base/network_change_notifier_linux.cc
@@ -8,6 +8,7 @@
#include <sys/socket.h>
#include "base/basictypes.h"
+#include "base/eintr_wrapper.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "net/base/net_errors.h"
@@ -31,15 +32,14 @@ NetworkChangeNotifierLinux::NetworkChangeNotifierLinux()
}
ListenForNotifications();
+ loop_->AddDestructionObserver(this);
}
NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() {
- if (netlink_fd_ != kInvalidSocket) {
- if (close(netlink_fd_) != 0)
- PLOG(ERROR) << "Failed to close socket";
- netlink_fd_ = kInvalidSocket;
- netlink_watcher_.StopWatchingFileDescriptor();
- }
+ StopWatching();
+
+ if (loop_)
+ loop_->RemoveDestructionObserver(this);
}
void NetworkChangeNotifierLinux::OnFileCanReadWithoutBlocking(int fd) {
@@ -52,6 +52,11 @@ void NetworkChangeNotifierLinux::OnFileCanWriteWithoutBlocking(int /* fd */) {
NOTREACHED();
}
+void NetworkChangeNotifierLinux::WillDestroyCurrentMessageLoop() {
+ StopWatching();
+ loop_ = NULL;
+}
+
void NetworkChangeNotifierLinux::ListenForNotifications() {
char buf[4096];
int rv = ReadNotificationMessage(buf, arraysize(buf));
@@ -88,4 +93,13 @@ int NetworkChangeNotifierLinux::ReadNotificationMessage(char* buf, size_t len) {
}
}
+void NetworkChangeNotifierLinux::StopWatching() {
+ if (netlink_fd_ != kInvalidSocket) {
+ if (HANDLE_EINTR(close(netlink_fd_)) != 0)
+ PLOG(ERROR) << "Failed to close socket";
+ netlink_fd_ = kInvalidSocket;
+ netlink_watcher_.StopWatchingFileDescriptor();
+ }
+}
+
} // namespace net
diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h
index 83e63a0..e12a73c 100644
--- a/net/base/network_change_notifier_linux.h
+++ b/net/base/network_change_notifier_linux.h
@@ -13,7 +13,9 @@
namespace net {
class NetworkChangeNotifierLinux
- : public NetworkChangeNotifier, public MessageLoopForIO::Watcher {
+ : public NetworkChangeNotifier,
+ public MessageLoopForIO::Watcher,
+ public MessageLoop::DestructionObserver {
public:
NetworkChangeNotifierLinux();
@@ -32,6 +34,10 @@ class NetworkChangeNotifierLinux
virtual void OnFileCanReadWithoutBlocking(int fd);
virtual void OnFileCanWriteWithoutBlocking(int /* fd */);
+ // MessageLoop::DestructionObserver methods:
+
+ virtual void WillDestroyCurrentMessageLoop();
+
private:
virtual ~NetworkChangeNotifierLinux();
@@ -44,10 +50,13 @@ class NetworkChangeNotifierLinux
// recv() would block. Otherwise, it returns a net error code.
int ReadNotificationMessage(char* buf, size_t len);
+ // Stops watching the netlink file descriptor.
+ void StopWatching();
+
ObserverList<Observer, true> observers_;
int netlink_fd_; // This is the netlink socket descriptor.
- MessageLoopForIO* const loop_;
+ MessageLoopForIO* loop_;
MessageLoopForIO::FileDescriptorWatcher netlink_watcher_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierLinux);