GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/connection_wrap.cc Lines: 37 38 97.4 %
Date: 2017-12-18 Branches: 28 52 53.8 %

Line Branch Exec Source
1
#include "connection_wrap.h"
2
3
#include "connect_wrap.h"
4
#include "env-inl.h"
5
#include "pipe_wrap.h"
6
#include "stream_wrap.h"
7
#include "tcp_wrap.h"
8
#include "util-inl.h"
9
10
namespace node {
11
12
using v8::Boolean;
13
using v8::Context;
14
using v8::HandleScope;
15
using v8::Integer;
16
using v8::Local;
17
using v8::Object;
18
using v8::Value;
19
20
21
template <typename WrapType, typename UVType>
22
10564
ConnectionWrap<WrapType, UVType>::ConnectionWrap(Environment* env,
23
                                                 Local<Object> object,
24
                                                 ProviderType provider)
25
    : LibuvStreamWrap(env,
26
                      object,
27
                      reinterpret_cast<uv_stream_t*>(&handle_),
28
10564
                      provider) {}
29
30
31
template <typename WrapType, typename UVType>
32
2377
void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
33
                                                    int status) {
34
2377
  WrapType* wrap_data = static_cast<WrapType*>(handle->data);
35

2377
  CHECK_NE(wrap_data, nullptr);
36

2377
  CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));
37
38
2377
  Environment* env = wrap_data->env();
39
2377
  HandleScope handle_scope(env->isolate());
40

4754
  Context::Scope context_scope(env->context());
41
42
  // We should not be getting this callback if someone has already called
43
  // uv_close() on the handle.
44

4754
  CHECK_EQ(wrap_data->persistent().IsEmpty(), false);
45
46
  Local<Value> argv[] = {
47
    Integer::New(env->isolate(), status),
48
    Undefined(env->isolate())
49
7131
  };
50
51

2377
  if (status == 0) {
52
2377
    env->set_init_trigger_async_id(wrap_data->get_async_id());
53
    // Instantiate the client javascript object and handle.
54
    Local<Object> client_obj = WrapType::Instantiate(env,
55
                                                     wrap_data,
56
2377
                                                     WrapType::SOCKET);
57
58
    // Unwrap the client javascript object.
59
    WrapType* wrap;
60

2377
    ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj);
61
    uv_stream_t* client_handle =
62
2377
        reinterpret_cast<uv_stream_t*>(&wrap->handle_);
63
    // uv_accept can fail if the new connection has already been closed, in
64
    // which case an EAGAIN (resource temporarily unavailable) will be
65
    // returned.
66

2377
    if (uv_accept(handle, client_handle))
67
      return;
68
69
    // Successful accept. Call the onconnection callback in JavaScript land.
70
2377
    argv[1] = client_obj;
71
  }
72
4754
  wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
73
}
74
75
76
template <typename WrapType, typename UVType>
77
2468
void ConnectionWrap<WrapType, UVType>::AfterConnect(uv_connect_t* req,
78
                                                    int status) {
79
2468
  ConnectWrap* req_wrap = static_cast<ConnectWrap*>(req->data);
80

2468
  CHECK_NE(req_wrap, nullptr);
81
2468
  WrapType* wrap = static_cast<WrapType*>(req->handle->data);
82

2468
  CHECK_EQ(req_wrap->env(), wrap->env());
83
2468
  Environment* env = wrap->env();
84
85
2468
  HandleScope handle_scope(env->isolate());
86
2468
  Context::Scope context_scope(env->context());
87
88
  // The wrap and request objects should still be there.
89

4936
  CHECK_EQ(req_wrap->persistent().IsEmpty(), false);
90

4936
  CHECK_EQ(wrap->persistent().IsEmpty(), false);
91
92
  bool readable, writable;
93
94

2468
  if (status) {
95
92
    readable = writable = 0;
96
  } else {
97
2376
    readable = uv_is_readable(req->handle) != 0;
98
2376
    writable = uv_is_writable(req->handle) != 0;
99
  }
100
101
  Local<Value> argv[5] = {
102
    Integer::New(env->isolate(), status),
103
    wrap->object(),
104
    req_wrap->object(),
105
    Boolean::New(env->isolate(), readable),
106
    Boolean::New(env->isolate(), writable)
107
14808
  };
108
109
2468
  req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
110
111

4936
  delete req_wrap;
112
2468
}
113
114
template ConnectionWrap<PipeWrap, uv_pipe_t>::ConnectionWrap(
115
    Environment* env,
116
    Local<Object> object,
117
    ProviderType provider);
118
119
template ConnectionWrap<TCPWrap, uv_tcp_t>::ConnectionWrap(
120
    Environment* env,
121
    Local<Object> object,
122
    ProviderType provider);
123
124
template void ConnectionWrap<PipeWrap, uv_pipe_t>::OnConnection(
125
    uv_stream_t* handle, int status);
126
127
template void ConnectionWrap<TCPWrap, uv_tcp_t>::OnConnection(
128
    uv_stream_t* handle, int status);
129
130
template void ConnectionWrap<PipeWrap, uv_pipe_t>::AfterConnect(
131
    uv_connect_t* handle, int status);
132
133
template void ConnectionWrap<TCPWrap, uv_tcp_t>::AfterConnect(
134
    uv_connect_t* handle, int status);
135
136
137
}  // namespace node