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

Side by Side Diff: mojo/edk/system/raw_channel_posix.cc

Issue 1403033003: Last set of fixes to make the src/mojo/edk pass the page cycler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 2 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
« no previous file with comments | « mojo/edk/system/raw_channel.cc ('k') | mojo/edk/system/raw_channel_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/edk/system/raw_channel.h" 5 #include "mojo/edk/system/raw_channel.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/uio.h> 9 #include <sys/uio.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 if (!pending_read_) { 363 if (!pending_read_) {
364 NOTREACHED(); 364 NOTREACHED();
365 return; 365 return;
366 } 366 }
367 367
368 pending_read_ = false; 368 pending_read_ = false;
369 size_t bytes_read = 0; 369 size_t bytes_read = 0;
370 IOResult io_result = Read(&bytes_read); 370 IOResult io_result = Read(&bytes_read);
371 if (io_result != IO_PENDING) { 371 if (io_result != IO_PENDING) {
372 OnReadCompleted(io_result, bytes_read); 372 base::AutoLock locker(read_lock());
373 OnReadCompletedNoLock(io_result, bytes_read);
373 // TODO(vtl): If we weren't destroyed, we'd like to do 374 // TODO(vtl): If we weren't destroyed, we'd like to do
374 // 375 //
375 // DCHECK(!read_watcher_ || pending_read_); 376 // DCHECK(!read_watcher_ || pending_read_);
376 // 377 //
377 // On failure, |read_watcher_| must have been reset; on success, we assume 378 // On failure, |read_watcher_| must have been reset; on success, we assume
378 // that |OnReadCompleted()| always schedules another read. Otherwise, we 379 // that |OnReadCompleted()| always schedules another read. Otherwise, we
379 // could end up spinning -- getting |OnFileCanReadWithoutBlocking()| again 380 // could end up spinning -- getting |OnFileCanReadWithoutBlocking()| again
380 // and again but not doing any actual read. 381 // and again but not doing any actual read.
381 // TODO(yzshen): An alternative is to stop watching if RawChannel doesn't 382 // TODO(yzshen): An alternative is to stop watching if RawChannel doesn't
382 // schedule a new read. But that code won't be reached under the current 383 // schedule a new read. But that code won't be reached under the current
(...skipping 14 matching lines...) Expand all
397 { 398 {
398 base::AutoLock locker(write_lock()); 399 base::AutoLock locker(write_lock());
399 400
400 DCHECK(pending_write_); 401 DCHECK(pending_write_);
401 402
402 pending_write_ = false; 403 pending_write_ = false;
403 io_result = WriteNoLock(&platform_handles_written, &bytes_written); 404 io_result = WriteNoLock(&platform_handles_written, &bytes_written);
404 } 405 }
405 406
406 if (io_result != IO_PENDING) { 407 if (io_result != IO_PENDING) {
407 OnWriteCompleted(io_result, platform_handles_written, bytes_written); 408 base::AutoLock locker(write_lock());
408 return; // |this| may have been destroyed in |OnWriteCompleted()|. 409 OnWriteCompletedNoLock(io_result, platform_handles_written, bytes_written);
410 return;
409 } 411 }
410 } 412 }
411 413
412 RawChannel::IOResult RawChannelPosix::ReadImpl(size_t* bytes_read) { 414 RawChannel::IOResult RawChannelPosix::ReadImpl(size_t* bytes_read) {
413 char* buffer = nullptr; 415 char* buffer = nullptr;
414 size_t bytes_to_read = 0; 416 size_t bytes_to_read = 0;
415 read_buffer()->GetBuffer(&buffer, &bytes_to_read); 417 read_buffer()->GetBuffer(&buffer, &bytes_to_read);
416 418
417 size_t old_num_platform_handles = read_platform_handles_.size(); 419 size_t old_num_platform_handles = read_platform_handles_.size();
418 ssize_t read_result = PlatformChannelRecvmsg( 420 ssize_t read_result = PlatformChannelRecvmsg(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 458 }
457 459
458 void RawChannelPosix::WaitToWrite() { 460 void RawChannelPosix::WaitToWrite() {
459 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); 461 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io());
460 462
461 DCHECK(write_watcher_); 463 DCHECK(write_watcher_);
462 464
463 if (!message_loop_for_io()->WatchFileDescriptor( 465 if (!message_loop_for_io()->WatchFileDescriptor(
464 fd_.get().fd, false, base::MessageLoopForIO::WATCH_WRITE, 466 fd_.get().fd, false, base::MessageLoopForIO::WATCH_WRITE,
465 write_watcher_.get(), this)) { 467 write_watcher_.get(), this)) {
466 { 468 base::AutoLock locker(write_lock());
467 base::AutoLock locker(write_lock()); 469 DCHECK(pending_write_);
468 470 pending_write_ = false;
469 DCHECK(pending_write_); 471 OnWriteCompletedNoLock(IO_FAILED_UNKNOWN, 0, 0);
470 pending_write_ = false; 472 return;
471 }
472 OnWriteCompleted(IO_FAILED_UNKNOWN, 0, 0);
473 return; // |this| may have been destroyed in |OnWriteCompleted()|.
474 } 473 }
475 } 474 }
476 475
477 } // namespace 476 } // namespace
478 477
479 // ----------------------------------------------------------------------------- 478 // -----------------------------------------------------------------------------
480 479
481 // Static factory method declared in raw_channel.h. 480 // Static factory method declared in raw_channel.h.
482 // static 481 // static
483 RawChannel* RawChannel::Create(ScopedPlatformHandle handle) { 482 RawChannel* RawChannel::Create(ScopedPlatformHandle handle) {
(...skipping 13 matching lines...) Expand all
497 struct stat stat1, stat2; 496 struct stat stat1, stat2;
498 if (fstat(this_handle.fd, &stat1) < 0) 497 if (fstat(this_handle.fd, &stat1) < 0)
499 return false; 498 return false;
500 if (fstat(other_handle.fd, &stat2) < 0) 499 if (fstat(other_handle.fd, &stat2) < 0)
501 return false; 500 return false;
502 return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino); 501 return (stat1.st_dev == stat2.st_dev) && (stat1.st_ino == stat2.st_ino);
503 } 502 }
504 503
505 } // namespace edk 504 } // namespace edk
506 } // namespace mojo 505 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/raw_channel.cc ('k') | mojo/edk/system/raw_channel_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698