Index: mojo/edk/system/raw_channel.h |
diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel.h b/mojo/edk/system/raw_channel.h |
similarity index 82% |
copy from third_party/mojo/src/mojo/edk/system/raw_channel.h |
copy to mojo/edk/system/raw_channel.h |
index cbcc1b3fc63d543ad03560161d57f611a3e83490..cd2b914673ed79c64284234f5590efed325e063c 100644 |
--- a/third_party/mojo/src/mojo/edk/system/raw_channel.h |
+++ b/mojo/edk/system/raw_channel.h |
@@ -41,9 +41,6 @@ namespace system { |
// on which |Init()| is called). |
class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
public: |
- // This object may be destroyed on any thread (if |Init()| was called, after |
- // |Shutdown()| was called). |
- virtual ~RawChannel(); |
// The |Delegate| is only accessed on the same thread as the message loop |
// (passed in on creation). |
@@ -84,7 +81,12 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
// Static factory method. |handle| should be a handle to a |
// (platform-appropriate) bidirectional communication channel (e.g., a socket |
// on POSIX, a named pipe on Windows). |
- static scoped_ptr<RawChannel> Create(embedder::ScopedPlatformHandle handle); |
+ static RawChannel* Create(embedder::ScopedPlatformHandle handle); |
+ |
+ // Returns the amount of space needed in the |MessageInTransit|'s |
+ // |TransportData|'s "platform handle table" per platform handle (to be |
+ // attached to a message). (This amount may be zero.) |
+ static size_t GetSerializedPlatformHandleSize(); |
// This must be called (on an I/O thread) before this object is used. Does |
// *not* take ownership of |delegate|. Both the I/O thread and |delegate| must |
@@ -95,6 +97,20 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
// This must be called (on the I/O thread) before this object is destroyed. |
void Shutdown(); |
+ // Returns the platform handle for the pipe synchronously. |
+ |
+ |
+ // Flushes all pending writes synchronously. |
+ |
+ |
+ // TODO(jam): change above to write it to shared memory and return handle as |
+ // writing synchronously won't work for lots of pending data. |
+ // Returns any partially read data. |
+ // NOTE: After calling this, consider the channel shutdown and don't call into |
+ // it anymore |
+ embedder::ScopedPlatformHandle ReleaseHandle( |
+ std::vector<char>* read_buffer); |
+ |
// Writes the given message (or schedules it to be written). |message| must |
// have no |Dispatcher|s still attached (i.e., |
// |SerializeAndCloseDispatchers()| should have been called). This method is |
@@ -107,10 +123,14 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
// becomes empty (or something like that). |
bool IsWriteBufferEmpty(); |
- // Returns the amount of space needed in the |MessageInTransit|'s |
- // |TransportData|'s "platform handle table" per platform handle (to be |
- // attached to a message). (This amount may be zero.) |
- virtual size_t GetSerializedPlatformHandleSize() const = 0; |
+ bool IsReadBufferEmpty(); |
+ |
+ void SetInitialReadBufferData(char* data, size_t size); |
+ |
+ void set_debug_started_sending() { debug_started_sending_ = true; } |
+ bool debug_started_sending() { return debug_started_sending_; } |
+ |
+ virtual embedder::PlatformHandle HandleForDebuggingNoLock() = 0; |
protected: |
// Result of I/O operations. |
@@ -132,6 +152,14 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
void GetBuffer(char** addr, size_t* size); |
+ void Reset() {num_valid_bytes_ = 0; } |
+ |
+ // temp for debugging |
+ // TODO(jam): pass in a cleaner way to ReleaseHandle, just like shutdown |
+ // case. |
+ char* buffer() { return &buffer_[0]; } |
+ size_t num_valid_bytes() {return num_valid_bytes_;} |
+ |
private: |
friend class RawChannel; |
@@ -152,7 +180,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
size_t size; |
}; |
- explicit WriteBuffer(size_t serialized_platform_handle_size); |
+ WriteBuffer(); |
~WriteBuffer(); |
// Returns true if there are (more) platform handles to be sent (from the |
@@ -179,10 +207,23 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
// |OnWriteCompletedNoLock()|. |
void GetBuffers(std::vector<Buffer>* buffers) const; |
- private: |
+ |
+ |
+ |
+ |
+ // temp for testing |
+ size_t queue_size() {return message_queue_.Size();} |
+ |
+ // TODO(jam): better way of giving buffer on release handle |
+ MessageInTransitQueue* message_queue() { return &message_queue_; } |
+ |
+ |
+ |
+ // TODO JAM REMOVE AND ADD METHODS |
+// private: |
friend class RawChannel; |
- const size_t serialized_platform_handle_size_; |
+ size_t serialized_platform_handle_size_; |
MessageInTransitQueue message_queue_; |
// Platform handles are sent before the message data, but doing so may |
@@ -199,6 +240,11 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
RawChannel(); |
+ // Shutdown must be called on the IO thread. This object deletes itself once |
+ // it's flushed all pending writes and insured that the other side of the pipe |
+ // read them. |
+ virtual ~RawChannel(); |
+ |
// |result| must not be |IO_PENDING|. Must be called on the I/O thread WITHOUT |
// |write_lock_| held. This object may be destroyed by this call. |
void OnReadCompleted(IOResult io_result, size_t bytes_read); |
@@ -210,6 +256,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
base::MessageLoopForIO* message_loop_for_io() { return message_loop_for_io_; } |
base::Lock& write_lock() { return write_lock_; } |
+ base::Lock& read_lock() { return read_lock_; } |
// Should only be called on the I/O thread. |
yzshen1
2015/09/23 22:47:09
Now that ReleaseHandle could be called on non-IO t
|
ReadBuffer* read_buffer() { return read_buffer_.get(); } |
@@ -234,6 +281,12 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
virtual bool OnReadMessageForRawChannel( |
const MessageInTransit::View& message_view); |
+ |
+ // Implementation must write any pending messages synchronously. |
+ // TODO(jam): change to return shared memory with pending serialized msgs. |
+ virtual embedder::ScopedPlatformHandle ReleaseHandleNoLock( |
+ std::vector<char>* read_buffer) = 0; |
+ |
// Reads into |read_buffer()|. |
// This class guarantees that: |
// - the area indicated by |GetBuffer()| will stay valid until read completion |
@@ -289,7 +342,11 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
virtual void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, |
scoped_ptr<WriteBuffer> write_buffer) = 0; |
+ void SendQueuedMessagesNoLock(); |
+ |
private: |
+ friend class base::DeleteHelper<RawChannel>; |
+ |
// Converts an |IO_FAILED_...| for a read to a |Delegate::Error|. |
static Delegate::Error ReadIOResultToError(IOResult io_result); |
@@ -297,6 +354,8 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
// |write_lock_| held. This object may be destroyed by this call. |
void CallOnError(Delegate::Error error); |
+ void LockAndCallOnError(Delegate::Error error); |
+ |
// If |io_result| is |IO_SUCCESS|, updates the write buffer and schedules a |
// write operation to run later if there is more to write. If |io_result| is |
// failure or any other error occurs, cancels pending writes and returns |
@@ -306,19 +365,51 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { |
size_t platform_handles_written, |
size_t bytes_written); |
+ // Handler for the RAW_CHANNEL_QUIT message. |
+ void HandleQuitMessage(); |
+ |
+ // Helper method to dispatch messages from the read buffer. |
+ // |did_dispatch_message| is true iff it dispatched any messages. |
+ // |stop_dispatching| is set to true if the code calling this should stop |
+ // dispatching, either because we hit an erorr or the delegate shutdown the |
+ // channel. |
+ void DispatchMessages(bool* did_dispatch_message, bool* stop_dispatching); |
+ |
// Set in |Init()| and never changed (hence usable on any thread without |
// locking): |
base::MessageLoopForIO* message_loop_for_io_; |
+ |
+ |
+ |
+ |
+ // TODO(jam): one lock only.... |
+ |
+ |
+ |
+ |
// Only used on the I/O thread: |
- Delegate* delegate_; |
+ |
bool* set_on_shutdown_; |
+ |
+ base::Lock read_lock_; // Protects read_buffer_. |
+ // This is usually only accessed on IO thread, except when ReleaseHandle is |
+ // called. |
scoped_ptr<ReadBuffer> read_buffer_; |
+ // ditto: usually used on io thread except ReleaseHandle |
+ Delegate* delegate_; |
+ |
+ // If grabbing both locks, grab read first. |
base::Lock write_lock_; // Protects the following members. |
+ bool write_ready_; |
bool write_stopped_; |
scoped_ptr<WriteBuffer> write_buffer_; |
+ bool debug_started_sending_; |
+ |
+ bool error_occurred_; |
+ |
// This is used for posting tasks from write threads to the I/O thread. It |
// must only be accessed under |write_lock_|. The weak pointers it produces |
// are only used/invalidated on the I/O thread. |