| 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/system/raw_channel.h" | 5 #include "mojo/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 23 matching lines...) Expand all Loading... |
| 34 public base::MessageLoopForIO::Watcher { | 34 public base::MessageLoopForIO::Watcher { |
| 35 public: | 35 public: |
| 36 explicit RawChannelPosix(embedder::ScopedPlatformHandle handle); | 36 explicit RawChannelPosix(embedder::ScopedPlatformHandle handle); |
| 37 virtual ~RawChannelPosix(); | 37 virtual ~RawChannelPosix(); |
| 38 | 38 |
| 39 // |RawChannel| public methods: | 39 // |RawChannel| public methods: |
| 40 virtual size_t GetSerializedPlatformHandleSize() const OVERRIDE; | 40 virtual size_t GetSerializedPlatformHandleSize() const OVERRIDE; |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 // |RawChannel| protected methods: | 43 // |RawChannel| protected methods: |
| 44 // Actually override |EnqueueMessageNoLock()| so that we can send multiple |
| 45 // messages with FDs if necessary. |
| 46 virtual void EnqueueMessageNoLock( |
| 47 scoped_ptr<MessageInTransit> message) OVERRIDE; |
| 44 virtual IOResult Read(size_t* bytes_read) OVERRIDE; | 48 virtual IOResult Read(size_t* bytes_read) OVERRIDE; |
| 45 virtual IOResult ScheduleRead() OVERRIDE; | 49 virtual IOResult ScheduleRead() OVERRIDE; |
| 46 virtual embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( | 50 virtual embedder::ScopedPlatformHandleVectorPtr GetReadPlatformHandles( |
| 47 size_t num_platform_handles, | 51 size_t num_platform_handles, |
| 48 const void* platform_handle_table) OVERRIDE; | 52 const void* platform_handle_table) OVERRIDE; |
| 49 virtual IOResult WriteNoLock(size_t* platform_handles_written, | 53 virtual IOResult WriteNoLock(size_t* platform_handles_written, |
| 50 size_t* bytes_written) OVERRIDE; | 54 size_t* bytes_written) OVERRIDE; |
| 51 virtual IOResult ScheduleWriteNoLock() OVERRIDE; | 55 virtual IOResult ScheduleWriteNoLock() OVERRIDE; |
| 52 virtual bool OnInit() OVERRIDE; | 56 virtual bool OnInit() OVERRIDE; |
| 53 virtual void OnShutdownNoLock( | 57 virtual void OnShutdownNoLock( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 DCHECK(!write_watcher_.get()); | 109 DCHECK(!write_watcher_.get()); |
| 106 | 110 |
| 107 embedder::CloseAllPlatformHandles(&read_platform_handles_); | 111 embedder::CloseAllPlatformHandles(&read_platform_handles_); |
| 108 } | 112 } |
| 109 | 113 |
| 110 size_t RawChannelPosix::GetSerializedPlatformHandleSize() const { | 114 size_t RawChannelPosix::GetSerializedPlatformHandleSize() const { |
| 111 // We don't actually need any space on POSIX (since we just send FDs). | 115 // We don't actually need any space on POSIX (since we just send FDs). |
| 112 return 0; | 116 return 0; |
| 113 } | 117 } |
| 114 | 118 |
| 119 void RawChannelPosix::EnqueueMessageNoLock( |
| 120 scoped_ptr<MessageInTransit> message) { |
| 121 // TODO(vtl): Split any message with too many platform handles into multiple |
| 122 // messages. |
| 123 RawChannel::EnqueueMessageNoLock(message.Pass()); |
| 124 } |
| 125 |
| 115 RawChannel::IOResult RawChannelPosix::Read(size_t* bytes_read) { | 126 RawChannel::IOResult RawChannelPosix::Read(size_t* bytes_read) { |
| 116 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); | 127 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); |
| 117 DCHECK(!pending_read_); | 128 DCHECK(!pending_read_); |
| 118 | 129 |
| 119 char* buffer = NULL; | 130 char* buffer = NULL; |
| 120 size_t bytes_to_read = 0; | 131 size_t bytes_to_read = 0; |
| 121 read_buffer()->GetBuffer(&buffer, &bytes_to_read); | 132 read_buffer()->GetBuffer(&buffer, &bytes_to_read); |
| 122 | 133 |
| 123 size_t old_num_platform_handles = read_platform_handles_.size(); | 134 size_t old_num_platform_handles = read_platform_handles_.size(); |
| 124 ssize_t read_result = | 135 ssize_t read_result = |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 414 |
| 404 // Static factory method declared in raw_channel.h. | 415 // Static factory method declared in raw_channel.h. |
| 405 // static | 416 // static |
| 406 scoped_ptr<RawChannel> RawChannel::Create( | 417 scoped_ptr<RawChannel> RawChannel::Create( |
| 407 embedder::ScopedPlatformHandle handle) { | 418 embedder::ScopedPlatformHandle handle) { |
| 408 return scoped_ptr<RawChannel>(new RawChannelPosix(handle.Pass())); | 419 return scoped_ptr<RawChannel>(new RawChannelPosix(handle.Pass())); |
| 409 } | 420 } |
| 410 | 421 |
| 411 } // namespace system | 422 } // namespace system |
| 412 } // namespace mojo | 423 } // namespace mojo |
| OLD | NEW |