lws_get_ctx conversion
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
0161f01082
commit
8203be6742
15 changed files with 42 additions and 46 deletions
|
@ -347,6 +347,7 @@ lws_client_connect(struct lws_context *context, const char *address,
|
|||
if (wsi == NULL)
|
||||
goto bail;
|
||||
|
||||
wsi->context = context;
|
||||
wsi->sock = LWS_SOCK_INVALID;
|
||||
|
||||
/* -1 means just use latest supported */
|
||||
|
|
|
@ -326,7 +326,7 @@ spill:
|
|||
wsi->u.ws.ping_pending_flag = 1;
|
||||
|
||||
/* get it sent as soon as possible */
|
||||
lws_callback_on_writable(wsi->protocol->owning_server, wsi);
|
||||
lws_callback_on_writable(lws_get_ctx(wsi), wsi);
|
||||
ping_drop:
|
||||
wsi->u.ws.rx_user_buffer_head = 0;
|
||||
handled = 1;
|
||||
|
@ -403,7 +403,7 @@ ping_drop:
|
|||
if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
||||
lwsl_info("Client doing pong callback\n");
|
||||
|
||||
m = wsi->protocol->callback(wsi->protocol->owning_server,
|
||||
m = wsi->protocol->callback(lws_get_ctx(wsi),
|
||||
wsi, (enum lws_callback_reasons)callback_action,
|
||||
wsi->user_space, eff_buf.token, eff_buf.token_len);
|
||||
|
||||
|
|
|
@ -657,7 +657,7 @@ check_extensions:
|
|||
lwsl_ext("checking client ext %s\n", ext_name);
|
||||
|
||||
n = 0;
|
||||
ext = wsi->protocol->owning_server->extensions;
|
||||
ext = lws_get_ctx(wsi)->extensions;
|
||||
while (ext && ext->callback) {
|
||||
if (strcmp(ext_name, ext->name)) {
|
||||
ext++;
|
||||
|
@ -682,7 +682,7 @@ check_extensions:
|
|||
|
||||
/* allow him to construct his context */
|
||||
|
||||
ext->callback(wsi->protocol->owning_server, ext, wsi,
|
||||
ext->callback(lws_get_ctx(wsi), ext, wsi,
|
||||
LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
|
||||
wsi->active_extensions_user[
|
||||
wsi->count_active_extensions],
|
||||
|
|
|
@ -206,19 +206,13 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
|
||||
for (context->count_protocols = 0;
|
||||
info->protocols[context->count_protocols].callback;
|
||||
context->count_protocols++) {
|
||||
info->protocols[context->count_protocols].owning_server =
|
||||
context;
|
||||
info->protocols[context->count_protocols].protocol_index =
|
||||
context->count_protocols;
|
||||
|
||||
context->count_protocols++)
|
||||
/*
|
||||
* inform all the protocols that they are doing their one-time
|
||||
* initialization if they want to
|
||||
*/
|
||||
info->protocols[context->count_protocols].callback(context,
|
||||
NULL, LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* give all extensions a chance to create any per-context
|
||||
|
|
|
@ -50,7 +50,7 @@ int lws_ext_callback_for_each_active(struct lws *wsi, int reason,
|
|||
|
||||
for (n = 0; n < wsi->count_active_extensions; n++) {
|
||||
m = wsi->active_extensions[n]->callback(
|
||||
wsi->protocol->owning_server,
|
||||
lws_get_ctx(wsi),
|
||||
wsi->active_extensions[n], wsi,
|
||||
reason,
|
||||
wsi->active_extensions_user[n],
|
||||
|
@ -176,7 +176,7 @@ lws_issue_raw_ext_access(struct lws *wsi,
|
|||
* when he is ready to send and take care of it there
|
||||
*/
|
||||
lws_callback_on_writable(
|
||||
wsi->protocol->owning_server, wsi);
|
||||
lws_get_ctx(wsi), wsi);
|
||||
wsi->extension_data_pending = 1;
|
||||
ret = 0;
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ http_postbody:
|
|||
len -= body_chunk_len;
|
||||
|
||||
n = wsi->protocol->callback(
|
||||
wsi->protocol->owning_server, wsi,
|
||||
lws_get_ctx(wsi), wsi,
|
||||
LWS_CALLBACK_HTTP_BODY, wsi->user_space,
|
||||
buf, body_chunk_len);
|
||||
if (n)
|
||||
|
@ -166,7 +166,7 @@ http_postbody:
|
|||
postbody_completion:
|
||||
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
|
||||
n = wsi->protocol->callback(
|
||||
wsi->protocol->owning_server, wsi,
|
||||
lws_get_ctx(wsi), wsi,
|
||||
LWS_CALLBACK_HTTP_BODY_COMPLETION,
|
||||
wsi->user_space, NULL, 0);
|
||||
if (n)
|
||||
|
|
|
@ -935,6 +935,12 @@ lws_get_fops(struct lws_context *context)
|
|||
return &context->fops;
|
||||
}
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN struct lws_context *
|
||||
lws_get_ctx(struct lws *wsi)
|
||||
{
|
||||
return wsi->context;
|
||||
}
|
||||
|
||||
#ifdef LWS_WITH_OLD_API_WRAPPERS
|
||||
|
||||
/*
|
||||
|
|
|
@ -1197,9 +1197,6 @@ typedef int (extension_callback_function)(struct lws_context *context,
|
|||
* Accessible via lws_get_protocol(wsi)->user
|
||||
* This should not be confused with wsi->user, it is not the same.
|
||||
* The library completely ignores any value in here.
|
||||
* @owning_server: the server init call fills in this opaque pointer when
|
||||
* registering this protocol with the server.
|
||||
* @protocol_index: which protocol we are starting from zero
|
||||
*
|
||||
* This structure represents one protocol supported by the server. An
|
||||
* array of these structures is passed to lws_create_server()
|
||||
|
@ -1218,14 +1215,6 @@ struct lws_protocols {
|
|||
unsigned int id;
|
||||
void *user;
|
||||
|
||||
/*
|
||||
* below are filled in on server init and can be left uninitialized,
|
||||
* no need for user to use them directly either
|
||||
*/
|
||||
|
||||
struct lws_context *owning_server;
|
||||
int protocol_index;
|
||||
|
||||
/* Add new things just above here ---^
|
||||
* This is part of the ABI, don't needlessly break compatibilty */
|
||||
};
|
||||
|
@ -1640,6 +1629,9 @@ lws_hdr_copy(struct lws *wsi, char *dest, int len,
|
|||
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
|
||||
lws_get_fops(struct lws_context *context);
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN struct lws_context *
|
||||
lws_get_ctx(struct lws *wsi);
|
||||
|
||||
/*
|
||||
* File Operations access helpers
|
||||
*
|
||||
|
|
|
@ -35,7 +35,7 @@ void lws_conn::serialized_writeable(struct lws *_wsi)
|
|||
|
||||
lwsl_debug("%s: wsi %p\r\n", __func__, (void *)wsi);
|
||||
|
||||
lws_service_fd(wsi->protocol->owning_server, &pollfd);
|
||||
lws_service_fd(lws_get_ctx(wsi), &pollfd);
|
||||
}
|
||||
|
||||
extern "C" void mbed3_tcp_stream_bind(void *sock, int port, struct lws *wsi)
|
||||
|
@ -169,7 +169,7 @@ void lws_conn::onRX(Socket *s)
|
|||
|
||||
lwsl_debug("%s: lws %p\n", __func__, wsi);
|
||||
|
||||
lws_service_fd(wsi->protocol->owning_server, &pollfd);
|
||||
lws_service_fd(lws_get_ctx(wsi), &pollfd);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -201,7 +201,7 @@ void lws_conn_listener::onIncoming(TCPListener *tl, void *impl)
|
|||
* created. mbed3_tcp_stream_accept() is also called from
|
||||
* here to bind the conn and new wsi together
|
||||
*/
|
||||
lws_server_socket_service(wsi->protocol->owning_server,
|
||||
lws_server_socket_service(lws_get_ctx(wsi),
|
||||
wsi, (struct pollfd *)conn);
|
||||
|
||||
conn->ts->setOnError(TCPStream::ErrorHandler_t(conn, &lws_conn::onError));
|
||||
|
@ -281,7 +281,7 @@ void lws_conn::onSent(Socket *s, uint16_t len)
|
|||
|
||||
lwsl_debug("%s: wsi %p (servicing now)\r\n", __func__, (void *)wsi);
|
||||
|
||||
lws_service_fd(wsi->protocol->owning_server, &pollfd);
|
||||
lws_service_fd(lws_get_ctx(wsi), &pollfd);
|
||||
}
|
||||
|
||||
void lws_conn_listener::onError(Socket *s, socket_error_t err)
|
||||
|
@ -296,7 +296,7 @@ void lws_conn::onDisconnect(TCPStream *s)
|
|||
{
|
||||
lwsl_notice("%s:\r\n", __func__);
|
||||
(void)s;
|
||||
lws_close_and_free_session(wsi->protocol->owning_server, wsi,
|
||||
lws_close_and_free_session(lws_get_ctx(wsi), wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ lws_0405_frame_mask_generate(struct lws *wsi)
|
|||
|
||||
/* fetch the per-frame nonce */
|
||||
|
||||
n = lws_get_random(wsi->protocol->owning_server,
|
||||
n = lws_get_random(lws_get_ctx(wsi),
|
||||
wsi->u.ws.frame_masking_nonce_04, 4);
|
||||
if (n != 4) {
|
||||
lwsl_parser("Unable to read from random device %s %d\n",
|
||||
|
@ -90,7 +90,7 @@ LWS_VISIBLE void lwsl_hexdump(void *vbuf, size_t len)
|
|||
|
||||
int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
|
||||
{
|
||||
struct lws_context *context = wsi->protocol->owning_server;
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
size_t real_len = len;
|
||||
int n, m;
|
||||
|
||||
|
@ -157,7 +157,7 @@ handle_truncated_send:
|
|||
}
|
||||
}
|
||||
/* always callback on writeable */
|
||||
lws_callback_on_writable(wsi->protocol->owning_server, wsi);
|
||||
lws_callback_on_writable(lws_get_ctx(wsi), wsi);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ handle_truncated_send:
|
|||
memcpy(wsi->truncated_send_malloc, buf + n, real_len - n);
|
||||
|
||||
/* since something buffered, force it to get another chance to send */
|
||||
lws_callback_on_writable(wsi->protocol->owning_server, wsi);
|
||||
lws_callback_on_writable(lws_get_ctx(wsi), wsi);
|
||||
|
||||
return real_len;
|
||||
}
|
||||
|
|
|
@ -927,7 +927,7 @@ process_as_ping:
|
|||
wsi->u.ws.ping_pending_flag = 1;
|
||||
|
||||
/* get it sent as soon as possible */
|
||||
lws_callback_on_writable(wsi->protocol->owning_server, wsi);
|
||||
lws_callback_on_writable(lws_get_ctx(wsi), wsi);
|
||||
ping_drop:
|
||||
wsi->u.ws.rx_user_buffer_head = 0;
|
||||
return 0;
|
||||
|
@ -994,7 +994,7 @@ ping_drop:
|
|||
|
||||
ret = user_callback_handle_rxflow(
|
||||
wsi->protocol->callback,
|
||||
wsi->protocol->owning_server,
|
||||
lws_get_ctx(wsi),
|
||||
wsi,
|
||||
(enum lws_callback_reasons)callback_action,
|
||||
wsi->user_space,
|
||||
|
|
|
@ -141,7 +141,7 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or)
|
|||
if (!wsi || !wsi->protocol || wsi->position_in_fds_table < 0)
|
||||
return 1;
|
||||
|
||||
context = wsi->protocol->owning_server;
|
||||
context = lws_get_ctx(wsi);
|
||||
if (!context)
|
||||
return 1;
|
||||
|
||||
|
|
|
@ -836,6 +836,7 @@ struct lws {
|
|||
struct lws_io_watcher w_read;
|
||||
struct lws_io_watcher w_write;
|
||||
#endif /* LWS_USE_LIBEV */
|
||||
const struct lws_context *context;
|
||||
const struct lws_protocols *protocol;
|
||||
#ifndef LWS_NO_EXTENSIONS
|
||||
struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
|
||||
|
|
|
@ -75,7 +75,7 @@ lws_extension_server_handshake(struct lws_context *context,
|
|||
|
||||
/* check a client's extension against our support */
|
||||
|
||||
ext = wsi->protocol->owning_server->extensions;
|
||||
ext = lws_get_ctx(wsi)->extensions;
|
||||
|
||||
while (ext && ext->callback) {
|
||||
|
||||
|
@ -91,9 +91,9 @@ lws_extension_server_handshake(struct lws_context *context,
|
|||
* particular connection + protocol
|
||||
*/
|
||||
|
||||
n = wsi->protocol->owning_server->
|
||||
n = lws_get_ctx(wsi)->
|
||||
protocols[0].callback(
|
||||
wsi->protocol->owning_server,
|
||||
lws_get_ctx(wsi),
|
||||
wsi,
|
||||
LWS_CALLBACK_CONFIRM_EXTENSION_OKAY,
|
||||
wsi->user_space, ext_name, 0);
|
||||
|
@ -136,7 +136,7 @@ lws_extension_server_handshake(struct lws_context *context,
|
|||
|
||||
/* allow him to construct his context */
|
||||
|
||||
ext->callback(wsi->protocol->owning_server,
|
||||
ext->callback(lws_get_ctx(wsi),
|
||||
ext, wsi,
|
||||
LWS_EXT_CALLBACK_CONSTRUCT,
|
||||
wsi->active_extensions_user[
|
||||
|
@ -262,7 +262,7 @@ handshake_0405(struct lws_context *context, struct lws *wsi)
|
|||
/* notify user code that we're ready to roll */
|
||||
|
||||
if (wsi->protocol->callback)
|
||||
wsi->protocol->callback(wsi->protocol->owning_server,
|
||||
wsi->protocol->callback(lws_get_ctx(wsi),
|
||||
wsi, LWS_CALLBACK_ESTABLISHED,
|
||||
wsi->user_space,
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
|
|
|
@ -125,6 +125,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
compatible_close(sockfd);
|
||||
return 1;
|
||||
}
|
||||
wsi->context = context;
|
||||
wsi->sock = sockfd;
|
||||
wsi->mode = LWS_CONNMODE_SERVER_LISTENER;
|
||||
wsi->protocol = context->protocols;
|
||||
|
@ -151,7 +152,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
|
|||
int
|
||||
_lws_rx_flow_control(struct lws *wsi)
|
||||
{
|
||||
struct lws_context *context = wsi->protocol->owning_server;
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
|
||||
/* there is no pending change */
|
||||
if (!(wsi->rxflow_change_to & LWS_RXFLOW_PENDING_CHANGE))
|
||||
|
@ -523,7 +524,7 @@ upgrade_ws:
|
|||
* have the opportunity to deny it
|
||||
*/
|
||||
|
||||
if ((wsi->protocol->callback)(wsi->protocol->owning_server, wsi,
|
||||
if ((wsi->protocol->callback)(lws_get_ctx(wsi), wsi,
|
||||
LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
|
||||
wsi->user_space,
|
||||
lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) {
|
||||
|
@ -603,6 +604,7 @@ lws_create_new_server_wsi(struct lws_context *context)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
new_wsi->context = context;
|
||||
new_wsi->pending_timeout = NO_PENDING_TIMEOUT;
|
||||
new_wsi->rxflow_change_to = LWS_RXFLOW_ALLOW;
|
||||
|
||||
|
@ -769,7 +771,7 @@ try_pollout:
|
|||
if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE) {
|
||||
n = user_callback_handle_rxflow(
|
||||
wsi->protocol->callback,
|
||||
wsi->protocol->owning_server,
|
||||
lws_get_ctx(wsi),
|
||||
wsi, LWS_CALLBACK_HTTP_WRITEABLE,
|
||||
wsi->user_space,
|
||||
NULL,
|
||||
|
|
Loading…
Add table
Reference in a new issue