GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/connection_wrap.cc Lines: 18 18 100.0 %
Date: 2016-09-05 Branches: 12 24 50.0 %

Line Branch Exec Source
1
#include "connection_wrap.h"
2
3
#include "env-inl.h"
4
#include "env.h"
5
#include "pipe_wrap.h"
6
#include "stream_wrap.h"
7
#include "tcp_wrap.h"
8
#include "util.h"
9
#include "util-inl.h"
10
11
namespace node {
12
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
7878
ConnectionWrap<WrapType, UVType>::ConnectionWrap(Environment* env,
23
                                                 Local<Object> object,
24
                                                 ProviderType provider,
25
                                                 AsyncWrap* parent)
26
    : StreamWrap(env,
27
                 object,
28
                 reinterpret_cast<uv_stream_t*>(&handle_),
29
                 provider,
30
7878
                 parent) {}
31
32
33
template <typename WrapType, typename UVType>
34
3183
void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle,
35
                                                    int status) {
36
3183
  WrapType* wrap_data = static_cast<WrapType*>(handle->data);
37

3183
  CHECK_NE(wrap_data, nullptr);
38

3183
  CHECK_EQ(&wrap_data->handle_, reinterpret_cast<UVType*>(handle));
39
40
3183
  Environment* env = wrap_data->env();
41
6366
  HandleScope handle_scope(env->isolate());
42
9549
  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

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

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

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

3183
    if (uv_accept(handle, client_handle))
66
      return;
67
68
    // Successful accept. Call the onconnection callback in JavaScript land.
69
3183
    argv[1] = client_obj;
70
  }
71
6366
  wrap_data->MakeCallback(env->onconnection_string(), arraysize(argv), argv);
72
}
73
74
template ConnectionWrap<PipeWrap, uv_pipe_t>::ConnectionWrap(
75
    Environment* env,
76
    Local<Object> object,
77
    ProviderType provider,
78
    AsyncWrap* parent);
79
80
template ConnectionWrap<TCPWrap, uv_tcp_t>::ConnectionWrap(
81
    Environment* env,
82
    Local<Object> object,
83
    ProviderType provider,
84
    AsyncWrap* parent);
85
86
template void ConnectionWrap<PipeWrap, uv_pipe_t>::OnConnection(
87
    uv_stream_t* handle, int status);
88
89
template void ConnectionWrap<TCPWrap, uv_tcp_t>::OnConnection(
90
    uv_stream_t* handle, int status);
91
92
93
}  // namespace node