GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tcp_wrap.h Lines: 8 10 80.0 %
Date: 2022-09-22 04:22:24 Branches: 2 3 66.7 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#ifndef SRC_TCP_WRAP_H_
23
#define SRC_TCP_WRAP_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include "async_wrap.h"
28
#include "connection_wrap.h"
29
30
namespace node {
31
32
class ExternalReferenceRegistry;
33
class Environment;
34
35
class TCPWrap : public ConnectionWrap<TCPWrap, uv_tcp_t> {
36
 public:
37
  enum SocketType {
38
    SOCKET,
39
    SERVER
40
  };
41
42
  static v8::MaybeLocal<v8::Object> Instantiate(Environment* env,
43
                                                AsyncWrap* parent,
44
                                                SocketType type);
45
  static void Initialize(v8::Local<v8::Object> target,
46
                         v8::Local<v8::Value> unused,
47
                         v8::Local<v8::Context> context,
48
                         void* priv);
49
  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
50
51
13
  SET_NO_MEMORY_INFO()
52
13
  SET_SELF_SIZE(TCPWrap)
53
55
  std::string MemoryInfoName() const override {
54
55
    switch (provider_type()) {
55
41
      case ProviderType::PROVIDER_TCPWRAP:
56
41
        return "TCPSocketWrap";
57
14
      case ProviderType::PROVIDER_TCPSERVERWRAP:
58
14
        return "TCPServerWrap";
59
      default:
60
        UNREACHABLE();
61
    }
62
  }
63
64
 private:
65
  typedef uv_tcp_t HandleType;
66
67
  template <typename T,
68
            int (*F)(const typename T::HandleType*, sockaddr*, int*)>
69
  friend void GetSockOrPeerName(const v8::FunctionCallbackInfo<v8::Value>&);
70
71
  TCPWrap(Environment* env, v8::Local<v8::Object> object,
72
          ProviderType provider);
73
74
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
75
  static void SetNoDelay(const v8::FunctionCallbackInfo<v8::Value>& args);
76
  static void SetKeepAlive(const v8::FunctionCallbackInfo<v8::Value>& args);
77
  static void Bind(const v8::FunctionCallbackInfo<v8::Value>& args);
78
  static void Bind6(const v8::FunctionCallbackInfo<v8::Value>& args);
79
  static void Listen(const v8::FunctionCallbackInfo<v8::Value>& args);
80
  static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args);
81
  static void Connect6(const v8::FunctionCallbackInfo<v8::Value>& args);
82
  template <typename T>
83
  static void Connect(const v8::FunctionCallbackInfo<v8::Value>& args,
84
      std::function<int(const char* ip_address, T* addr)> uv_ip_addr);
85
  static void Open(const v8::FunctionCallbackInfo<v8::Value>& args);
86
  template <typename T>
87
  static void Bind(
88
      const v8::FunctionCallbackInfo<v8::Value>& args,
89
      int family,
90
      std::function<int(const char* ip_address, int port, T* addr)> uv_ip_addr);
91
  static void Reset(const v8::FunctionCallbackInfo<v8::Value>& args);
92
  int Reset(v8::Local<v8::Value> close_callback = v8::Local<v8::Value>());
93
94
#ifdef _WIN32
95
  static void SetSimultaneousAccepts(
96
      const v8::FunctionCallbackInfo<v8::Value>& args);
97
#endif
98
};
99
100
101
}  // namespace node
102
103
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
104
105
#endif  // SRC_TCP_WRAP_H_