Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
  • Loading branch information
Jianhui Zhao committed Jun 18, 2018
1 parent 09a7fe4 commit d1b3276
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/uwsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ static inline void uwsc_error(struct uwsc_client *cl, int error)
{
cl->us->eof = true;
cl->error = error;

cl->send(cl, NULL, 0, WEBSOCKET_OP_CLOSE);
ustream_state_change(cl->us);
}

Expand Down Expand Up @@ -92,8 +94,7 @@ static bool parse_frame(struct uwsc_client *cl, uint8_t *data, uint64_t len)

if (data[1] & 0x80) {
uwsc_log_err("Masked error");
cl->send(cl, NULL, 0, WEBSOCKET_OP_CLOSE);
cl->error = UWSC_ERROR_SERVER_MASKED;
uwsc_error(cl, UWSC_ERROR_SERVER_MASKED);
return false;
}

Expand Down Expand Up @@ -131,8 +132,7 @@ static bool parse_frame(struct uwsc_client *cl, uint8_t *data, uint64_t len)
frame->payload = realloc(frame->payload, new_len);
if (!frame->payload) {
uwsc_log_err("No mem");
cl->send(cl, NULL, 0, WEBSOCKET_OP_CLOSE);
cl->error = UWSC_ERROR_NOMEM;
uwsc_error(cl, UWSC_ERROR_NOMEM);
return false;
}

Expand All @@ -149,8 +149,7 @@ static bool parse_frame(struct uwsc_client *cl, uint8_t *data, uint64_t len)
frame->payload = malloc(payloadlen);
if (!frame->payload) {
uwsc_log_err("No mem");
cl->send(cl, NULL, 0, WEBSOCKET_OP_CLOSE);
cl->error = UWSC_ERROR_NOMEM;
uwsc_error(cl, UWSC_ERROR_NOMEM);
return false;
}
memcpy(frame->payload, payload, payloadlen);
Expand Down

0 comments on commit d1b3276

Please sign in to comment.