GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/src/stream_wrap.h Lines: 4 4 100.0 %
Date: 2016-07-12 Branches: 8 8 100.0 %

Line Exec Source
1
#ifndef SRC_STREAM_WRAP_H_
2
#define SRC_STREAM_WRAP_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "stream_base.h"
7
8
#include "env.h"
9
#include "handle_wrap.h"
10
#include "string_bytes.h"
11
#include "v8.h"
12
13
namespace node {
14
15
// Forward declaration
16
class StreamWrap;
17
18
class StreamWrap : public HandleWrap, public StreamBase {
19
 public:
20
  static void Initialize(v8::Local<v8::Object> target,
21
                         v8::Local<v8::Value> unused,
22
                         v8::Local<v8::Context> context);
23
24
  int GetFD() override;
25
  void* Cast() override;
26
  bool IsAlive() override;
27
  bool IsClosing() override;
28
  bool IsIPCPipe() override;
29
30
  // JavaScript functions
31
  int ReadStart() override;
32
  int ReadStop() override;
33
34
  // Resource implementation
35
  int DoShutdown(ShutdownWrap* req_wrap) override;
36
  int DoTryWrite(uv_buf_t** bufs, size_t* count) override;
37
  int DoWrite(WriteWrap* w,
38
              uv_buf_t* bufs,
39
              size_t count,
40
              uv_stream_t* send_handle) override;
41
42
  inline uv_stream_t* stream() const {
43
    return stream_;
44
  }
45
46
  inline bool is_named_pipe() const {
47
36495
    return stream()->type == UV_NAMED_PIPE;
48
  }
49
50
  inline bool is_named_pipe_ipc() const {
51
47134
    return is_named_pipe() &&
52
10639
           reinterpret_cast<const uv_pipe_t*>(stream())->ipc != 0;
53
  }
54
55
  inline bool is_tcp() const {
56
    return stream()->type == UV_TCP;
57
  }
58
59
 protected:
60
  StreamWrap(Environment* env,
61
             v8::Local<v8::Object> object,
62
             uv_stream_t* stream,
63
             AsyncWrap::ProviderType provider,
64
             AsyncWrap* parent = nullptr);
65
66
14002
  ~StreamWrap() {
67
  }
68
69
  AsyncWrap* GetAsyncWrap() override;
70
  void UpdateWriteQueueSize();
71
72
  static void AddMethods(Environment* env,
73
                         v8::Local<v8::FunctionTemplate> target,
74
                         int flags = StreamBase::kFlagNone);
75
76
 private:
77
  static void SetBlocking(const v8::FunctionCallbackInfo<v8::Value>& args);
78
79
  // Callbacks for libuv
80
  static void OnAlloc(uv_handle_t* handle,
81
                      size_t suggested_size,
82
                      uv_buf_t* buf);
83
84
  static void OnRead(uv_stream_t* handle,
85
                     ssize_t nread,
86
                     const uv_buf_t* buf);
87
  static void OnReadCommon(uv_stream_t* handle,
88
                           ssize_t nread,
89
                           const uv_buf_t* buf,
90
                           uv_handle_type pending);
91
  static void AfterWrite(uv_write_t* req, int status);
92
  static void AfterShutdown(uv_shutdown_t* req, int status);
93
94
  // Resource interface implementation
95
  static void OnAfterWriteImpl(WriteWrap* w, void* ctx);
96
  static void OnAllocImpl(size_t size, uv_buf_t* buf, void* ctx);
97
  static void OnReadImpl(ssize_t nread,
98
                         const uv_buf_t* buf,
99
                         uv_handle_type pending,
100
                         void* ctx);
101
102
  uv_stream_t* const stream_;
103
};
104
105
106
}  // namespace node
107
108
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
109
110
#endif  // SRC_STREAM_WRAP_H_