@@ -30,6 +30,13 @@ class NodeBIO {
3030 return &method_;
3131 }
3232
33+ NodeBIO () : length_(0 ), read_head_(&head_), write_head_(&head_) {
34+ // Loop head
35+ head_.next_ = &head_;
36+ }
37+
38+ ~NodeBIO ();
39+
3340 static int New (BIO* bio);
3441 static int Free (BIO* bio);
3542 static int Read (BIO* bio, char * out, int len);
@@ -38,27 +45,6 @@ class NodeBIO {
3845 static int Gets (BIO* bio, char * out, int size);
3946 static long Ctrl (BIO* bio, int cmd, long num, void * ptr);
4047
41- protected:
42- static const size_t kBufferLength = 16 * 1024 ;
43-
44- class Buffer {
45- public:
46- Buffer () : read_pos_(0 ), write_pos_(0 ), next_(NULL ) {
47- }
48-
49- size_t read_pos_;
50- size_t write_pos_;
51- Buffer* next_;
52- char data_[kBufferLength ];
53- };
54-
55- NodeBIO () : length_(0 ), read_head_(&head_), write_head_(&head_) {
56- // Loop head
57- head_.next_ = &head_;
58- }
59-
60- ~NodeBIO ();
61-
6248 // Allocate new buffer for write if needed
6349 void TryAllocateForWrite ();
6450
@@ -69,6 +55,10 @@ class NodeBIO {
6955 // Deallocate children of write head's child if they're empty
7056 void FreeEmpty ();
7157
58+ // Return pointer to internal data and amount of
59+ // contiguous data available to read
60+ char * Peek (size_t * size);
61+
7262 // Find first appearance of `delim` in buffer or `limit` if `delim`
7363 // wasn't found.
7464 size_t IndexOf (char delim, size_t limit);
@@ -79,6 +69,13 @@ class NodeBIO {
7969 // Put `len` bytes from `data` into buffer
8070 void Write (const char * data, size_t size);
8171
72+ // Return pointer to internal data and amount of
73+ // contiguous data available for future writes
74+ char * PeekWritable (size_t * size);
75+
76+ // Commit reserved data
77+ void Commit (size_t size);
78+
8279 // Return size of buffer in bytes
8380 size_t inline Length () {
8481 return length_;
@@ -89,6 +86,20 @@ class NodeBIO {
8986 return static_cast <NodeBIO*>(bio->ptr );
9087 }
9188
89+ protected:
90+ static const size_t kBufferLength = 16 * 1024 ;
91+
92+ class Buffer {
93+ public:
94+ Buffer () : read_pos_(0 ), write_pos_(0 ), next_(NULL ) {
95+ }
96+
97+ size_t read_pos_;
98+ size_t write_pos_;
99+ Buffer* next_;
100+ char data_[kBufferLength ];
101+ };
102+
92103 size_t length_;
93104 Buffer head_;
94105 Buffer* read_head_;
0 commit comments