Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove w_stm_xxx accessor functions
Summary: Just call the methods on the stream instead.

Reviewed By: farnz

Differential Revision: D4183238

fbshipit-source-id: abf92e844ba8edb98c5c696b1bfb7a9ba0af321e
  • Loading branch information
wez authored and Facebook Github Bot committed Nov 29, 2016
1 parent b15cd8c commit 23cc507
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 72 deletions.
16 changes: 8 additions & 8 deletions json.cpp
Expand Up @@ -67,7 +67,7 @@ static bool fill_buffer(w_jbuffer_t *jr, w_stm_t stm)
}

errno = 0;
r = w_stm_read(stm, jr->buf + jr->wpos, avail);
r = stm->read(jr->buf + jr->wpos, avail);
if (r <= 0) {
return false;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ static json_ref read_bser_pdu(
jr->rpos += 2;

// We don't handle EAGAIN cleanly in here
w_stm_set_nonblock(stm, false);
stm->setNonBlock(false);
if (!w_bser_decode_pdu_info(jr, stm, bser_version, &val, &bser_capabilities,
jerr)) {
return nullptr;
Expand Down Expand Up @@ -238,7 +238,7 @@ static json_ref read_bser_pdu(

// We have enough room for the whole thing, let's read it in
while ((jr->wpos - jr->rpos) < val) {
r = w_stm_read(stm, jr->buf + jr->wpos, jr->allocd - jr->wpos);
r = stm->read(jr->buf + jr->wpos, jr->allocd - jr->wpos);
if (r <= 0) {
snprintf(jerr->text, sizeof(jerr->text),
"error reading PDU: %s",
Expand All @@ -253,7 +253,7 @@ static json_ref read_bser_pdu(
// Ensure that we move the read position to the wpos; we consumed it all
jr->rpos = jr->wpos;

w_stm_set_nonblock(stm, true);
stm->setNonBlock(true);
return obj;
}

Expand Down Expand Up @@ -365,7 +365,7 @@ static bool stream_n_bytes(w_jbuffer_t *jr, w_stm_t stm, json_int_t len,
}

avail = std::min((uint32_t)len, shunt_down(jr));
r = w_stm_read(stm, jr->buf + jr->wpos, avail);
r = stm->read(jr->buf + jr->wpos, avail);

if (r <= 0) {
snprintf(
Expand Down Expand Up @@ -437,7 +437,7 @@ bool w_json_buffer_passthru(w_jbuffer_t *jr,
json_error_t jerr;
bool res;

w_stm_set_nonblock(stm, false);
stm->setNonBlock(false);
if (!read_and_detect_pdu(jr, stm, &jerr)) {
w_log(W_LOG_ERR, "failed to identify PDU: %s\n",
jerr.text);
Expand Down Expand Up @@ -486,8 +486,8 @@ static bool jbuffer_flush(struct jbuffer_write_data *data)
int x;

while (data->jr->wpos - data->jr->rpos) {
x = w_stm_write(data->stm, data->jr->buf + data->jr->rpos,
data->jr->wpos - data->jr->rpos);
x = data->stm->write(
data->jr->buf + data->jr->rpos, data->jr->wpos - data->jr->rpos);

if (x <= 0) {
return false;
Expand Down
56 changes: 0 additions & 56 deletions stream.cpp
Expand Up @@ -12,59 +12,3 @@ std::unique_ptr<watchman_stream> w_stm_connect(
return w_stm_connect_unix(path, timeoutms);
#endif
}

int w_stm_read(w_stm_t stm, void *buf, int size) {
if (!stm) {
errno = EBADF;
return -1;
}
return stm->read(buf, size);
}

int w_stm_write(w_stm_t stm, const void *buf, int size) {
if (!stm) {
errno = EBADF;
return -1;
}
return stm->write(buf, size);
}

void w_stm_get_events(w_stm_t stm, w_evt_t *readable) {
if (!stm) {
errno = EBADF;
return;
}
*readable = stm->getEvents();
}

void w_stm_set_nonblock(w_stm_t stm, bool nonb) {
if (!stm) {
errno = EBADF;
return;
}
stm->setNonBlock(nonb);
}

bool w_stm_rewind(w_stm_t stm) {
if (!stm) {
errno = EBADF;
return false;
}
return stm->rewind();
}

bool w_stm_shutdown(w_stm_t stm) {
if (!stm) {
errno = EBADF;
return false;
}
return stm->shutdown();
}

bool w_stm_peer_is_owner(w_stm_t stm) {
if (!stm) {
errno = EBADF;
return false;
}
return stm->peerIsOwner();
}
8 changes: 0 additions & 8 deletions watchman_stream.h
Expand Up @@ -44,14 +44,6 @@ int w_poll_events(struct watchman_event_poll *p, int n, int timeoutms);
// Create a connected unix socket or a named pipe client stream
std::unique_ptr<watchman_stream> w_stm_connect(const char* path, int timeoutms);

int w_stm_read(w_stm_t stm, void *buf, int size);
int w_stm_write(w_stm_t stm, const void *buf, int size);
void w_stm_get_events(w_stm_t stm, w_evt_t *readable);
void w_stm_set_nonblock(w_stm_t stm, bool nonb);
bool w_stm_rewind(w_stm_t stm);
bool w_stm_shutdown(w_stm_t stm);
bool w_stm_peer_is_owner(w_stm_t stm);

w_stm_t w_stm_stdout(void);
w_stm_t w_stm_stdin(void);
#ifndef _WIN32
Expand Down

0 comments on commit 23cc507

Please sign in to comment.