Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: net/socket/socket_bio_adapter.h

Issue 2411033003: Drop buffers in idle SSLClientSockets (and SSLServerSockets). (Closed)
Patch Set: typo Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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_SOCKET_BIO_ADAPTER_H_
6 #define NET_SOCKET_SOCKET_BIO_ADAPTER_H_
7
8 #include <openssl/base.h>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
12 #include "net/base/completion_callback.h"
13 #include "net/base/net_export.h"
14
15 namespace net {
16
17 class GrowableIOBuffer;
18 class IOBuffer;
19 class StreamSocket;
20
21 // An adapter to convert between StreamSocket and OpenSSL BIO I/O models.
Ryan Sleevi 2016/10/12 23:30:27 Could you expand a little more in this class descr
davidben 2016/10/13 23:40:13 Done.
22 class NET_EXPORT_PRIVATE SocketBIOAdapter {
23 public:
24 class Delegate {
Ryan Sleevi 2016/10/12 23:30:27 Similarly, a little expansion on the Delegate (and
davidben 2016/10/13 23:40:13 Done. I kept the pattern a bit vague because it re
25 public:
26 // Called after a BIO_read call failed due to an asynchronous operation. The
27 // delegate should retry any high-level operations which were blocked on a
28 // read.
29 virtual void OnReadReady() = 0;
30
31 // Called after a BIO_write call failed due to an asynchronous operation.
32 // The delegate should retry any high-level operations which were blocked on
33 // a write.
34 virtual void OnWriteReady() = 0;
35 };
36
37 // Creates a new SocketBIOAdapter for the specified socket. |socket| and
38 // |delegate| must remain valid for the lifetime of the SocketBIOAdapter.
39 SocketBIOAdapter(StreamSocket* socket,
40 int read_buffer_size,
41 int write_buffer_size,
Ryan Sleevi 2016/10/12 23:30:27 style: Why int, instead of size_t? - https://chrom
davidben 2016/10/13 23:40:13 The entire net stack (and BIO for that matter...)
42 Delegate* delegate);
43 ~SocketBIOAdapter();
44
45 BIO* bio() { return bio_.get(); }
46
47 // Returns true if any data has been read from the underlying StreamSocket but
Ryan Sleevi 2016/10/12 23:30:27 nit: StreamSocket, but
davidben 2016/10/13 23:40:13 Done.
48 // not yet consumed by the BIO.
49 bool HasPendingReadData();
50
51 private:
52 int BIORead(char* out, int len);
53 void HandleSocketReadResult(int result);
54 void OnSocketReadComplete(int result);
55
56 int BIOWrite(const char* in, int len);
57 void SocketWrite();
58 void HandleSocketWriteResult(int result);
59 void OnSocketWriteComplete(int result);
60 void CallOnReadReady();
61
62 static SocketBIOAdapter* GetAdapter(BIO* bio);
63 static int BIOReadWrapper(BIO* bio, char* out, int len);
64 static int BIOWriteWrapper(BIO* bio, const char* in, int len);
65 static long BIOCtrlWrapper(BIO* bio, int cmd, long larg, void* parg);
66
67 static const BIO_METHOD kBIOMethod;
Ryan Sleevi 2016/10/12 23:30:27 This can be moved fully in the .cc, can it not?
davidben 2016/10/13 23:40:13 It needs to have access to the statics which, in t
davidben 2016/10/13 23:44:08 Oh, I guess (b) and (c) aren't true. It's in two a
68
69 bssl::UniquePtr<BIO> bio_;
70
71 // The pointer is non-owning so this class may be used with both
72 // ClientSocketHandles and raw StreamSockets.
73 StreamSocket* socket_;
74
75 CompletionCallback read_callback_;
76 CompletionCallback write_callback_;
77
78 // The capacity of the read buffer.
79 int read_buffer_size_;
80 // A buffer containing data from the most recent socket Read(). The buffer is
81 // deallocated when unused.
82 scoped_refptr<IOBuffer> read_buffer_;
83 // The number of bytes of read_buffer_ consumed.
84 int read_offset_;
85 // The result of the most recent socket Read(). If ERR_IO_PENDING, there is a
86 // socket Read() in progress. If another error, Read() has failed. Otherwise,
87 // it is the number of bytes in the buffer (zero if empty).
88 int read_result_;
89
90 // The capacity of the write buffer.
91 int write_buffer_size_;
92 // A ring buffer of data to be written to the transport. The offset of the
93 // buffer is the start of the ring buffer and is advanced on successful
94 // Write(). The buffer is deallocated when unused.
95 scoped_refptr<GrowableIOBuffer> write_buffer_;
96 // The number of bytes of data in write_buffer_.
97 int write_buffer_data_size_;
98 // The most recent socket Write() error. If ERR_IO_PENDING, there is a socket
99 // Write() in progress. If OK, there is no socket Write() in progress and none
100 // have failed.
101 int write_error_;
102
103 Delegate* delegate_;
104
105 base::WeakPtrFactory<SocketBIOAdapter> weak_factory_;
106
107 DISALLOW_COPY_AND_ASSIGN(SocketBIOAdapter);
108 };
109
110 } // namespace net
111
112 #endif // NET_SOCKET_SOCKET_BIO_ADAPTER_H_
OLDNEW
« no previous file with comments | « net/net.gypi ('k') | net/socket/socket_bio_adapter.cc » ('j') | net/socket/socket_bio_adapter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698