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

Unified Diff: mojo/edk/system/raw_channel_posix.cc

Issue 859333004: Allow mojo::system::RawChannel::Delegate methods to destroy the RawChannel. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: mojo/edk/system/raw_channel_posix.cc
diff --git a/mojo/edk/system/raw_channel_posix.cc b/mojo/edk/system/raw_channel_posix.cc
index 078f8cbfcdd39c4f4c65dbf3a2bddccbbd49b365..d8c55d56b1b2bb3ef2b3f45c0ed53a60fdbeabe0 100644
--- a/mojo/edk/system/raw_channel_posix.cc
+++ b/mojo/edk/system/raw_channel_posix.cc
@@ -356,18 +356,23 @@ void RawChannelPosix::OnFileCanReadWithoutBlocking(int fd) {
pending_read_ = false;
size_t bytes_read = 0;
IOResult io_result = Read(&bytes_read);
- if (io_result != IO_PENDING)
+ if (io_result != IO_PENDING) {
OnReadCompleted(io_result, bytes_read);
+ // TODO(vtl): If we weren't destroyed, we'd like to do
+ //
+ // DCHECK(!read_watcher_ || pending_read_);
+ //
+ // On failure, |read_watcher_| must have been reset; on success, we assume
+ // that |OnReadCompleted()| always schedules another read. Otherwise, we
+ // could end up spinning -- getting |OnFileCanReadWithoutBlocking()| again
+ // and again but not doing any actual read.
+ // TODO(yzshen): An alternative is to stop watching if RawChannel doesn't
+ // schedule a new read. But that code won't be reached under the current
+ // RawChannel implementation.
+ return; // |this| may have been destroyed in |OnReadCompleted()|.
+ }
- // On failure, |read_watcher_| must have been reset; on success,
- // we assume that |OnReadCompleted()| always schedules another read.
- // Otherwise, we could end up spinning -- getting
- // |OnFileCanReadWithoutBlocking()| again and again but not doing any actual
- // read.
- // TODO(yzshen): An alternative is to stop watching if RawChannel doesn't
- // schedule a new read. But that code won't be reached under the current
- // RawChannel implementation.
- DCHECK(!read_watcher_ || pending_read_);
+ DCHECK(pending_read_);
}
void RawChannelPosix::OnFileCanWriteWithoutBlocking(int fd) {
@@ -386,8 +391,10 @@ void RawChannelPosix::OnFileCanWriteWithoutBlocking(int fd) {
io_result = WriteNoLock(&platform_handles_written, &bytes_written);
}
- if (io_result != IO_PENDING)
+ if (io_result != IO_PENDING) {
OnWriteCompleted(io_result, platform_handles_written, bytes_written);
+ return; // |this| may have been destroyed in |OnWriteCompleted()|.
+ }
}
RawChannel::IOResult RawChannelPosix::ReadImpl(size_t* bytes_read) {
@@ -451,6 +458,7 @@ void RawChannelPosix::WaitToWrite() {
pending_write_ = false;
}
OnWriteCompleted(IO_FAILED_UNKNOWN, 0, 0);
+ return; // |this| may have been destroyed in |OnWriteCompleted()|.
}
}

Powered by Google App Engine
This is Rietveld 408576698