summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_channel_posix.h
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 21:41:47 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-01 21:41:47 +0000
commit3d5a60bf527eca66a0f41cf8e8fd05a949b135bf (patch)
tree76d2b66e81e410b35ddc5a40a608ffc12bb57b00 /ipc/ipc_channel_posix.h
parent5f887613876aa1854a3cf66a857e96b9870b2cf6 (diff)
downloadchromium_src-3d5a60bf527eca66a0f41cf8e8fd05a949b135bf.zip
chromium_src-3d5a60bf527eca66a0f41cf8e8fd05a949b135bf.tar.gz
chromium_src-3d5a60bf527eca66a0f41cf8e8fd05a949b135bf.tar.bz2
Separate out the platform-independent parts of Channel reading.
I'm planning on comsolidating the platform-independent management of the overflow buffer and message dispatch between the posix and windows channels. This patch separates out the behavior into the functions I'm planning on adding on the virtual interface. Basically, ProcessIncomingMessages and DispatchInputData will be the main shared code. In future patches, I'll refactor Windows in a similar way and then combine them into a shared base class. Review URL: http://codereview.chromium.org/9570001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_channel_posix.h')
-rw-r--r--ipc/ipc_channel_posix.h37
1 files changed, 25 insertions, 12 deletions
diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h
index 38f8ba4..7d26e9b 100644
--- a/ipc/ipc_channel_posix.h
+++ b/ipc/ipc_channel_posix.h
@@ -70,6 +70,8 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
#endif // OS_LINUX
private:
+ enum ReadState { READ_SUCCEEDED, READ_FAILED, READ_PENDING };
+
bool CreatePipe(const IPC::ChannelHandle& channel_handle);
bool ProcessIncomingMessages();
@@ -81,18 +83,25 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
void QueueHelloMessage();
bool IsHelloMessage(const Message* m) const;
- // Reads data from the "regular" (non FD) pipe into the input buffers. The
- // two output params will identify the data received.
+ // Populates the given buffer with data from the pipe.
+ //
+ // Returns the state of the read. On READ_SUCCESS, the number of bytes
+ // read will be placed into |*bytes_read| (which can be less than the
+ // buffer size). On READ_FAILED, the channel will be closed.
//
- // On success, returns true. If there is no data waiting, the pointers will
- // both be set to NULL. Otherwise, they'll indicate the data read. This will
- // be inside the input_buf_ for short messages, and for long messages will
- // automatically spill into the input_overflow_buf_. When in non-READWRITE
- // mode this will also load any handles from the message into input_fds_.
+ // If the return value is READ_PENDING, it means that there was no data
+ // ready for reading. The implementation is then responsible for either
+ // calling AsyncReadComplete with the number of bytes read into the
+ // buffer, or ProcessIncomingMessages to try the read again (depending
+ // on whether the platform's async I/O is "try again" or "write
+ // asynchronously into your buffer").
+ ReadState ReadData(char* buffer, int buffer_len, int* bytes_read);
+
+ // Takes the given data received from the IPC channel and dispatches any
+ // fully completed messages.
//
- // On failure, returns false. This means there was some kind of pipe error
- // and we should not continue.
- bool ReadDataFromPipe(const char** begin, const char** end);
+ // Returns true on success. False means channel error.
+ bool DispatchInputData(const char* input_data, int input_data_len);
#if defined(IPC_USES_READWRITE)
// Reads the next message from the fd_pipe_ and appends them to the
@@ -107,7 +116,11 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
//
// This will read from the input_fds_ and read more handles from the FD
// pipe if necessary.
- bool PopulateMessageFileDescriptors(Message* msg);
+ bool WillDispatchInputMessage(Message* msg);
+
+ // Performs post-dispatch checks. Called when all input buffers are empty,
+ // though there could be more data ready to be read from the OS.
+ bool DidEmptyInputBuffers();
// Finds the set of file descriptors in the given message. On success,
// appends the descriptors to the input_fds_ member and returns true
@@ -170,7 +183,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher {
// Messages to be sent are queued here.
std::queue<Message*> output_queue_;
- // We read from the pipe into this buffer. Managed by ReadDataFromPipe, do
+ // We read from the pipe into this buffer. Managed by DispatchInputData, do
// not access directly outside that function.
char input_buf_[Channel::kReadBufferSize];