Update mojo sdk to rev 59145288bae55b0fce4276b017df6a1117bcf00f
[chromium-blink-merge.git] / mojo / services / network / tcp_connected_socket_impl.h
blob041f85800146088bb5114a83e3d608fa62ee9b04
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
3 // found in the LICENSE file.
5 #ifndef MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_
6 #define MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "mojo/common/handle_watcher.h"
11 #include "mojo/public/cpp/bindings/interface_impl.h"
12 #include "mojo/services/network/public/interfaces/tcp_connected_socket.mojom.h"
13 #include "net/socket/tcp_socket.h"
15 namespace mojo {
17 class MojoToNetPendingBuffer;
18 class NetToMojoPendingBuffer;
20 class TCPConnectedSocketImpl : public InterfaceImpl<TCPConnectedSocket> {
21 public:
22 TCPConnectedSocketImpl(scoped_ptr<net::TCPSocket> socket,
23 ScopedDataPipeConsumerHandle send_stream,
24 ScopedDataPipeProducerHandle receive_stream);
25 ~TCPConnectedSocketImpl() override;
27 private:
28 // "Receiving" in this context means reading from TCPSocket and writing to
29 // the Mojo receive_stream.
30 void ReceiveMore();
31 void OnReceiveStreamReady(MojoResult result);
32 void DidReceive(bool completed_synchronously, int result);
34 // "Writing" is reading from the Mojo send_stream and writing to the
35 // TCPSocket.
36 void SendMore();
37 void OnSendStreamReady(MojoResult result);
38 void DidSend(bool completed_asynchronously, int result);
40 scoped_ptr<net::TCPSocket> socket_;
42 // 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
44 // *PendingBuffer.
46 // For reading from the network and writing to Mojo pipe.
47 ScopedDataPipeConsumerHandle send_stream_;
48 common::HandleWatcher receive_handle_watcher_;
49 scoped_refptr<NetToMojoPendingBuffer> pending_receive_;
51 // For reading from the Mojo pipe and writing to the network.
52 ScopedDataPipeProducerHandle receive_stream_;
53 common::HandleWatcher send_handle_watcher_;
54 scoped_refptr<MojoToNetPendingBuffer> pending_send_;
56 base::WeakPtrFactory<TCPConnectedSocketImpl> weak_ptr_factory_;
59 } // namespace mojo
61 #endif // MOJO_SERVICES_NETWORK_TCP_CONNECTED_SOCKET_H_