diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-09 06:46:06 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-09 06:46:06 +0000 |
commit | 313c00e5ed70534d2072e9e4c88016d509a8848b (patch) | |
tree | c5b98bcdfd319eed0ba04511ff57e0518b182a5a /ipc | |
parent | c230751ba15f1991943b8936d262940593c61e03 (diff) | |
download | chromium_src-313c00e5ed70534d2072e9e4c88016d509a8848b.zip chromium_src-313c00e5ed70534d2072e9e4c88016d509a8848b.tar.gz chromium_src-313c00e5ed70534d2072e9e4c88016d509a8848b.tar.bz2 |
Fix NamedProxyLauncher on windows. Wait for the named pipe to be connectable.
Enable NamedInterfaceTest on windows.
BUG=chromium-os:8515
TEST=none
Review URL: http://codereview.chromium.org/7486007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95957 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_channel.h | 4 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.cc | 11 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.h | 1 | ||||
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 14 | ||||
-rw-r--r-- | ipc/ipc_channel_win.cc | 18 | ||||
-rw-r--r-- | ipc/ipc_channel_win.h | 3 |
6 files changed, 49 insertions, 2 deletions
diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index 6bfcded..f3bf78f 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -171,6 +171,10 @@ class Channel : public Message::Sender { void ResetToAcceptingConnectionState(); #endif // defined(OS_POSIX) && !defined(OS_NACL) + // Returns true if a named server channel is initialized on the given channel + // ID. Even if true, the server may have already accepted a connection. + static bool IsNamedServerInitialized(const std::string& channel_id); + protected: // Used in Chrome by the TestSink to provide a dummy channel implementation // for testing. TestSink overrides the "interesting" functions in Channel so diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc index 462d442..fe60691 100644 --- a/ipc/ipc_channel_posix.cc +++ b/ipc/ipc_channel_posix.cc @@ -993,6 +993,12 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() { input_overflow_fds_.clear(); } +// static +bool Channel::ChannelImpl::IsNamedServerInitialized( + const std::string& channel_id) { + return file_util::PathExists(FilePath(channel_id)); +} + // Called by libevent when we can read from the pipe without blocking. void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { bool send_server_hello_msg = false; @@ -1202,4 +1208,9 @@ void Channel::ResetToAcceptingConnectionState() { channel_impl_->ResetToAcceptingConnectionState(); } +// static +bool Channel::IsNamedServerInitialized(const std::string& channel_id) { + return ChannelImpl::IsNamedServerInitialized(channel_id); +} + } // namespace IPC diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h index 652a29a..b66b1fc 100644 --- a/ipc/ipc_channel_posix.h +++ b/ipc/ipc_channel_posix.h @@ -62,6 +62,7 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher { bool HasAcceptedConnection() const; bool GetClientEuid(uid_t* client_euid) const; void ResetToAcceptingConnectionState(); + static bool IsNamedServerInitialized(const std::string& channel_id); private: bool CreatePipe(const IPC::ChannelHandle& channel_handle); diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index 5e9677d..cc6f20b 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -337,6 +337,20 @@ TEST_F(IPCChannelPosixTest, BadMode) { ASSERT_FALSE(channel.Connect()); } +TEST_F(IPCChannelPosixTest, IsNamedServerInitialized) { + IPCChannelPosixTestListener listener(false); + IPC::ChannelHandle chan_handle(kConnectionSocketTestName); + ASSERT_TRUE(file_util::Delete(FilePath(kConnectionSocketTestName), false)); + ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( + kConnectionSocketTestName)); + IPC::Channel channel(chan_handle, IPC::Channel::MODE_NAMED_SERVER, &listener); + ASSERT_TRUE(IPC::Channel::IsNamedServerInitialized( + kConnectionSocketTestName)); + channel.Close(); + ASSERT_FALSE(IPC::Channel::IsNamedServerInitialized( + kConnectionSocketTestName)); +} + // A long running process that connects to us MULTIPROCESS_TEST_MAIN(IPCChannelPosixTestConnectionProc) { MessageLoopForIO message_loop; diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc index e56235d..3a85a16 100644 --- a/ipc/ipc_channel_win.cc +++ b/ipc/ipc_channel_win.cc @@ -93,8 +93,19 @@ bool Channel::ChannelImpl::Send(Message* message) { return true; } +// static +bool Channel::ChannelImpl::IsNamedServerInitialized( + const std::string& channel_id) { + if (WaitNamedPipe(PipeName(channel_id).c_str(), 1)) + return true; + // If ERROR_SEM_TIMEOUT occurred, the pipe exists but is handling another + // connection. + return GetLastError() == ERROR_SEM_TIMEOUT; +} + +// static const std::wstring Channel::ChannelImpl::PipeName( - const std::string& channel_id) const { + const std::string& channel_id) { std::string name("\\\\.\\pipe\\chrome."); return ASCIIToWide(name.append(channel_id)); } @@ -411,4 +422,9 @@ bool Channel::Send(Message* message) { return channel_impl_->Send(message); } +// static +bool Channel::IsNamedServerInitialized(const std::string& channel_id) { + return ChannelImpl::IsNamedServerInitialized(channel_id); +} + } // namespace IPC diff --git a/ipc/ipc_channel_win.h b/ipc/ipc_channel_win.h index 358d6fa..ada88ac 100644 --- a/ipc/ipc_channel_win.h +++ b/ipc/ipc_channel_win.h @@ -30,8 +30,9 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler { void Close(); void set_listener(Listener* listener) { listener_ = listener; } bool Send(Message* message); + static bool IsNamedServerInitialized(const std::string& channel_id); private: - const std::wstring PipeName(const std::string& channel_id) const; + static const std::wstring PipeName(const std::string& channel_id); bool CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode); bool ProcessConnection(); |