diff options
author | Fedor Indutny <fedor.indutny@gmail.com> | 2013-06-11 14:59:10 +0400 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2013-06-16 11:30:14 +0400 |
commit | 03e008ddb8381b601dd42330ae57efedd5979ce4 (patch) | |
tree | ba4a068856a365e93648866b71591753b80fd4c3 /src/node_crypto_bio.h | |
parent | 4c48a39c65c175c2f0b1ec5bf58456dd83e71d99 (diff) |
tls_wrap: embed TLS encryption into streamwrap
Diffstat (limited to 'src/node_crypto_bio.h')
-rw-r--r-- | src/node_crypto_bio.h | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/node_crypto_bio.h b/src/node_crypto_bio.h index c2fd6a0ba76..4794453ef83 100644 --- a/src/node_crypto_bio.h +++ b/src/node_crypto_bio.h @@ -30,6 +30,13 @@ class NodeBIO { return &method_; } + NodeBIO() : length_(0), read_head_(&head_), write_head_(&head_) { + // Loop head + head_.next_ = &head_; + } + + ~NodeBIO(); + static int New(BIO* bio); static int Free(BIO* bio); static int Read(BIO* bio, char* out, int len); @@ -38,27 +45,6 @@ class NodeBIO { static int Gets(BIO* bio, char* out, int size); static long Ctrl(BIO* bio, int cmd, long num, void* ptr); - protected: - static const size_t kBufferLength = 16 * 1024; - - class Buffer { - public: - Buffer() : read_pos_(0), write_pos_(0), next_(NULL) { - } - - size_t read_pos_; - size_t write_pos_; - Buffer* next_; - char data_[kBufferLength]; - }; - - NodeBIO() : length_(0), read_head_(&head_), write_head_(&head_) { - // Loop head - head_.next_ = &head_; - } - - ~NodeBIO(); - // Allocate new buffer for write if needed void TryAllocateForWrite(); @@ -69,6 +55,10 @@ class NodeBIO { // Deallocate children of write head's child if they're empty void FreeEmpty(); + // Return pointer to internal data and amount of + // contiguous data available to read + char* Peek(size_t* size); + // Find first appearance of `delim` in buffer or `limit` if `delim` // wasn't found. size_t IndexOf(char delim, size_t limit); @@ -79,6 +69,13 @@ class NodeBIO { // Put `len` bytes from `data` into buffer void Write(const char* data, size_t size); + // Return pointer to internal data and amount of + // contiguous data available for future writes + char* PeekWritable(size_t* size); + + // Commit reserved data + void Commit(size_t size); + // Return size of buffer in bytes size_t inline Length() { return length_; @@ -89,6 +86,20 @@ class NodeBIO { return static_cast<NodeBIO*>(bio->ptr); } + protected: + static const size_t kBufferLength = 16 * 1024; + + class Buffer { + public: + Buffer() : read_pos_(0), write_pos_(0), next_(NULL) { + } + + size_t read_pos_; + size_t write_pos_; + Buffer* next_; + char data_[kBufferLength]; + }; + size_t length_; Buffer head_; Buffer* read_head_; |