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

2394
  CHECK_NE(wrap_data, nullptr);
38

2394
  CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));
39
40
2394
  Environment* env = wrap_data->env();
41
2394
  HandleScope handle_scope(env->isolate());
42

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

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

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

2394
    ASSIGN_OR_RETURN_UNWRAP(&wrap, client_obj);
61
    uv_stream_t* client_handle =
62
2394
        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

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

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

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

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

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

2479
  if (status) {
95
90
    readable = writable = 0;
96
  } else {
97
2389
    readable = uv_is_readable(req->handle) != 0;
98
2389
    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
14874
  };
108
109
2479
  req_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
110
111

4958
  delete req_wrap;
112
2479
}
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