Skip to content

Commit

Permalink
Fix pingserver (#154)
Browse files Browse the repository at this point in the history
* add error handler to ping server

* allow 'ping' as an alternative to 'PING'

* use strncasecmp() which is better
  • Loading branch information
Yao Yue authored Apr 27, 2017
1 parent 43b4d29 commit 873ee6e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/protocol/data/ping/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ compose_req(struct buf **buf)
{
log_verb("composing request to buf %p", buf);

if (buf_wsize(*buf) < sizeof(REQUEST) && dbuf_double(buf) != CC_OK) {
if (buf_wsize(*buf) < REQ_LEN && dbuf_double(buf) != CC_OK) {
log_debug("failed to double buf %p");
INCR(compose_req_metrics, request_compose_ex);

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/data/ping/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ parse_req(struct buf *buf)
return PARSE_EUNFIN;
}

if (cc_memcmp(buf->rpos, REQUEST, REQ_LEN) == 0) {
if (strncasecmp(buf->rpos, REQUEST, REQ_LEN) == 0) {
buf->rpos += REQ_LEN;
INCR(parse_req_metrics, request_parse);
return PARSE_OK;
Expand Down
14 changes: 14 additions & 0 deletions src/server/pingserver/data/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@ pingserver_process_write(struct buf_sock *s)

return 0;
}

int
pingserver_process_error(struct buf_sock *s)
{
log_verb("post-error processing");

/* normalize buffer size */
buf_reset(s->rbuf);
dbuf_shrink(&s->rbuf);
buf_reset(s->wbuf);
dbuf_shrink(&s->wbuf);

return 0;
}
1 change: 1 addition & 0 deletions src/server/pingserver/data/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

int pingserver_process_read(struct buf_sock *s);
int pingserver_process_write(struct buf_sock *s);
int pingserver_process_error(struct buf_sock *s);
3 changes: 2 additions & 1 deletion src/server/pingserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

struct processor worker_processor = {
pingserver_process_read,
pingserver_process_write
pingserver_process_write,
pingserver_process_error,
};

static void
Expand Down

0 comments on commit 873ee6e

Please sign in to comment.