mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
change-client-mode-to-enum.patch
Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
parent
1efb63c2be
commit
f3d3b40364
5 changed files with 30 additions and 10 deletions
|
@ -534,7 +534,7 @@ check_accept:
|
|||
this->fds[this->fds_count++].events = POLLIN;
|
||||
|
||||
wsi->state = WSI_STATE_ESTABLISHED;
|
||||
wsi->client_mode = 1;
|
||||
wsi->mode = LWS_CONNMODE_WS_CLIENT;
|
||||
|
||||
fprintf(stderr, "handshake OK for protocol %s\n", wsi->protocol->name);
|
||||
|
||||
|
|
|
@ -463,12 +463,17 @@ libwebsocket_read(struct libwebsocket *wsi, unsigned char * buf, size_t len)
|
|||
fwrite(buf, 1, len, stderr);
|
||||
#endif
|
||||
|
||||
if (wsi->client_mode) {
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_WS_CLIENT:
|
||||
for (n = 0; n < len; n++)
|
||||
libwebsocket_client_rx_sm(wsi, *buf++);
|
||||
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* LWS_CONNMODE_WS_SERVING */
|
||||
|
||||
for (n = 0; n < len; n++)
|
||||
libwebsocket_parse(wsi, *buf++);
|
||||
|
@ -557,13 +562,18 @@ libwebsocket_read(struct libwebsocket *wsi, unsigned char * buf, size_t len)
|
|||
break;
|
||||
|
||||
case WSI_STATE_ESTABLISHED:
|
||||
if (wsi->client_mode) {
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_WS_CLIENT:
|
||||
for (n = 0; n < len; n++)
|
||||
libwebsocket_client_rx_sm(wsi, *buf++);
|
||||
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* LWS_CONNMODE_WS_SERVING */
|
||||
|
||||
if (libwebsocket_interpret_incoming_packet(wsi, buf, len) < 0)
|
||||
goto bail;
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ libwebsocket_poll_connections(struct libwebsocket_context *this)
|
|||
|
||||
/* only to clients connected to us */
|
||||
|
||||
if (wsi->client_mode)
|
||||
if (wsi->mode != LWS_CONNMODE_WS_SERVING)
|
||||
continue;
|
||||
|
||||
/*
|
||||
|
@ -223,10 +223,14 @@ libwebsocket_context_destroy(struct libwebsocket_context *this)
|
|||
|
||||
/* close listening skt and per-protocol broadcast sockets */
|
||||
for (client = this->count_protocols + 1; client < this->fds_count; client++)
|
||||
if (this->wsi[client]->client_mode)
|
||||
libwebsocket_client_close(this->wsi[client]);
|
||||
else
|
||||
switch (this->wsi[client]->mode) {
|
||||
case LWS_CONNMODE_WS_SERVING:
|
||||
libwebsocket_close_and_free_session(this->wsi[client]);
|
||||
break;
|
||||
case LWS_CONNMODE_WS_CLIENT:
|
||||
libwebsocket_client_close(this->wsi[client]);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
if (this->ssl_ctx)
|
||||
|
@ -397,7 +401,7 @@ libwebsocket_service(struct libwebsocket_context *this, int timeout_ms)
|
|||
this->wsi[this->fds_count]->sock = fd;
|
||||
this->wsi[this->fds_count]->state = WSI_STATE_HTTP;
|
||||
this->wsi[this->fds_count]->name_buffer_pos = 0;
|
||||
this->wsi[this->fds_count]->client_mode = 0;
|
||||
this->wsi[this->fds_count]->mode = LWS_CONNMODE_WS_SERVING;
|
||||
|
||||
for (n = 0; n < WSI_TOKEN_COUNT; n++) {
|
||||
this->wsi[this->fds_count]->
|
||||
|
|
|
@ -1138,7 +1138,8 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
|
|||
* Deal with masking if appropriate
|
||||
*/
|
||||
|
||||
if (wsi->client_mode && wsi->ietf_spec_revision == 4) {
|
||||
if (wsi->mode == LWS_CONNMODE_WS_CLIENT &&
|
||||
wsi->ietf_spec_revision == 4) {
|
||||
|
||||
/*
|
||||
* this is only useful for security tests where it's required
|
||||
|
|
|
@ -182,6 +182,11 @@ struct libwebsocket_context {
|
|||
int count_protocols;
|
||||
};
|
||||
|
||||
enum connection_mode {
|
||||
LWS_CONNMODE_WS_SERVING,
|
||||
LWS_CONNMODE_WS_CLIENT,
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* This is totally opaque to code using the library. It's exported as a
|
||||
|
@ -222,7 +227,7 @@ struct libwebsocket {
|
|||
|
||||
/* client support */
|
||||
char initial_handshake_hash_base64[30];
|
||||
int client_mode;
|
||||
enum connection_mode mode;
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
SSL *ssl;
|
||||
|
|
Loading…
Add table
Reference in a new issue