| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_ |
| 6 #define MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_ | 6 #define MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "mojo/common/handle_watcher.h" | 10 #include "mojo/common/handle_watcher.h" |
| 11 #include "mojo/services/network/public/interfaces/tcp_connected_socket.mojom.h" | 11 #include "mojo/services/network/public/interfaces/tcp_connected_socket.mojom.h" |
| 12 #include "net/socket/tcp_socket.h" | 12 #include "net/socket/tcp_socket.h" |
| 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 | 16 |
| 17 class MojoToNetPendingBuffer; | 17 class MojoToNetPendingBuffer; |
| 18 class NetToMojoPendingBuffer; | 18 class NetToMojoPendingBuffer; |
| 19 | 19 |
| 20 class TCPConnectedSocketImpl : public InterfaceImpl<TCPConnectedSocket> { | 20 class TCPConnectedSocketImpl : public InterfaceImpl<TCPConnectedSocket> { |
| 21 public: | 21 public: |
| 22 TCPConnectedSocketImpl(scoped_ptr<net::TCPSocket> socket, | 22 TCPConnectedSocketImpl(scoped_ptr<net::TCPSocket> socket, |
| 23 ScopedDataPipeConsumerHandle send_stream, | 23 ScopedDataPipeConsumerHandle send_stream, |
| 24 ScopedDataPipeProducerHandle receive_stream); | 24 ScopedDataPipeProducerHandle receive_stream); |
| 25 ~TCPConnectedSocketImpl() override; | 25 ~TCPConnectedSocketImpl() override; |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 enum Direction { |
| 29 SEND, |
| 30 RECEIVE, |
| 31 }; |
| 32 |
| 28 // "Receiving" in this context means reading from TCPSocket and writing to | 33 // "Receiving" in this context means reading from TCPSocket and writing to |
| 29 // the Mojo receive_stream. | 34 // the Mojo receive_stream. |
| 30 void ReceiveMore(); | 35 void ReceiveMore(); |
| 31 void OnReceiveStreamReady(MojoResult result); | 36 void OnReceiveStreamReady(MojoResult result); |
| 32 void DidReceive(bool completed_synchronously, int result); | 37 void DidReceive(bool completed_synchronously, int result); |
| 38 void ShutdownReceive(); |
| 33 | 39 |
| 34 // "Writing" is reading from the Mojo send_stream and writing to the | 40 // "Writing" is reading from the Mojo send_stream and writing to the |
| 35 // TCPSocket. | 41 // TCPSocket. |
| 36 void SendMore(); | 42 void SendMore(); |
| 37 void OnSendStreamReady(MojoResult result); | 43 void OnSendStreamReady(MojoResult result); |
| 38 void DidSend(bool completed_asynchronously, int result); | 44 void DidSend(bool completed_asynchronously, int result); |
| 45 void ShutdownSend(); |
| 46 |
| 47 // Notify that socket direction has been closed. |
| 48 void NotifyClose(Direction direction, int net_result, MojoResult mojo_result); |
| 39 | 49 |
| 40 scoped_ptr<net::TCPSocket> socket_; | 50 scoped_ptr<net::TCPSocket> socket_; |
| 41 | 51 |
| 42 // The *stream handles will be null while there is an in-progress transation | 52 // The *stream handles will be null while there is an in-progress transation |
| 43 // between net and mojo. During this time, the handle will be owned by the | 53 // between net and mojo. During this time, the handle will be owned by the |
| 44 // *PendingBuffer. | 54 // *PendingBuffer. |
| 45 | 55 |
| 46 // For reading from the network and writing to Mojo pipe. | 56 // For reading from the network and writing to Mojo pipe. |
| 47 ScopedDataPipeConsumerHandle send_stream_; | 57 ScopedDataPipeConsumerHandle send_stream_; |
| 48 common::HandleWatcher receive_handle_watcher_; | 58 common::HandleWatcher receive_handle_watcher_; |
| 49 scoped_refptr<NetToMojoPendingBuffer> pending_receive_; | 59 scoped_refptr<NetToMojoPendingBuffer> pending_receive_; |
| 50 | 60 |
| 51 // For reading from the Mojo pipe and writing to the network. | 61 // For reading from the Mojo pipe and writing to the network. |
| 52 ScopedDataPipeProducerHandle receive_stream_; | 62 ScopedDataPipeProducerHandle receive_stream_; |
| 53 common::HandleWatcher send_handle_watcher_; | 63 common::HandleWatcher send_handle_watcher_; |
| 54 scoped_refptr<MojoToNetPendingBuffer> pending_send_; | 64 scoped_refptr<MojoToNetPendingBuffer> pending_send_; |
| 55 | 65 |
| 56 base::WeakPtrFactory<TCPConnectedSocketImpl> weak_ptr_factory_; | 66 base::WeakPtrFactory<TCPConnectedSocketImpl> weak_ptr_factory_; |
| 57 }; | 67 }; |
| 58 | 68 |
| 59 } // namespace mojo | 69 } // namespace mojo |
| 60 | 70 |
| 61 #endif // MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_ | 71 #endif // MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_ |
| OLD | NEW |