summaryrefslogtreecommitdiffstats
path: root/net/base/network_change_notifier_linux.cc
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/base/network_change_notifier_linux.cc
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/base/network_change_notifier_linux.cc')
-rw-r--r--net/base/network_change_notifier_linux.cc26
1 files changed, 20 insertions, 6 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