Browse Source

stream_wrap: add handle type checkers

Add is_named_pipe(), is_named_pipe_ipc() and is_tcp() and update the
code base to use those rather than `stream->type == UV_FOO` and
`reinterpret_cast<uv_pipe_t*>(handle)->ipc` style checks.
v0.11.6-release
Ben Noordhuis 12 years ago
parent
commit
54a9ec4ef0
  1. 13
      src/stream_wrap.cc
  2. 13
      src/stream_wrap.h
  3. 4
      src/tls_wrap.cc

13
src/stream_wrap.cc

@ -107,10 +107,8 @@ void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) {
UNWRAP(StreamWrap)
bool ipc_pipe = wrap->stream()->type == UV_NAMED_PIPE &&
reinterpret_cast<uv_pipe_t*>(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<Value>& args) {
buf.base = data;
buf.len = data_size;
bool ipc_pipe = wrap->stream()->type == UV_NAMED_PIPE &&
reinterpret_cast<uv_pipe_t*>(wrap->stream())->ipc;
if (!ipc_pipe) {
if (!wrap->is_named_pipe_ipc()) {
err = wrap->callbacks()->DoWrite(req_wrap,
&buf,
1,

13
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<const uv_pipe_t*>(stream())->ipc != 0;
}
inline bool is_tcp() const {
return stream()->type == UV_TCP;
}
protected:
static size_t WriteBuffer(v8::Handle<v8::Value> val, uv_buf_t* buf);

4
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_);
}
}

Loading…
Cancel
Save