GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/stream_wrap.h Lines: 11 11 100.0 %
Date: 2017-10-21 Branches: 5 6 83.3 %

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_STREAM_WRAP_H_
23
#define SRC_STREAM_WRAP_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include "stream_base.h"
28
29
#include "env.h"
30
#include "handle_wrap.h"
31
#include "string_bytes.h"
32
#include "v8.h"
33
34
namespace node {
35
36
class LibuvStreamWrap : public HandleWrap, public StreamBase {
37
 public:
38
  static void Initialize(v8::Local<v8::Object> target,
39
                         v8::Local<v8::Value> unused,
40
                         v8::Local<v8::Context> context);
41
42
  int GetFD() override;
43
  void* Cast() override;
44
  bool IsAlive() override;
45
  bool IsClosing() override;
46
  bool IsIPCPipe() override;
47
48
  // JavaScript functions
49
  int ReadStart() override;
50
  int ReadStop() override;
51
52
  // Resource implementation
53
  int DoShutdown(ShutdownWrap* req_wrap) override;
54
  int DoTryWrite(uv_buf_t** bufs, size_t* count) override;
55
  int DoWrite(WriteWrap* w,
56
              uv_buf_t* bufs,
57
              size_t count,
58
              uv_stream_t* send_handle) override;
59
60
289365
  inline uv_stream_t* stream() const {
61
289365
    return stream_;
62
  }
63
64
69663
  inline bool is_named_pipe() const {
65
69663
    return stream()->type == UV_NAMED_PIPE;
66
  }
67
68
64198
  inline bool is_named_pipe_ipc() const {
69

97748
    return is_named_pipe() &&
70
97748
           reinterpret_cast<const uv_pipe_t*>(stream())->ipc != 0;
71
  }
72
73
25614
  inline bool is_tcp() const {
74
25614
    return stream()->type == UV_TCP;
75
  }
76
77
 protected:
78
  LibuvStreamWrap(Environment* env,
79
                  v8::Local<v8::Object> object,
80
                  uv_stream_t* stream,
81
                  AsyncWrap::ProviderType provider);
82
83
8332
  ~LibuvStreamWrap() {
84
8332
  }
85
86
  AsyncWrap* GetAsyncWrap() override;
87
  uint32_t UpdateWriteQueueSize();
88
89
  static void AddMethods(Environment* env,
90
                         v8::Local<v8::FunctionTemplate> target,
91
                         int flags = StreamBase::kFlagNone);
92
93
 private:
94
  static void UpdateWriteQueueSize(
95
      const v8::FunctionCallbackInfo<v8::Value>& args);
96
  static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args);
97
98
  // Callbacks for libuv
99
  static void OnAlloc(uv_handle_t* handle,
100
                      size_t suggested_size,
101
                      uv_buf_t* buf);
102
103
  static void OnRead(uv_stream_t* handle,
104
                     ssize_t nread,
105
                     const uv_buf_t* buf);
106
  static void AfterWrite(uv_write_t* req, int status);
107
  static void AfterShutdown(uv_shutdown_t* req, int status);
108
109
  // Resource interface implementation
110
  static void OnAfterWriteImpl(WriteWrap* w, void* ctx);
111
  static void OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx);
112
  static void OnReadImpl(ssize_t nread,
113
                         const uv_buf_t* buf,
114
                         uv_handle_type pending,
115
                         void* ctx);
116
117
  uv_stream_t* const stream_;
118
};
119
120
121
}  // namespace node
122
123
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
124
125
#endif  // SRC_STREAM_WRAP_H_