Skip to content
Snippets Groups Projects
Commit 1929e044 authored by rswindell's avatar rswindell
Browse files

Added branch callback to webserver (using js_CommonBranchCallback), with

customizable properties (branch limit, yield and GC intervals).
parent d3510b88
No related branches found
No related tags found
No related merge requests found
...@@ -443,6 +443,12 @@ void sbbs_read_ini( ...@@ -443,6 +443,12 @@ void sbbs_read_ini(
=iniReadInteger(fp,section,strJavaScriptMaxBytes ,global->js.max_bytes); =iniReadInteger(fp,section,strJavaScriptMaxBytes ,global->js.max_bytes);
web->js_cx_stack web->js_cx_stack
=iniReadInteger(fp,section,strJavaScriptContextStack ,global->js.cx_stack); =iniReadInteger(fp,section,strJavaScriptContextStack ,global->js.cx_stack);
web->js_branch_limit
=iniReadInteger(fp,section,strJavaScriptBranchLimit ,global->js.branch_limit);
web->js_gc_interval
=iniReadInteger(fp,section,strJavaScriptGcInterval ,global->js.gc_interval);
web->js_yield_interval
=iniReadInteger(fp,section,strJavaScriptYieldInterval ,global->js.yield_interval);
SAFECOPY(web->host_name SAFECOPY(web->host_name
,iniReadString(fp,section,strHostName,global->host_name,value)); ,iniReadString(fp,section,strHostName,global->host_name,value));
...@@ -982,6 +988,21 @@ BOOL sbbs_write_ini( ...@@ -982,6 +988,21 @@ BOOL sbbs_write_ini(
else if(!iniSetInteger(lp,section,strJavaScriptContextStack ,web->js_cx_stack,&style)) else if(!iniSetInteger(lp,section,strJavaScriptContextStack ,web->js_cx_stack,&style))
break; break;
if(web->js_branch_limit==global->js.branch_limit)
iniRemoveValue(lp,section,strJavaScriptBranchLimit);
else if(!iniSetInteger(lp,section,strJavaScriptBranchLimit ,web->js_branch_limit,&style))
break;
if(web->js_gc_interval==global->js.gc_interval)
iniRemoveValue(lp,section,strJavaScriptGcInterval);
else if(!iniSetInteger(lp,section,strJavaScriptGcInterval ,web->js_gc_interval,&style))
break;
if(web->js_yield_interval==global->js.yield_interval)
iniRemoveValue(lp,section,strJavaScriptYieldInterval);
else if(!iniSetInteger(lp,section,strJavaScriptYieldInterval,web->js_yield_interval,&style))
break;
if(strcmp(web->host_name,global->host_name)==0 if(strcmp(web->host_name,global->host_name)==0
|| strcmp(bbs->host_name,cfg->sys_inetaddr)==0) || strcmp(bbs->host_name,cfg->sys_inetaddr)==0)
iniRemoveKey(lp,section,strHostName); iniRemoveKey(lp,section,strHostName);
......
...@@ -212,6 +212,7 @@ typedef struct { ...@@ -212,6 +212,7 @@ typedef struct {
JSObject* js_query; JSObject* js_query;
JSObject* js_header; JSObject* js_header;
JSObject* js_request; JSObject* js_request;
js_branch_t js_branch;
/* Client info */ /* Client info */
client_t client; client_t client;
...@@ -819,7 +820,6 @@ static BOOL send_headers(http_session_t *session, const char *status) ...@@ -819,7 +820,6 @@ static BOOL send_headers(http_session_t *session, const char *status)
struct tm tm; struct tm tm;
char *headers; char *headers;
char header[MAX_REQUEST_LINE+1]; char header[MAX_REQUEST_LINE+1];
char *p;
list_node_t *node; list_node_t *node;
lprintf(LOG_DEBUG,"%04d Request resolved to: %s" lprintf(LOG_DEBUG,"%04d Request resolved to: %s"
...@@ -1379,7 +1379,6 @@ static void js_add_header(http_session_t * session, char *key, char *value) ...@@ -1379,7 +1379,6 @@ static void js_add_header(http_session_t * session, char *key, char *value)
static BOOL parse_headers(http_session_t * session) static BOOL parse_headers(http_session_t * session)
{ {
char *head_line; char *head_line;
char next_char;
char *value; char *value;
char *p; char *p;
int i; int i;
...@@ -1626,7 +1625,6 @@ static BOOL get_request_headers(http_session_t * session) ...@@ -1626,7 +1625,6 @@ static BOOL get_request_headers(http_session_t * session)
char head_line[MAX_REQUEST_LINE+1]; char head_line[MAX_REQUEST_LINE+1];
char next_char; char next_char;
char *value; char *value;
char *p;
int i; int i;
while(sockreadline(session,head_line,sizeof(head_line)-1)>0) { while(sockreadline(session,head_line,sizeof(head_line)-1)>0) {
...@@ -2435,6 +2433,17 @@ static JSFunctionSpec js_global_functions[] = { ...@@ -2435,6 +2433,17 @@ static JSFunctionSpec js_global_functions[] = {
{0} {0}
}; };
static JSBool
js_BranchCallback(JSContext *cx, JSScript *script)
{
http_session_t* session;
if((session=(http_session_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
return(js_CommonBranchCallback(cx,&session->js_branch));
}
static JSContext* static JSContext*
js_initcx(JSRuntime* runtime, SOCKET sock, JSObject** glob, http_session_t *session) js_initcx(JSRuntime* runtime, SOCKET sock, JSObject** glob, http_session_t *session)
{ {
...@@ -2452,6 +2461,8 @@ js_initcx(JSRuntime* runtime, SOCKET sock, JSObject** glob, http_session_t *sess ...@@ -2452,6 +2461,8 @@ js_initcx(JSRuntime* runtime, SOCKET sock, JSObject** glob, http_session_t *sess
JS_SetErrorReporter(js_cx, js_ErrorReporter); JS_SetErrorReporter(js_cx, js_ErrorReporter);
JS_SetBranchCallback(js_cx, js_BranchCallback);
do { do {
lprintf(LOG_INFO,"%04d JavaScript: Initializing Global object",sock); lprintf(LOG_INFO,"%04d JavaScript: Initializing Global object",sock);
...@@ -2591,7 +2602,7 @@ static BOOL exec_ssjs(http_session_t* session) { ...@@ -2591,7 +2602,7 @@ static BOOL exec_ssjs(http_session_t* session) {
/* RUN SCRIPT */ /* RUN SCRIPT */
JS_ClearPendingException(session->js_cx); JS_ClearPendingException(session->js_cx);
session->js_branch.counter=0;
if((js_script=JS_CompileFile(session->js_cx, session->js_glob if((js_script=JS_CompileFile(session->js_cx, session->js_glob
,session->req.physical_path))==NULL) { ,session->req.physical_path))==NULL) {
...@@ -3313,6 +3324,11 @@ void DLLCALL web_server(void* arg) ...@@ -3313,6 +3324,11 @@ void DLLCALL web_server(void* arg)
SAFECOPY(session->host_ip,host_ip); SAFECOPY(session->host_ip,host_ip);
session->addr=client_addr; session->addr=client_addr;
session->socket=client_socket; session->socket=client_socket;
session->js_branch.auto_terminate=TRUE;
session->js_branch.terminated=&terminate_server;
session->js_branch.limit=startup->js_branch_limit;
session->js_branch.gc_interval=startup->js_gc_interval;
session->js_branch.yield_interval=startup->js_yield_interval;
_beginthread(http_session_thread, 0, session); _beginthread(http_session_thread, 0, session);
served++; served++;
......
...@@ -53,6 +53,9 @@ typedef struct { ...@@ -53,6 +53,9 @@ typedef struct {
DWORD options; DWORD options;
DWORD js_max_bytes; DWORD js_max_bytes;
DWORD js_cx_stack; DWORD js_cx_stack;
DWORD js_branch_limit;
DWORD js_yield_interval;
DWORD js_gc_interval;
void* cbdata; /* Private data passed to callbacks */ void* cbdata; /* Private data passed to callbacks */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment