summaryrefslogtreecommitdiff
path: root/src/tls_wrap.h
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2015-02-22 21:59:07 +0300
committerFedor Indutny <fedor@indutny.com>2015-02-22 22:31:57 +0300
commitb9686233fc0be679d7ba1262b611711629ee334e (patch)
tree9dbf94288a1faeaa956867b3a30f0d257747cd52 /src/tls_wrap.h
parent97b424365a883f3b8de18b3ec3f256307a92ad09 (diff)
downloadandroid-node-v8-b9686233fc0be679d7ba1262b611711629ee334e.tar.gz
android-node-v8-b9686233fc0be679d7ba1262b611711629ee334e.tar.bz2
android-node-v8-b9686233fc0be679d7ba1262b611711629ee334e.zip
stream_base: introduce StreamBase
StreamBase is an improved way to write C++ streams. The class itself is for separting `StreamWrap` (with the methods like `.writeAsciiString`, `.writeBuffer`, `.writev`, etc) from the `HandleWrap` class, making possible to write abstract C++ streams that are not bound to any uv socket. The following methods are important part of the abstraction (which mimics libuv's stream API): * Events: * `OnAlloc(size_t size, uv_buf_t*)` * `OnRead(ssize_t nread, const uv_buf_t*, uv_handle_type pending)` * `OnAfterWrite(WriteWrap*)` * Wrappers: * `DoShutdown(ShutdownWrap*)` * `DoTryWrite(uv_buf_t** bufs, size_t* count)` * `DoWrite(WriteWrap*, uv_buf_t*, size_t count, uv_stream_t* handle)` * `Error()` * `ClearError()` The implementation should provide all of these methods, thus providing the access to the underlying resource (be it uv handle, TLS socket, or anything else). A C++ stream may consume the input of another stream by replacing the event callbacks and proxying the writes. This kind of API is actually used now for the TLSWrap implementation, making it possible to wrap TLS stream into another TLS stream. Thus legacy API calls are no longer required in `_tls_wrap.js`. PR-URL: https://github.com/iojs/io.js/pull/840 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Diffstat (limited to 'src/tls_wrap.h')
-rw-r--r--src/tls_wrap.h73
1 files changed, 46 insertions, 27 deletions
diff --git a/src/tls_wrap.h b/src/tls_wrap.h
index 3815878d58..42452055ce 100644
--- a/src/tls_wrap.h
+++ b/src/tls_wrap.h
@@ -21,33 +21,33 @@ namespace crypto {
class SecureContext;
}
-class TLSCallbacks : public crypto::SSLWrap<TLSCallbacks>,
- public StreamWrapCallbacks,
- public AsyncWrap {
+class TLSWrap : public crypto::SSLWrap<TLSWrap>,
+ public StreamBase,
+ public AsyncWrap {
public:
- ~TLSCallbacks() override;
+ ~TLSWrap() override;
static void Initialize(v8::Handle<v8::Object> target,
v8::Handle<v8::Value> unused,
v8::Handle<v8::Context> context);
- const char* Error() const override;
- void ClearError() override;
- int TryWrite(uv_buf_t** bufs, size_t* count) override;
+ void* Cast() override;
+ int GetFD() const override;
+ bool IsAlive() const override;
+ bool IsClosing() const override;
+
+ // JavaScript functions
+ int ReadStart() override;
+ int ReadStop() override;
+
+ int DoShutdown(ShutdownWrap* req_wrap) override;
+ int DoTryWrite(uv_buf_t** bufs, size_t* count) override;
int DoWrite(WriteWrap* w,
uv_buf_t* bufs,
size_t count,
- uv_stream_t* send_handle,
- uv_write_cb cb) override;
- void AfterWrite(WriteWrap* w) override;
- void DoAlloc(uv_handle_t* handle,
- size_t suggested_size,
- uv_buf_t* buf) override;
- void DoRead(uv_stream_t* handle,
- ssize_t nread,
- const uv_buf_t* buf,
- uv_handle_type pending) override;
- int DoShutdown(ShutdownWrap* req_wrap, uv_shutdown_cb cb) override;
+ uv_stream_t* send_handle) override;
+ const char* Error() const override;
+ void ClearError() override;
void NewSessionDoneCb();
@@ -66,27 +66,26 @@ class TLSCallbacks : public crypto::SSLWrap<TLSCallbacks>,
// Write callback queue's item
class WriteItem {
public:
- WriteItem(WriteWrap* w, uv_write_cb cb) : w_(w), cb_(cb) {
+ explicit WriteItem(WriteWrap* w) : w_(w) {
}
~WriteItem() {
w_ = nullptr;
- cb_ = nullptr;
}
WriteWrap* w_;
- uv_write_cb cb_;
ListNode<WriteItem> member_;
};
- TLSCallbacks(Environment* env,
- Kind kind,
- v8::Handle<v8::Object> sc,
- StreamWrapCallbacks* old);
+ TLSWrap(Environment* env,
+ Kind kind,
+ StreamBase* steram,
+ v8::Handle<v8::Object> stream_obj,
+ v8::Handle<v8::Object> sc);
static void SSLInfoCallback(const SSL* ssl_, int where, int ret);
void InitSSL();
void EncOut();
- static void EncOutCb(uv_write_t* req, int status);
+ static void EncOutCb(WriteWrap* req_wrap, int status);
bool ClearIn();
void ClearOut();
void MakePending();
@@ -104,6 +103,25 @@ class TLSCallbacks : public crypto::SSLWrap<TLSCallbacks>,
}
}
+ AsyncWrap* GetAsyncWrap() override;
+ bool IsIPCPipe() const override;
+
+ // Resource implementation
+ static void OnAfterWriteImpl(WriteWrap* w, void* ctx);
+ static void OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx);
+ static void OnReadImpl(ssize_t nread,
+ const uv_buf_t* buf,
+ uv_handle_type pending,
+ void* ctx);
+ static void OnAfterWriteSelf(WriteWrap* w, void* ctx);
+ static void OnAllocSelf(size_t size, uv_buf_t* buf, void* ctx);
+ static void OnReadSelf(ssize_t nread,
+ const uv_buf_t* buf,
+ uv_handle_type pending,
+ void* ctx);
+
+ void DoRead(ssize_t nread, const uv_buf_t* buf, uv_handle_type pending);
+
// If |msg| is not nullptr, caller is responsible for calling `delete[] *msg`.
v8::Local<v8::Value> GetSSLError(int status, int* err, const char** msg);
@@ -125,10 +143,11 @@ class TLSCallbacks : public crypto::SSLWrap<TLSCallbacks>,
crypto::SecureContext* sc_;
v8::Persistent<v8::Object> sc_handle_;
+ StreamBase* stream_;
+ v8::Persistent<v8::Object> stream_handle_;
BIO* enc_in_;
BIO* enc_out_;
NodeBIO* clear_in_;
- uv_write_t write_req_;
size_t write_size_;
size_t write_queue_size_;
typedef ListHead<WriteItem, &WriteItem::member_> WriteItemList;