Index: net/base/network_change_notifier_linux.cc |
=================================================================== |
--- net/base/network_change_notifier_linux.cc (revision 44286) |
+++ net/base/network_change_notifier_linux.cc (working copy) |
@@ -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 @@ |
} |
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 @@ |
NOTREACHED(); |
} |
+void NetworkChangeNotifierLinux::WillDestroyCurrentMessageLoop() { |
+ StopWatching(); |
+ loop_ = NULL; |
+} |
+ |
void NetworkChangeNotifierLinux::ListenForNotifications() { |
char buf[4096]; |
int rv = ReadNotificationMessage(buf, arraysize(buf)); |
@@ -88,4 +93,13 @@ |
} |
} |
+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 |