| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // ---------------------------------------------------------------------------- | 47 // ---------------------------------------------------------------------------- |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 const char kHelloString[] = "Hello, SyncSocket Client"; | 50 const char kHelloString[] = "Hello, SyncSocket Client"; |
| 51 const size_t kHelloStringLength = arraysize(kHelloString); | 51 const size_t kHelloStringLength = arraysize(kHelloString); |
| 52 } // namespace | 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::Channel::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; |
| 63 } | 63 } |
| 64 | 64 |
| 65 virtual bool OnMessageReceived(const IPC::Message& msg) { | 65 virtual bool OnMessageReceived(const IPC::Message& msg) { |
| 66 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 66 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 SyncSocketServerListener listener; | 114 SyncSocketServerListener listener; |
| 115 IPC::Channel chan(kSyncSocketChannel, IPC::Channel::MODE_CLIENT, &listener); | 115 IPC::Channel chan(kSyncSocketChannel, IPC::Channel::MODE_CLIENT, &listener); |
| 116 EXPECT_TRUE(chan.Connect()); | 116 EXPECT_TRUE(chan.Connect()); |
| 117 listener.Init(&chan); | 117 listener.Init(&chan); |
| 118 MessageLoop::current()->Run(); | 118 MessageLoop::current()->Run(); |
| 119 return 0; | 119 return 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 // The SyncSocket client listener only processes one sort of message, | 122 // The SyncSocket client listener only processes one sort of message, |
| 123 // a response from the server. | 123 // a response from the server. |
| 124 class SyncSocketClientListener : public IPC::Channel::Listener { | 124 class SyncSocketClientListener : public IPC::Listener { |
| 125 public: | 125 public: |
| 126 SyncSocketClientListener() { | 126 SyncSocketClientListener() { |
| 127 } | 127 } |
| 128 | 128 |
| 129 void Init(base::SyncSocket* socket, IPC::Channel* chan) { | 129 void Init(base::SyncSocket* socket, IPC::Channel* chan) { |
| 130 socket_ = socket; | 130 socket_ = socket; |
| 131 chan_ = chan; | 131 chan_ = chan; |
| 132 } | 132 } |
| 133 | 133 |
| 134 virtual bool OnMessageReceived(const IPC::Message& msg) { | 134 virtual bool OnMessageReceived(const IPC::Message& msg) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 EXPECT_EQ(0U, pair[0].Send(kHelloString, kHelloStringLength)); | 300 EXPECT_EQ(0U, pair[0].Send(kHelloString, kHelloStringLength)); |
| 301 EXPECT_EQ(bytes_in_buffer, pair[1].Peek()); | 301 EXPECT_EQ(bytes_in_buffer, pair[1].Peek()); |
| 302 | 302 |
| 303 // Read from another socket to free some space for a new write. | 303 // Read from another socket to free some space for a new write. |
| 304 char hello[kHelloStringLength] = {0}; | 304 char hello[kHelloStringLength] = {0}; |
| 305 pair[1].Receive(&hello[0], sizeof(hello)); | 305 pair[1].Receive(&hello[0], sizeof(hello)); |
| 306 | 306 |
| 307 // Should be able to write more data to the buffer now. | 307 // Should be able to write more data to the buffer now. |
| 308 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); | 308 EXPECT_EQ(kHelloStringLength, pair[0].Send(kHelloString, kHelloStringLength)); |
| 309 } | 309 } |
| OLD | NEW |