1
1
#include " pipe_wrap.h"
2
2
3
3
#include " async-wrap.h"
4
+ #include " connection_wrap.h"
4
5
#include " env.h"
5
6
#include " env-inl.h"
6
7
#include " handle_wrap.h"
@@ -27,7 +28,6 @@ using v8::Integer;
27
28
using v8::Local;
28
29
using v8::Object;
29
30
using v8::String;
30
- using v8::Undefined;
31
31
using v8::Value;
32
32
33
33
@@ -51,11 +51,6 @@ static void NewPipeConnectWrap(const FunctionCallbackInfo<Value>& args) {
51
51
}
52
52
53
53
54
- uv_pipe_t * PipeWrap::UVHandle () {
55
- return &handle_;
56
- }
57
-
58
-
59
54
Local<Object> PipeWrap::Instantiate (Environment* env, AsyncWrap* parent) {
60
55
EscapableHandleScope handle_scope (env->isolate ());
61
56
CHECK_EQ (false , env->pipe_constructor_template ().IsEmpty ());
@@ -125,11 +120,10 @@ PipeWrap::PipeWrap(Environment* env,
125
120
Local<Object> object,
126
121
bool ipc,
127
122
AsyncWrap* parent)
128
- : StreamWrap(env,
129
- object,
130
- reinterpret_cast <uv_stream_t *>(&handle_),
131
- AsyncWrap::PROVIDER_PIPEWRAP,
132
- parent) {
123
+ : ConnectionWrap(env,
124
+ object,
125
+ AsyncWrap::PROVIDER_PIPEWRAP,
126
+ parent) {
133
127
int r = uv_pipe_init (env->event_loop (), &handle_, ipc);
134
128
CHECK_EQ (r, 0 ); // How do we proxy this error up to javascript?
135
129
// Suggestion: uv_pipe_init() returns void.
@@ -167,44 +161,6 @@ void PipeWrap::Listen(const FunctionCallbackInfo<Value>& args) {
167
161
}
168
162
169
163
170
- // TODO(bnoordhuis) maybe share with TCPWrap?
171
- void PipeWrap::OnConnection (uv_stream_t * handle, int status) {
172
- PipeWrap* pipe_wrap = static_cast <PipeWrap*>(handle->data );
173
- CHECK_EQ (&pipe_wrap->handle_ , reinterpret_cast <uv_pipe_t *>(handle));
174
-
175
- Environment* env = pipe_wrap->env ();
176
- HandleScope handle_scope (env->isolate ());
177
- Context::Scope context_scope (env->context ());
178
-
179
- // We should not be getting this callback if someone as already called
180
- // uv_close() on the handle.
181
- CHECK_EQ (pipe_wrap->persistent ().IsEmpty (), false );
182
-
183
- Local<Value> argv[] = {
184
- Integer::New (env->isolate (), status),
185
- Undefined (env->isolate ())
186
- };
187
-
188
- if (status != 0 ) {
189
- pipe_wrap->MakeCallback (env->onconnection_string (), arraysize (argv), argv);
190
- return ;
191
- }
192
-
193
- // Instanciate the client javascript object and handle.
194
- Local<Object> client_obj = Instantiate (env, pipe_wrap);
195
-
196
- // Unwrap the client javascript object.
197
- PipeWrap* wrap;
198
- ASSIGN_OR_RETURN_UNWRAP (&wrap, client_obj);
199
- uv_stream_t * client_handle = reinterpret_cast <uv_stream_t *>(&wrap->handle_ );
200
- if (uv_accept (handle, client_handle))
201
- return ;
202
-
203
- // Successful accept. Call the onconnection callback in JavaScript land.
204
- argv[1 ] = client_obj;
205
- pipe_wrap->MakeCallback (env->onconnection_string (), arraysize (argv), argv);
206
- }
207
-
208
164
// TODO(bnoordhuis) Maybe share this with TCPWrap?
209
165
void PipeWrap::AfterConnect (uv_connect_t * req, int status) {
210
166
PipeConnectWrap* req_wrap = static_cast <PipeConnectWrap*>(req->data );
0 commit comments