diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index 10e70bfaa6..ea8aaecacc 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -107,10 +107,8 @@ void StreamWrap::ReadStart(const FunctionCallbackInfo& args) { UNWRAP(StreamWrap) - bool ipc_pipe = wrap->stream()->type == UV_NAMED_PIPE && - reinterpret_cast(wrap->stream())->ipc; int err; - if (ipc_pipe) { + if (wrap->is_named_pipe_ipc()) { err = uv_read2_start(wrap->stream(), OnAlloc, OnRead2); } else { err = uv_read_start(wrap->stream(), OnAlloc, OnRead); @@ -172,9 +170,9 @@ void StreamWrap::OnReadCommon(uv_stream_t* handle, assert(wrap->persistent().IsEmpty() == false); if (nread > 0) { - if (wrap->stream()->type == UV_TCP) { + if (wrap->is_tcp()) { NODE_COUNT_NET_BYTES_RECV(nread); - } else if (wrap->stream()->type == UV_NAMED_PIPE) { + } else if (wrap->is_named_pipe()) { NODE_COUNT_PIPE_BYTES_RECV(nread); } } @@ -285,10 +283,7 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo& args) { buf.base = data; buf.len = data_size; - bool ipc_pipe = wrap->stream()->type == UV_NAMED_PIPE && - reinterpret_cast(wrap->stream())->ipc; - - if (!ipc_pipe) { + if (!wrap->is_named_pipe_ipc()) { err = wrap->callbacks()->DoWrite(req_wrap, &buf, 1, diff --git a/src/stream_wrap.h b/src/stream_wrap.h index 25aff8b8d3..7f8f74af9f 100644 --- a/src/stream_wrap.h +++ b/src/stream_wrap.h @@ -130,6 +130,19 @@ class StreamWrap : public HandleWrap { return stream_; } + inline bool is_named_pipe() const { + return stream()->type == UV_NAMED_PIPE; + } + + inline bool is_named_pipe_ipc() const { + return is_named_pipe() && + reinterpret_cast(stream())->ipc != 0; + } + + inline bool is_tcp() const { + return stream()->type == UV_TCP; + } + protected: static size_t WriteBuffer(v8::Handle val, uv_buf_t* buf); diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 66dfd6e4a0..3cc169ec5c 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -398,9 +398,9 @@ void TLSCallbacks::EncOut() { // Ignore errors, this should be already handled in js if (!r) { - if (wrap()->stream()->type == UV_TCP) { + if (wrap()->is_tcp()) { NODE_COUNT_NET_BYTES_SENT(write_size_); - } else if (wrap()->stream()->type == UV_NAMED_PIPE) { + } else if (wrap()->is_named_pipe()) { NODE_COUNT_PIPE_BYTES_SENT(write_size_); } }