| OLD | NEW |
| 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/uio.h> | 8 #include <sys/uio.h> |
| 9 #include <unistd.h> | 9 #include <unistd.h> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 bool OnReadMessageForRawChannel( | 47 bool OnReadMessageForRawChannel( |
| 48 const MessageInTransit::View& message_view) override; | 48 const MessageInTransit::View& message_view) override; |
| 49 IOResult Read(size_t* bytes_read) override; | 49 IOResult Read(size_t* bytes_read) override; |
| 50 IOResult ScheduleRead() override; | 50 IOResult ScheduleRead() override; |
| 51 embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( | 51 embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( |
| 52 size_t num_platform_handles, | 52 size_t num_platform_handles, |
| 53 const void* platform_handle_table) override; | 53 const void* platform_handle_table) override; |
| 54 IOResult WriteNoLock(size_t* platform_handles_written, | 54 IOResult WriteNoLock(size_t* platform_handles_written, |
| 55 size_t* bytes_written) override; | 55 size_t* bytes_written) override; |
| 56 IOResult ScheduleWriteNoLock() override; | 56 IOResult ScheduleWriteNoLock() override; |
| 57 bool OnInit() override; | 57 void OnInit() override; |
| 58 void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, | 58 void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, |
| 59 scoped_ptr<WriteBuffer> write_buffer) override; | 59 scoped_ptr<WriteBuffer> write_buffer) override; |
| 60 | 60 |
| 61 // |base::MessageLoopForIO::Watcher| implementation: | 61 // |base::MessageLoopForIO::Watcher| implementation: |
| 62 void OnFileCanReadWithoutBlocking(int fd) override; | 62 void OnFileCanReadWithoutBlocking(int fd) override; |
| 63 void OnFileCanWriteWithoutBlocking(int fd) override; | 63 void OnFileCanWriteWithoutBlocking(int fd) override; |
| 64 | 64 |
| 65 // Implements most of |Read()| (except for a bit of clean-up): | 65 // Implements most of |Read()| (except for a bit of clean-up): |
| 66 IOResult ReadImpl(size_t* bytes_read); | 66 IOResult ReadImpl(size_t* bytes_read); |
| 67 | 67 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 if (message_loop_for_io()->WatchFileDescriptor( | 303 if (message_loop_for_io()->WatchFileDescriptor( |
| 304 fd_.get().fd, false, base::MessageLoopForIO::WATCH_WRITE, | 304 fd_.get().fd, false, base::MessageLoopForIO::WATCH_WRITE, |
| 305 write_watcher_.get(), this)) { | 305 write_watcher_.get(), this)) { |
| 306 pending_write_ = true; | 306 pending_write_ = true; |
| 307 return IO_PENDING; | 307 return IO_PENDING; |
| 308 } | 308 } |
| 309 | 309 |
| 310 return IO_FAILED_UNKNOWN; | 310 return IO_FAILED_UNKNOWN; |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool RawChannelPosix::OnInit() { | 313 void RawChannelPosix::OnInit() { |
| 314 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); | 314 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); |
| 315 | 315 |
| 316 DCHECK(!read_watcher_); | 316 DCHECK(!read_watcher_); |
| 317 read_watcher_.reset(new base::MessageLoopForIO::FileDescriptorWatcher()); | 317 read_watcher_.reset(new base::MessageLoopForIO::FileDescriptorWatcher()); |
| 318 DCHECK(!write_watcher_); | 318 DCHECK(!write_watcher_); |
| 319 write_watcher_.reset(new base::MessageLoopForIO::FileDescriptorWatcher()); | 319 write_watcher_.reset(new base::MessageLoopForIO::FileDescriptorWatcher()); |
| 320 | 320 |
| 321 if (!message_loop_for_io()->WatchFileDescriptor( | 321 // I don't know how this can fail (unless |fd_| is bad, in which case it's a |
| 322 fd_.get().fd, true, base::MessageLoopForIO::WATCH_READ, | 322 // bug in our code). I also don't know if |WatchFileDescriptor()| actually |
| 323 read_watcher_.get(), this)) { | 323 // fails cleanly. |
| 324 // TODO(vtl): I'm not sure |WatchFileDescriptor()| actually fails cleanly | 324 CHECK(message_loop_for_io()->WatchFileDescriptor( |
| 325 // (in the sense of returning the message loop's state to what it was before | 325 fd_.get().fd, true, base::MessageLoopForIO::WATCH_READ, |
| 326 // it was called). | 326 read_watcher_.get(), this)); |
| 327 read_watcher_.reset(); | |
| 328 write_watcher_.reset(); | |
| 329 return false; | |
| 330 } | |
| 331 | |
| 332 return true; | |
| 333 } | 327 } |
| 334 | 328 |
| 335 void RawChannelPosix::OnShutdownNoLock( | 329 void RawChannelPosix::OnShutdownNoLock( |
| 336 scoped_ptr<ReadBuffer> /*read_buffer*/, | 330 scoped_ptr<ReadBuffer> /*read_buffer*/, |
| 337 scoped_ptr<WriteBuffer> /*write_buffer*/) { | 331 scoped_ptr<WriteBuffer> /*write_buffer*/) { |
| 338 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); | 332 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); |
| 339 write_lock().AssertAcquired(); | 333 write_lock().AssertAcquired(); |
| 340 | 334 |
| 341 read_watcher_.reset(); // This will stop watching (if necessary). | 335 read_watcher_.reset(); // This will stop watching (if necessary). |
| 342 write_watcher_.reset(); // This will stop watching (if necessary). | 336 write_watcher_.reset(); // This will stop watching (if necessary). |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 460 |
| 467 // Static factory method declared in raw_channel.h. | 461 // Static factory method declared in raw_channel.h. |
| 468 // static | 462 // static |
| 469 scoped_ptr<RawChannel> RawChannel::Create( | 463 scoped_ptr<RawChannel> RawChannel::Create( |
| 470 embedder::ScopedPlatformHandle handle) { | 464 embedder::ScopedPlatformHandle handle) { |
| 471 return make_scoped_ptr(new RawChannelPosix(handle.Pass())); | 465 return make_scoped_ptr(new RawChannelPosix(handle.Pass())); |
| 472 } | 466 } |
| 473 | 467 |
| 474 } // namespace system | 468 } // namespace system |
| 475 } // namespace mojo | 469 } // namespace mojo |
| OLD | NEW |