Skip to content
Snippets Groups Projects
Commit 8c07636d authored by Andy Green's avatar Andy Green
Browse files

lwsgs: update messageboard to avoid back-to-back writes

parent 87aff27a
Branches
Tags
No related merge requests found
......@@ -262,9 +262,10 @@ reply:
lwsl_err("_write returned %d from %ld\n", n, (long)(p - start));
return -1;
}
n = lws_write(wsi, (unsigned char *)s, 1, LWS_WRITE_HTTP);
if (n != 1)
return -1;
pss->check_response_value = s[0];
pss->check_response = 1;
lws_callback_on_writable(wsi);
return 0;
}
......
......@@ -94,8 +94,10 @@ struct per_session_data__gs {
char ip[46];
struct lws_process_html_state phs;
int spos;
char check_response_value;
unsigned int logging_out:1;
unsigned int check_response:1;
};
/* utils.c */
......
......@@ -420,6 +420,14 @@ callback_generic_sessions(struct lws *wsi, enum lws_callback_reasons reason,
}
break;
case LWS_CALLBACK_HTTP_WRITEABLE:
if (!pss->check_response)
break;
n = lws_write(wsi, (unsigned char *)&pss->check_response_value, 1, LWS_WRITE_HTTP_FINAL);
if (n != 1)
return -1;
goto try_to_reuse;
case LWS_CALLBACK_HTTP:
lwsl_info("LWS_CALLBACK_HTTP: %s\n", (const char *)in);
......@@ -439,7 +447,8 @@ callback_generic_sessions(struct lws *wsi, enum lws_callback_reasons reason,
}
if (!strcmp((const char *)in, "/lwsgs-check")) {
lwsgs_handler_check(vhd, wsi, pss);
goto try_to_reuse;
/* second, async part will complete transaction */
break;
}
if (!strcmp((const char *)in, "/lwsgs-login"))
......
......@@ -41,6 +41,7 @@ struct per_session_data__gs_mb {
struct lws_spa *spa;
unsigned long last_idx;
unsigned int our_form:1;
char second_http_part;
};
static const char * const param_names[] = {
......@@ -309,6 +310,16 @@ callback_messageboard(struct lws *wsi, enum lws_callback_reasons reason,
}
break;
case LWS_CALLBACK_HTTP_WRITEABLE:
if (!pss->second_http_part)
break;
s[0] = '0';
n = lws_write(wsi, (unsigned char *)s, 1, LWS_WRITE_HTTP);
if (n != 1)
return -1;
goto try_to_reuse;
case LWS_CALLBACK_HTTP_BODY_COMPLETION:
if (!pss->our_form)
goto passthru;
......@@ -334,12 +345,10 @@ callback_messageboard(struct lws *wsi, enum lws_callback_reasons reason,
lwsl_err("_write returned %d from %ld\n", n, (long)(p - start));
return -1;
}
s[0] = '0';
n = lws_write(wsi, (unsigned char *)s, 1, LWS_WRITE_HTTP);
if (n != 1)
return -1;
pss->second_http_part = 1;
goto try_to_reuse;
lws_callback_on_writable(wsi);
break;
case LWS_CALLBACK_HTTP_BIND_PROTOCOL:
if (!pss || pss->pss_gs)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment