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 Aug 21, 2018
1 parent d396540 commit 28a7c64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
16 changes: 3 additions & 13 deletions src/uwsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ static void uwsc_free(struct uwsc_client *cl)

static inline void uwsc_error(struct uwsc_client *cl, int error)
{
uwsc_log_err("uwsc_error: %i\n", error);

cl->us->eof = true;
cl->error = error;

Expand All @@ -74,11 +72,10 @@ static void dispach_message(struct uwsc_client *cl)
uloop_timeout_set(&cl->ping_timer, cl->ping_interval * 1000);
break;
case WEBSOCKET_OP_CLOSE:
uwsc_log_err("dispach_message: WEBSOCKET_OP_CLOSE\n");
uwsc_error(cl, 0);
uwsc_error(cl, UWSC_ERROR_CLOSED_BY_SERVER);
break;
default:
uwsc_log_err("dispach_message: default - %i\n", frame->opcode);
uwsc_log_err("dispach_message: Invalid opcode - %d\n", frame->opcode);
break;
}
}
Expand Down Expand Up @@ -429,15 +426,11 @@ static int uwsc_send(struct uwsc_client *cl, void *data, int len, enum websocket
ustream_write(cl->us, data, len, false);
free(head);

//if (op == WEBSOCKET_OP_CLOSE)
// uwsc_error(cl, 0);

return 0;
}

static inline void uwsc_ping(struct uwsc_client *cl)
{
uwsc_log_info("Ping server\n");
cl->send(cl, NULL, 0, WEBSOCKET_OP_PING);
}

Expand Down Expand Up @@ -470,9 +463,7 @@ static void uwsc_ping_cb(struct uloop_timeout *timeout)
struct uwsc_client *cl = container_of(timeout, struct uwsc_client, ping_timer);

if (cl->wait_pingresp) {
uwsc_log_err("Ping server, no response\n");
uwsc_error(cl, 0);
uwsc_log_err("Send WEBSOCKET_OP_CLOSE complete\n");
uwsc_error(cl, UWSC_ERROR_PING_TIMEOUT);
return;
}

Expand Down Expand Up @@ -591,4 +582,3 @@ struct uwsc_client *uwsc_new_ssl(const char *url, const char *ca_crt_file, bool

return NULL;
}

4 changes: 3 additions & 1 deletion src/uwsc.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ enum uwsc_error_code {
UWSC_ERROR_SSL_CN_MISMATCH,
UWSC_ERROR_SERVER_MASKED,
UWSC_ERROR_NOMEM,
UWSC_ERROR_NOT_SUPPORT
UWSC_ERROR_NOT_SUPPORT,
UWSC_ERROR_PING_TIMEOUT,
UWSC_ERROR_CLOSED_BY_SERVER
};

enum client_state {
Expand Down

0 comments on commit 28a7c64

Please sign in to comment.