mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
lws_get_context not _ctx
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
54806b1541
commit
6d64539fcb
18 changed files with 38 additions and 38 deletions
|
@ -134,7 +134,7 @@ Since almost all apis no longer need the context as a parameter, it's no longer
|
|||
provided at the user callback directly.
|
||||
|
||||
However if you need it, for ALL callbacks wsi is valid and has a valid context
|
||||
pointer you can recover using lws_get_ctx(wsi).
|
||||
pointer you can recover using lws_get_context(wsi).
|
||||
|
||||
|
||||
v1.5-chrome47-firefox41
|
||||
|
|
|
@ -650,7 +650,7 @@ check_extensions:
|
|||
lwsl_ext("checking client ext %s\n", ext_name);
|
||||
|
||||
n = 0;
|
||||
ext = lws_get_ctx(wsi)->extensions;
|
||||
ext = lws_get_context(wsi)->extensions;
|
||||
while (ext && ext->callback) {
|
||||
if (strcmp(ext_name, ext->name)) {
|
||||
ext++;
|
||||
|
@ -675,7 +675,7 @@ check_extensions:
|
|||
|
||||
/* allow him to construct his context */
|
||||
|
||||
ext->callback(lws_get_ctx(wsi), ext, wsi,
|
||||
ext->callback(lws_get_context(wsi), ext, wsi,
|
||||
LWS_EXT_CALLBACK_CLIENT_CONSTRUCT,
|
||||
wsi->active_extensions_user[
|
||||
wsi->count_active_extensions],
|
||||
|
|
|
@ -216,7 +216,7 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
* initialization if they want to.
|
||||
*
|
||||
* NOTE the wsi is all zeros except for the context pointer
|
||||
* so lws_get_ctx(wsi) can work in the callback.
|
||||
* so lws_get_context(wsi) can work in the callback.
|
||||
*/
|
||||
info->protocols[context->count_protocols].callback(&wsi,
|
||||
LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
|
||||
|
|
|
@ -49,7 +49,7 @@ int lws_ext_cb_wsi_active_exts(struct lws *wsi, int reason, void *arg, int len)
|
|||
|
||||
for (n = 0; n < wsi->count_active_extensions; n++) {
|
||||
m = wsi->active_extensions[n]->callback(
|
||||
lws_get_ctx(wsi),
|
||||
lws_get_context(wsi),
|
||||
wsi->active_extensions[n], wsi,
|
||||
reason,
|
||||
wsi->active_extensions_user[n],
|
||||
|
|
|
@ -176,7 +176,7 @@ LWS_VISIBLE int
|
|||
lws_return_http_status(struct lws *wsi, unsigned int code, const char *html_body)
|
||||
{
|
||||
int n, m;
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
struct lws_context *context = lws_get_context(wsi);
|
||||
unsigned char *p = context->serv_buf +
|
||||
LWS_SEND_BUFFER_PRE_PADDING;
|
||||
unsigned char *start = p;
|
||||
|
|
|
@ -135,7 +135,7 @@ lws_initloop(
|
|||
LWS_VISIBLE void
|
||||
lws_libev_accept(struct lws *new_wsi, int accept_fd)
|
||||
{
|
||||
struct lws_context *context = lws_get_ctx(new_wsi);
|
||||
struct lws_context *context = lws_get_context(new_wsi);
|
||||
struct ev_io *r = &new_wsi->w_read.watcher;
|
||||
struct ev_io *w = &new_wsi->w_write.watcher;
|
||||
|
||||
|
@ -151,7 +151,7 @@ lws_libev_accept(struct lws *new_wsi, int accept_fd)
|
|||
LWS_VISIBLE void
|
||||
lws_libev_io(struct lws *wsi, int flags)
|
||||
{
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
struct lws_context *context = lws_get_context(wsi);
|
||||
|
||||
if (!LWS_LIBEV_ENABLED(context))
|
||||
return;
|
||||
|
|
|
@ -927,7 +927,7 @@ lws_get_fops(struct lws_context *context)
|
|||
}
|
||||
|
||||
LWS_VISIBLE LWS_EXTERN struct lws_context *
|
||||
lws_get_ctx(const struct lws *wsi)
|
||||
lws_get_context(const struct lws *wsi)
|
||||
{
|
||||
return wsi->context;
|
||||
}
|
||||
|
|
|
@ -1581,7 +1581,7 @@ 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(const struct lws *wsi);
|
||||
lws_get_context(const struct lws *wsi);
|
||||
|
||||
/*
|
||||
* Wsi-associated File Operations access helpers
|
||||
|
@ -1602,34 +1602,34 @@ static LWS_INLINE lws_filefd_type
|
|||
lws_plat_file_open(struct lws *wsi, const char *filename,
|
||||
unsigned long *filelen, int flags)
|
||||
{
|
||||
return lws_get_fops(lws_get_ctx(wsi))->open(wsi, filename,
|
||||
return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
|
||||
filelen, flags);
|
||||
}
|
||||
|
||||
static LWS_INLINE int
|
||||
lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
|
||||
{
|
||||
return lws_get_fops(lws_get_ctx(wsi))->close(wsi, fd);
|
||||
return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
|
||||
}
|
||||
|
||||
static LWS_INLINE unsigned long
|
||||
lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
|
||||
{
|
||||
return lws_get_fops(lws_get_ctx(wsi))->seek_cur(wsi, fd, offset);
|
||||
return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
|
||||
}
|
||||
|
||||
static LWS_INLINE int
|
||||
lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
|
||||
unsigned char *buf, unsigned long len)
|
||||
{
|
||||
return lws_get_fops(lws_get_ctx(wsi))->read(wsi, fd, amount, buf, len);
|
||||
return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf, len);
|
||||
}
|
||||
|
||||
static LWS_INLINE int
|
||||
lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
|
||||
unsigned char *buf, unsigned long len)
|
||||
{
|
||||
return lws_get_fops(lws_get_ctx(wsi))->write(wsi, fd, amount, buf, len);
|
||||
return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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(lws_get_ctx(wsi), &pollfd);
|
||||
lws_service_fd(lws_get_context(wsi), &pollfd);
|
||||
}
|
||||
|
||||
extern "C" void mbed3_tcp_stream_bind(void *sock, int port, struct lws *wsi)
|
||||
|
@ -167,7 +167,7 @@ void lws_conn::onRX(Socket *s)
|
|||
|
||||
lwsl_debug("%s: lws %p\n", __func__, wsi);
|
||||
|
||||
lws_service_fd(lws_get_ctx(wsi), &pollfd);
|
||||
lws_service_fd(lws_get_context(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(lws_get_ctx(wsi),
|
||||
lws_server_socket_service(lws_get_context(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(lws_get_ctx(wsi), &pollfd);
|
||||
lws_service_fd(lws_get_context(wsi), &pollfd);
|
||||
}
|
||||
|
||||
void lws_conn_listener::onError(Socket *s, socket_error_t err)
|
||||
|
|
|
@ -28,7 +28,7 @@ lws_0405_frame_mask_generate(struct lws *wsi)
|
|||
|
||||
/* fetch the per-frame nonce */
|
||||
|
||||
n = lws_get_random(lws_get_ctx(wsi), wsi->u.ws.mask_nonce, 4);
|
||||
n = lws_get_random(lws_get_context(wsi), wsi->u.ws.mask_nonce, 4);
|
||||
if (n != 4) {
|
||||
lwsl_parser("Unable to read from random device %s %d\n",
|
||||
SYSTEM_RANDOM_FILEPATH, n);
|
||||
|
@ -89,7 +89,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 = lws_get_ctx(wsi);
|
||||
struct lws_context *context = lws_get_context(wsi);
|
||||
size_t real_len = len;
|
||||
int n, m;
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or)
|
|||
if (!wsi || !wsi->protocol || wsi->position_in_fds_table < 0)
|
||||
return 1;
|
||||
|
||||
context = lws_get_ctx(wsi);
|
||||
context = lws_get_context(wsi);
|
||||
if (!context)
|
||||
return 1;
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p)
|
|||
|
||||
/* check a client's extension against our support */
|
||||
|
||||
ext = lws_get_ctx(wsi)->extensions;
|
||||
ext = lws_get_context(wsi)->extensions;
|
||||
|
||||
while (ext && ext->callback) {
|
||||
|
||||
|
@ -90,7 +90,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p)
|
|||
* particular connection + protocol
|
||||
*/
|
||||
|
||||
n = lws_get_ctx(wsi)->protocols[0].callback(wsi,
|
||||
n = lws_get_context(wsi)->protocols[0].callback(wsi,
|
||||
LWS_CALLBACK_CONFIRM_EXTENSION_OKAY,
|
||||
wsi->user_space, ext_name, 0);
|
||||
|
||||
|
@ -131,7 +131,7 @@ lws_extension_server_handshake(struct lws *wsi, char **p)
|
|||
|
||||
/* allow him to construct his context */
|
||||
|
||||
ext->callback(lws_get_ctx(wsi),
|
||||
ext->callback(lws_get_context(wsi),
|
||||
ext, wsi,
|
||||
LWS_EXT_CALLBACK_CONSTRUCT,
|
||||
wsi->active_extensions_user[
|
||||
|
|
|
@ -334,7 +334,7 @@ bail_nuke_ah:
|
|||
|
||||
int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
|
||||
{
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
struct lws_context *context = lws_get_context(wsi);
|
||||
struct allocated_headers *ah;
|
||||
int protocol_len, n, hit;
|
||||
char protocol_list[128];
|
||||
|
@ -895,7 +895,7 @@ LWS_VISIBLE int lws_serve_http_file(struct lws *wsi, const char *file,
|
|||
const char *other_headers,
|
||||
int other_headers_len)
|
||||
{
|
||||
struct lws_context *context = lws_get_ctx(wsi);
|
||||
struct lws_context *context = lws_get_context(wsi);
|
||||
unsigned char *response = context->serv_buf +
|
||||
LWS_SEND_BUFFER_PRE_PADDING;
|
||||
unsigned char *p = response;
|
||||
|
|
|
@ -75,7 +75,7 @@ lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
|
|||
switch (wsi->pps) {
|
||||
case LWS_PPS_HTTP2_MY_SETTINGS:
|
||||
case LWS_PPS_HTTP2_ACK_SETTINGS:
|
||||
lws_http2_do_pps_send(lws_get_ctx(wsi), wsi);
|
||||
lws_http2_do_pps_send(lws_get_context(wsi), wsi);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -70,7 +70,7 @@ OpenSSL_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||
context = SSL_get_ex_data(ssl, openssl_websocket_private_data_index);
|
||||
|
||||
/*
|
||||
* give him a fake wsi with context set, so he can use lws_get_ctx()
|
||||
* give him a fake wsi with context set, so he can use lws_get_context()
|
||||
* in the callback
|
||||
*/
|
||||
memset(&wsi, 0, sizeof(wsi));
|
||||
|
@ -118,7 +118,7 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
|
|||
|
||||
/*
|
||||
* give him a fake wsi with context set, so he can use
|
||||
* lws_get_ctx() in the callback
|
||||
* lws_get_context() in the callback
|
||||
*/
|
||||
memset(&wsi, 0, sizeof(wsi));
|
||||
wsi.context = context;
|
||||
|
@ -408,7 +408,7 @@ int lws_context_init_client_ssl(struct lws_context_creation_info *info,
|
|||
|
||||
/*
|
||||
* give him a fake wsi with context set, so he can use
|
||||
* lws_get_ctx() in the callback
|
||||
* lws_get_context() in the callback
|
||||
*/
|
||||
memset(&wsi, 0, sizeof(wsi));
|
||||
wsi.context = context;
|
||||
|
|
|
@ -145,7 +145,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
lwsl_notice("mirror: LWS_CALLBACK_CLIENT_ESTABLISHED\n");
|
||||
|
||||
lws_get_random(lws_get_ctx(wsi), rands, sizeof(rands[0]));
|
||||
lws_get_random(lws_get_context(wsi), rands, sizeof(rands[0]));
|
||||
mirror_lifetime = 16384 + (rands[0] & 65535);
|
||||
/* useful to test single connection stability */
|
||||
if (longlived)
|
||||
|
@ -173,7 +173,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
case LWS_CALLBACK_CLIENT_WRITEABLE:
|
||||
for (n = 0; n < 1; n++) {
|
||||
lws_get_random(lws_get_ctx(wsi), rands, sizeof(rands));
|
||||
lws_get_random(lws_get_context(wsi), rands, sizeof(rands));
|
||||
l += sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING + l],
|
||||
"c #%06X %d %d %d;",
|
||||
(int)rands[0] & 0xffffff,
|
||||
|
|
|
@ -134,7 +134,7 @@ callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
switch (psf->state) {
|
||||
|
||||
case FRAGSTATE_START_MESSAGE:
|
||||
lws_get_random(lws_get_ctx(wsi), &ran, sizeof(ran));
|
||||
lws_get_random(lws_get_context(wsi), &ran, sizeof(ran));
|
||||
psf->packets_left = (ran % 1024) + 1;
|
||||
fprintf(stderr, "Spamming %d random fragments\n",
|
||||
psf->packets_left);
|
||||
|
@ -153,11 +153,11 @@ callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
* code for rx spill because the rx buffer is full
|
||||
*/
|
||||
|
||||
lws_get_random(lws_get_ctx(wsi), &ran, sizeof(ran));
|
||||
lws_get_random(lws_get_context(wsi), &ran, sizeof(ran));
|
||||
chunk = (ran % 8000) + 1;
|
||||
psf->total_message += chunk;
|
||||
|
||||
lws_get_random(lws_get_ctx(wsi), bp, chunk);
|
||||
lws_get_random(lws_get_context(wsi), bp, chunk);
|
||||
for (n = 0; n < chunk; n++)
|
||||
psf->sum += bp[n];
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
if (((ringbuffer_head - pss->ringbuffer_tail) &
|
||||
(MAX_MESSAGE_QUEUE - 1)) == (MAX_MESSAGE_QUEUE - 15))
|
||||
lws_rx_flow_allow_all_protocol(lws_get_ctx(wsi),
|
||||
lws_rx_flow_allow_all_protocol(lws_get_context(wsi),
|
||||
lws_get_protocol(wsi));
|
||||
|
||||
if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
|
||||
|
@ -120,7 +120,7 @@ choke:
|
|||
lws_rx_flow_control(wsi, 0);
|
||||
|
||||
done:
|
||||
lws_callback_on_writable_all_protocol(lws_get_ctx(wsi),
|
||||
lws_callback_on_writable_all_protocol(lws_get_context(wsi),
|
||||
lws_get_protocol(wsi));
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue