OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/sync_socket.h" | 5 #include "base/sync_socket.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <string> | 8 #include <string> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "ipc/ipc_channel_proxy.h" | 15 #include "ipc/ipc_channel_proxy.h" |
16 #include "ipc/ipc_multiprocess_test.h" | 16 #include "ipc/ipc_multiprocess_test.h" |
17 #include "ipc/ipc_test_base.h" | 17 #include "ipc/ipc_test_base.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "testing/multiprocess_func_list.h" | 19 #include "testing/multiprocess_func_list.h" |
20 | 20 |
21 #if defined(OS_POSIX) | 21 #if defined(OS_POSIX) |
22 #include "base/file_descriptor_posix.h" | 22 #include "base/file_descriptor_posix.h" |
23 #endif | 23 #endif |
24 | 24 |
25 // IPC messages for testing --------------------------------------------------- | 25 // IPC messages for testing ---------------------------------------------------- |
26 | 26 |
27 #define IPC_MESSAGE_IMPL | 27 #define IPC_MESSAGE_IMPL |
28 #include "ipc/ipc_message_macros.h" | 28 #include "ipc/ipc_message_macros.h" |
29 | 29 |
30 #define IPC_MESSAGE_START TestMsgStart | 30 #define IPC_MESSAGE_START TestMsgStart |
31 | 31 |
32 // Message class to pass a base::SyncSocket::Handle to another process. This | 32 // Message class to pass a base::SyncSocket::Handle to another process. This |
33 // is not as easy as it sounds, because of the differences in transferring | 33 // is not as easy as it sounds, because of the differences in transferring |
34 // Windows HANDLEs versus posix file descriptors. | 34 // Windows HANDLEs versus posix file descriptors. |
35 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
36 IPC_MESSAGE_CONTROL1(MsgClassSetHandle, base::SyncSocket::Handle) | 36 IPC_MESSAGE_CONTROL1(MsgClassSetHandle, base::SyncSocket::Handle) |
37 #elif defined(OS_POSIX) | 37 #elif defined(OS_POSIX) |
38 IPC_MESSAGE_CONTROL1(MsgClassSetHandle, base::FileDescriptor) | 38 IPC_MESSAGE_CONTROL1(MsgClassSetHandle, base::FileDescriptor) |
39 #endif | 39 #endif |
40 | 40 |
41 // Message class to pass a response to the server. | 41 // Message class to pass a response to the server. |
42 IPC_MESSAGE_CONTROL1(MsgClassResponse, std::string) | 42 IPC_MESSAGE_CONTROL1(MsgClassResponse, std::string) |
43 | 43 |
44 // Message class to tell the server to shut down. | 44 // Message class to tell the server to shut down. |
45 IPC_MESSAGE_CONTROL0(MsgClassShutdown) | 45 IPC_MESSAGE_CONTROL0(MsgClassShutdown) |
46 | 46 |
47 // ---------------------------------------------------------------------------- | 47 // ----------------------------------------------------------------------------- |
48 | 48 |
49 namespace { | 49 namespace { |
| 50 |
50 const char kHelloString[] = "Hello, SyncSocket Client"; | 51 const char kHelloString[] = "Hello, SyncSocket Client"; |
51 const size_t kHelloStringLength = arraysize(kHelloString); | 52 const size_t kHelloStringLength = arraysize(kHelloString); |
52 } // namespace | |
53 | 53 |
54 // The SyncSocket server listener class processes two sorts of | 54 // The SyncSocket server listener class processes two sorts of |
55 // messages from the client. | 55 // messages from the client. |
56 class SyncSocketServerListener : public IPC::Listener { | 56 class SyncSocketServerListener : public IPC::Listener { |
57 public: | 57 public: |
58 SyncSocketServerListener() : chan_(NULL) { | 58 SyncSocketServerListener() : chan_(NULL) { |
59 } | 59 } |
60 | 60 |
61 void Init(IPC::Channel* chan) { | 61 void Init(IPC::Channel* chan) { |
62 chan_ = chan; | 62 chan_ = chan; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 EXPECT_EQ(0U, pair[0].Send(kHelloString, kHelloStringLength)); | 301 EXPECT_EQ(0U, pair[0].Send(kHelloString, kHelloStringLength)); |
302 EXPECT_EQ(bytes_in_buffer, pair[1].Peek()); | 302 EXPECT_EQ(bytes_in_buffer, pair[1].Peek()); |
303 | 303 |
304 // Read from another socket to free some space for a new write. | 304 // Read from another socket to free some space for a new write. |
305 char hello[kHelloStringLength] = {0}; | 305 char hello[kHelloStringLength] = {0}; |
306 pair[1].Receive(&hello[0], sizeof(hello)); | 306 pair[1].Receive(&hello[0], sizeof(hello)); |
307 | 307 |
308 // Should be able to write more data to the buffer now. | 308 // Should be able to write more data to the buffer now. |
309 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 309 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
310 } | 310 } |
| 311 |
| 312 } // namespace |
OLD | NEW |