OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_SOCKET_BUFFERED_WRITE_STREAM_SOCKET_H_ |
| 6 #define NET_SOCKET_BUFFERED_WRITE_STREAM_SOCKET_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "net/base/net_log.h" |
| 11 #include "net/socket/stream_socket.h" |
| 12 |
| 13 namespace base { |
| 14 class TimeDelta; |
| 15 } |
| 16 |
| 17 namespace net { |
| 18 |
| 19 class AddressList; |
| 20 class GrowableIOBuffer; |
| 21 class IPEndPoint; |
| 22 |
| 23 // A StreamSocket decorator. All functions are passed through to the wrapped |
| 24 // socket, except for Write(). |
| 25 // |
| 26 // Writes are buffered locally so that multiple Write()s to this class are |
| 27 // issued as only one Write() to the wrapped socket. This is useful to force |
| 28 // multiple requests to be issued in a single packet, as is needed to trigger |
| 29 // edge cases in HTTP pipelining. |
| 30 // |
| 31 // Note that the Write() always returns synchronously. It will either buffer the |
| 32 // entire input or return the most recently reported error. |
| 33 // |
| 34 // There are no bounds on the local buffer size. Use carefully. |
| 35 class NET_EXPORT_PRIVATE BufferedWriteStreamSocket : public StreamSocket { |
| 36 public: |
| 37 BufferedWriteStreamSocket(StreamSocket* socket_to_wrap); |
| 38 virtual ~BufferedWriteStreamSocket(); |
| 39 |
| 40 // Socket interface |
| 41 virtual int Read(IOBuffer* buf, int buf_len, |
| 42 const CompletionCallback& callback) OVERRIDE; |
| 43 virtual int Write(IOBuffer* buf, int buf_len, |
| 44 const CompletionCallback& callback) OVERRIDE; |
| 45 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 46 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 47 |
| 48 // StreamSocket interface |
| 49 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 50 virtual void Disconnect() OVERRIDE; |
| 51 virtual bool IsConnected() const OVERRIDE; |
| 52 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 53 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; |
| 54 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 55 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 56 virtual void SetSubresourceSpeculation() OVERRIDE; |
| 57 virtual void SetOmniboxSpeculation() OVERRIDE; |
| 58 virtual bool WasEverUsed() const OVERRIDE; |
| 59 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 60 virtual int64 NumBytesRead() const OVERRIDE; |
| 61 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 62 |
| 63 private: |
| 64 void DoDelayedWrite(); |
| 65 void OnIOComplete(int result); |
| 66 |
| 67 scoped_ptr<StreamSocket> wrapped_socket_; |
| 68 scoped_refptr<GrowableIOBuffer> io_buffer_; |
| 69 scoped_refptr<GrowableIOBuffer> backup_buffer_; |
| 70 base::WeakPtrFactory<BufferedWriteStreamSocket> weak_factory_; |
| 71 bool callback_pending_; |
| 72 bool wrapped_write_in_progress_; |
| 73 int error_; |
| 74 }; |
| 75 |
| 76 } // namespace net |
| 77 |
| 78 #endif // NET_SOCKET_STREAM_SOCKET_H_ |
OLD | NEW |