mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-01 02:35:03 +00:00
getting rid og dynamic options (step 1)
This commit is contained in:
@@ -1,441 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
#include "erlang.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
struct uwsgi_erlang uerl;
|
||||
|
||||
struct uwsgi_option erlang_options[] = {
|
||||
{"erlang", required_argument, 0, "spawn an erlang c-node", uwsgi_opt_set_str, &uerl.name, UWSGI_OPT_MASTER},
|
||||
{"erlang-cookie", required_argument, 0, "set erlang cookie", uwsgi_opt_set_str, &uerl.cookie, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
void dump_eterm(ei_x_buff *x) {
|
||||
|
||||
int etype, esize, arity;
|
||||
long long num;
|
||||
char *atom;
|
||||
int i;
|
||||
char *binary;
|
||||
long bin_size;
|
||||
double fnum;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
uwsgi_log("etype: %d/%c esize: %d\n", etype, etype, esize);
|
||||
|
||||
switch(etype) {
|
||||
case ERL_SMALL_INTEGER_EXT:
|
||||
case ERL_INTEGER_EXT:
|
||||
case ERL_SMALL_BIG_EXT:
|
||||
case ERL_LARGE_BIG_EXT:
|
||||
ei_decode_longlong(x->buff, &x->index, &num);
|
||||
uwsgi_log("num: %lu\n", num);
|
||||
break;
|
||||
case ERL_FLOAT_EXT:
|
||||
ei_decode_double(x->buff, &x->index, &fnum);
|
||||
uwsgi_log("float: %f\n", fnum);
|
||||
break;
|
||||
case ERL_STRING_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
ei_decode_string(x->buff, &x->index, atom);
|
||||
uwsgi_log("string: %s\n", atom);
|
||||
free(atom);
|
||||
break;
|
||||
case ERL_ATOM_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
ei_decode_atom(x->buff, &x->index, atom);
|
||||
uwsgi_log("atom: %s\n", atom);
|
||||
free(atom);
|
||||
break;
|
||||
case ERL_SMALL_TUPLE_EXT:
|
||||
case ERL_LARGE_TUPLE_EXT:
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
for(i=0;i<arity;i++) {
|
||||
dump_eterm(x);
|
||||
}
|
||||
break;
|
||||
case ERL_LIST_EXT:
|
||||
case ERL_NIL_EXT:
|
||||
ei_decode_list_header(x->buff, &x->index, &arity);
|
||||
if (arity == 0) {
|
||||
uwsgi_log("nil value\n");
|
||||
break;
|
||||
}
|
||||
for(i=0;i<arity+1;i++) {
|
||||
dump_eterm(x);
|
||||
}
|
||||
break;
|
||||
case ERL_BINARY_EXT:
|
||||
binary = uwsgi_malloc(esize);
|
||||
ei_decode_binary(x->buff, &x->index, binary, &bin_size);
|
||||
uwsgi_log("binary data of %d bytes\n", bin_size);
|
||||
free(binary);
|
||||
break;
|
||||
default:
|
||||
uwsgi_log("ignored...\n");
|
||||
ei_skip_term(x->buff, &x->index);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_erlang_rpc(int fd, erlang_pid *from, ei_x_buff *x) {
|
||||
|
||||
int etype, esize;
|
||||
int arity;
|
||||
|
||||
char *gen_call;
|
||||
char *module;
|
||||
char *call;
|
||||
char buffer[0xffff];
|
||||
|
||||
char *argv[256] ;
|
||||
uint16_t argvs[256] ;
|
||||
int argc = 0;
|
||||
uint16_t ret;
|
||||
ei_x_buff xr;
|
||||
|
||||
erlang_ref eref;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("%d %c %c %c\n", etype, etype, ERL_SMALL_TUPLE_EXT, ERL_LARGE_TUPLE_EXT);
|
||||
#endif
|
||||
if (etype != ERL_SMALL_TUPLE_EXT && etype != ERL_LARGE_TUPLE_EXT) return;
|
||||
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("rpc arity %d\n", arity);
|
||||
#endif
|
||||
if (arity != 3) return ;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;
|
||||
|
||||
gen_call = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, gen_call);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, gen_call);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("gen call = %s\n", gen_call);
|
||||
#endif
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_SMALL_TUPLE_EXT) return ;
|
||||
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
if (arity != 2) return ;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
ei_skip_term(x->buff, &x->index);
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
ei_decode_ref(x->buff, &x->index, &eref);
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
module = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, module);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, module);
|
||||
}
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_SMALL_TUPLE_EXT) return ;
|
||||
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("arity: %d\n", arity);
|
||||
#endif
|
||||
if (arity != 5) return ;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
char *method = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, method);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, method);
|
||||
}
|
||||
|
||||
if (strcmp(method, "call")) return;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;
|
||||
|
||||
module = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, module);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, module);
|
||||
}
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;
|
||||
|
||||
call = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, call);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, call);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("RPC %s %s\n", module, call);
|
||||
#endif
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
argc = 1;
|
||||
argv[0] = uwsgi_malloc(esize+1);
|
||||
ei_decode_atom(x->buff, &x->index, argv[0]);
|
||||
argvs[1] = esize;
|
||||
}
|
||||
else if (etype == ERL_STRING_EXT) {
|
||||
argc = 1;
|
||||
argv[0] = uwsgi_malloc(esize+1);
|
||||
ei_decode_string(x->buff, &x->index, argv[0]);
|
||||
argvs[1] = esize;
|
||||
}
|
||||
|
||||
ret = uwsgi_rpc(call, argc, argv, argvs, buffer);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("buffer: %.*s\n", ret, buffer);
|
||||
#endif
|
||||
|
||||
ei_x_new_with_version(&xr);
|
||||
|
||||
ei_x_encode_tuple_header(&xr, 2);
|
||||
//ei_x_encode_atom(&xr, "rex");
|
||||
ei_x_encode_ref(&xr, &eref);
|
||||
ei_x_encode_string_len(&xr, buffer, ret);
|
||||
|
||||
uwsgi_log("ei_send to %d %s %d %d %d: %d %d\n", fd, from->node, from->num , from->serial, from->creation, xr.index, ei_send(fd, from, xr.buff, xr.index));
|
||||
//uwsgi_log("ei_send to %d %s %d %d %d: %d %d\n", fd, from->node, from->num , from->serial, from->creation, xr.index, ei_reg_send(&uerl.cnode, fd, "rex", xr.buff, xr.index));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void erlang_loop(int id, void *data) {
|
||||
|
||||
ErlConnect econn;
|
||||
//ErlMessage em;
|
||||
erlang_msg em;
|
||||
int fd;
|
||||
|
||||
int eversion;
|
||||
|
||||
ei_x_buff x, xr;
|
||||
|
||||
ei_x_new(&x);
|
||||
ei_x_new(&xr);
|
||||
|
||||
|
||||
/*
|
||||
int fd0 = ei_connect(&uerl.cnode, "anothernode@maverick64");
|
||||
uwsgi_log("fd0: %d\n", fd0);
|
||||
|
||||
ei_x_encode_list_header(&x, 0);
|
||||
|
||||
ei_rpc_to(&uerl.cnode, fd0, "erlang", "node", x.buff, x.index);
|
||||
|
||||
ei_rpc_from(&uerl.cnode, fd0, 10000, &em, &xr);
|
||||
|
||||
uwsgi_log("From: %s To: %s RegName: %s\n", em.from.node, em.to.node, em.toname);
|
||||
|
||||
xr.index = 0;
|
||||
ei_decode_version(xr.buff, &xr.index, &eversion);
|
||||
uwsgi_log("eversion: %d\n", eversion);
|
||||
|
||||
dump_eterm(&xr);
|
||||
*/
|
||||
|
||||
for(;;) {
|
||||
|
||||
fd = ei_accept(&uerl.cnode, uerl.fd, &econn);
|
||||
|
||||
if (fd >= 0) {
|
||||
|
||||
for (;;) {
|
||||
if (ei_xreceive_msg(fd, &em, &x) == ERL_MSG) {
|
||||
|
||||
if (em.msgtype == ERL_TICK)
|
||||
continue;
|
||||
|
||||
uwsgi_log("[erlang] message From: %s To (process): %s\n", em.from.node, em.toname);
|
||||
|
||||
|
||||
|
||||
x.index = 0;
|
||||
ei_decode_version(x.buff, &x.index, &eversion);
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("eversion: %d\n", eversion);
|
||||
#endif
|
||||
|
||||
if (!strcmp(em.toname, "rex")) {
|
||||
uwsgi_erlang_rpc(fd, &em.from, &x);
|
||||
}
|
||||
else {
|
||||
struct uwsgi_erlang_process *uep = uerl.uep;
|
||||
while(uep) {
|
||||
if (!strcmp(uep->name, em.toname)) {
|
||||
if (uep->plugin) {
|
||||
uep->plugin(uep->func, &x);
|
||||
}
|
||||
break;
|
||||
}
|
||||
uep = uep->next;
|
||||
}
|
||||
|
||||
if (!uep) {
|
||||
uwsgi_log("!!! unregistered erlang process requested, dumping it !!!\n");
|
||||
dump_eterm(&x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
if (em.msgtype) {
|
||||
dump_erl_obj(em.msg);
|
||||
erl_free_compound(em.msg);
|
||||
}
|
||||
if (em.to) {
|
||||
uwsgi_log("*** TO ***\n");
|
||||
dump_erl_obj(em.to);
|
||||
erl_free_compound(em.to);
|
||||
}
|
||||
|
||||
if (em.from) {
|
||||
uwsgi_log("*** FROM ***\n");
|
||||
dump_erl_obj(em.from);
|
||||
erl_free_compound(em.from);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int erlang_init() {
|
||||
|
||||
char *host;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t slen = sizeof(struct sockaddr_in);
|
||||
char *ip = NULL;
|
||||
char *nodename;
|
||||
struct in_addr addr;
|
||||
|
||||
uerl.lock = uwsgi_lock_init("erlang");
|
||||
|
||||
if (uerl.name) {
|
||||
|
||||
|
||||
host = strchr(uerl.name, '@');
|
||||
|
||||
if (!host) {
|
||||
if (ei_connect_init(&uerl.cnode, uerl.name, uerl.cookie, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nodename = uwsgi_concat2n(uerl.name, host-uerl.name, "",0);
|
||||
ip = uwsgi_resolve_ip(host+1);
|
||||
if (ip) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("ip: %s\n", ip);
|
||||
#endif
|
||||
addr.s_addr = inet_addr(ip);
|
||||
if (ei_connect_xinit(&uerl.cnode, host+1, nodename, uerl.name, &addr, uerl.cookie, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ei_connect_init(&uerl.cnode, nodename, uerl.cookie, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
free(nodename);
|
||||
}
|
||||
|
||||
if (ip) {
|
||||
uerl.fd = bind_to_tcp(ip, uwsgi.listen_queue, NULL);
|
||||
}
|
||||
else {
|
||||
uerl.fd = bind_to_tcp("", uwsgi.listen_queue, NULL);
|
||||
}
|
||||
|
||||
if (uerl.fd < 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (getsockname(uerl.fd, (struct sockaddr *) &sin, &slen)) {
|
||||
uwsgi_error("getsockname()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ei_publish(&uerl.cnode, ntohs(sin.sin_port)) < 0) {
|
||||
uwsgi_log( "*** unable to subscribe with EPMD ***\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uwsgi_log("Erlang C-Node %s registered on port %d\n", ei_thisnodename(&uerl.cnode), ntohs(sin.sin_port));
|
||||
|
||||
|
||||
if (register_gateway("uWSGI erlang c-node", erlang_loop, NULL) == NULL) {
|
||||
uwsgi_log("unable to register the erlang gateway\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_plugin erlang_plugin = {
|
||||
|
||||
.name = "erlang",
|
||||
.options = erlang_options,
|
||||
.init = erlang_init,
|
||||
};
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include <ei.h>
|
||||
|
||||
struct uwsgi_erlang_process {
|
||||
|
||||
char name[0xff];
|
||||
void (*plugin)(void *, ei_x_buff *);
|
||||
void *func;
|
||||
|
||||
struct uwsgi_erlang_process *next;
|
||||
};
|
||||
|
||||
struct uwsgi_erlang {
|
||||
|
||||
ei_cnode cnode;
|
||||
char *name;
|
||||
char *cookie;
|
||||
|
||||
int fd;
|
||||
|
||||
void *lock;
|
||||
|
||||
struct uwsgi_erlang_process *uep;
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import os
|
||||
|
||||
NAME='erlang'
|
||||
|
||||
ERLANGPATH = os.environ.get('UWSGICONFIG_ERLANGPATH', 'erl')
|
||||
|
||||
includedir = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, include)])\" -s erlang halt").read().rstrip()
|
||||
libpath = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, lib)])\" -s erlang halt").read().rstrip()
|
||||
|
||||
CFLAGS = [ '-I' + includedir ]
|
||||
LDFLAGS = [ '-L' + libpath ]
|
||||
|
||||
LIBS = ['-lei']
|
||||
|
||||
GCC_LIST = ['erlang']
|
||||
@@ -1,116 +0,0 @@
|
||||
#include <uwsgi.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void (*uwsgi_go_helper_post_fork_c)();
|
||||
void (*uwsgi_go_helper_post_init_c)();
|
||||
void * (*uwsgi_go_helper_env_new_c)(struct wsgi_request *);
|
||||
void (*uwsgi_go_helper_env_add_c)(void *, char *, int, char *, int);
|
||||
void (*uwsgi_go_helper_request_c)(void *, struct wsgi_request *);
|
||||
int (*uwsgi_go_helper_signal_handler_c)(int, void *);
|
||||
void (*uwsgi_go_helper_run_core_c)(int);
|
||||
char *(*uwsgi_go_helper_version_c)();
|
||||
|
||||
void uwsgi_go_post_fork() {
|
||||
uwsgi_go_helper_post_fork_c();
|
||||
}
|
||||
|
||||
void uwsgi_opt_setup_goroutines(char *opt, char *value, void *foobar) {
|
||||
// set async mode
|
||||
uwsgi_opt_set_int(opt, value, &uwsgi.async);
|
||||
// set loop engine
|
||||
uwsgi.loop = "goroutines";
|
||||
}
|
||||
|
||||
struct uwsgi_option uwsgi_go_options[] = {
|
||||
{"goroutines", required_argument, 0, "a shortcut setting optimal options for goroutine-based apps, takes the number of goroutines to spawn as argument", uwsgi_opt_setup_goroutines, NULL, UWSGI_OPT_THREADS},
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
|
||||
};
|
||||
|
||||
#define uwsgi_go_get_symbol(x) x ## _c = dlsym(RTLD_DEFAULT, #x);\
|
||||
if (!x ## _c) {\
|
||||
uwsgi_log("[uwsgi-go] unable to load " #x " function\n"); exit(1);\
|
||||
}
|
||||
|
||||
static int uwsgi_go_init() {
|
||||
|
||||
// build the functions table
|
||||
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_post_fork)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_post_init)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_env_new)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_env_add)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_request)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_signal_handler)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_run_core)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_version)
|
||||
|
||||
uwsgi_log("Go version \"%s\" initialized\n", uwsgi_go_helper_version_c());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_go_request(struct wsgi_request *wsgi_req) {
|
||||
/* Standard GO request */
|
||||
if (!wsgi_req->uh->pktsize) {
|
||||
uwsgi_log("Empty GO request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi_parse_vars(wsgi_req)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
wsgi_req->async_environ = uwsgi_go_helper_env_new_c(wsgi_req);
|
||||
int i;
|
||||
for(i=0;i<wsgi_req->var_cnt;i++) {
|
||||
uwsgi_go_helper_env_add_c(wsgi_req->async_environ, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len,
|
||||
wsgi_req->hvec[i+1].iov_base, wsgi_req->hvec[i+1].iov_len);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
uwsgi_go_helper_request_c(wsgi_req->async_environ, wsgi_req);
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
static void uwsgi_go_after_request(struct wsgi_request *wsgi_req) {
|
||||
log_request(wsgi_req);
|
||||
}
|
||||
|
||||
static int uwsgi_go_signal_handler(uint8_t signum, void *handler) {
|
||||
return uwsgi_go_helper_signal_handler_c((int)signum, handler);
|
||||
}
|
||||
|
||||
static void goroutines_loop() {
|
||||
int i;
|
||||
for (i = 1; i < uwsgi.async; i++) {
|
||||
uwsgi_go_helper_run_core_c(i);
|
||||
}
|
||||
simple_loop_run_int(0);
|
||||
}
|
||||
|
||||
static void uwsgi_go_on_load() {
|
||||
uwsgi_register_loop("goroutines", goroutines_loop);
|
||||
}
|
||||
|
||||
static void uwsgi_go_call_init_hook() {
|
||||
if (uwsgi_go_helper_post_init_c) {
|
||||
uwsgi_go_helper_post_init_c();
|
||||
}
|
||||
}
|
||||
|
||||
struct uwsgi_plugin go_plugin = {
|
||||
.name = "go",
|
||||
.modifier1 = 11,
|
||||
.request = uwsgi_go_request,
|
||||
.after_request = uwsgi_go_after_request,
|
||||
.preinit_apps = uwsgi_go_call_init_hook,
|
||||
.post_fork = uwsgi_go_post_fork,
|
||||
.init = uwsgi_go_init,
|
||||
.signal_handler = uwsgi_go_signal_handler,
|
||||
.on_load = uwsgi_go_on_load,
|
||||
.options = uwsgi_go_options,
|
||||
};
|
||||
@@ -1,420 +0,0 @@
|
||||
/*
|
||||
uWSGI go integration package
|
||||
*/
|
||||
|
||||
package uwsgi
|
||||
|
||||
/*
|
||||
#include <uwsgi.h>
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
// commodity functions to simulate argc/argv
|
||||
|
||||
static char ** uwsgi_go_helper_create_argv(int len) {
|
||||
return uwsgi_calloc(sizeof(char *) * len);
|
||||
}
|
||||
|
||||
static void uwsgi_go_helper_set_argv(char **argv, int pos, char *item) {
|
||||
argv[pos] = item;
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
"unsafe"
|
||||
"strings"
|
||||
"strconv"
|
||||
"io"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// this stores the modifier used by the go plugin (default 11)
|
||||
var uwsgi_modifier1 int = -1;
|
||||
// the following to objects are used to implement a sort of GC to avoid request environ and
|
||||
// signal handlers to be garbage collected
|
||||
var uwsgi_env_gc = make(map[*C.struct_wsgi_request](*map[string]string))
|
||||
var uwsgi_signals_gc = make([]*func(int), 256)
|
||||
|
||||
var uwsgi_default_request_handler func(http.ResponseWriter, *http.Request) = nil
|
||||
var uwsgi_default_handler http.Handler = nil
|
||||
var uwsgi_post_fork_hook func() = nil
|
||||
var uwsgi_post_init_hook func() = nil
|
||||
|
||||
|
||||
/*
|
||||
|
||||
uWSGI api functions
|
||||
|
||||
*/
|
||||
|
||||
// raise a uWSGI signal
|
||||
func Signal(signum int) {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return
|
||||
}
|
||||
C.uwsgi_signal_send(C.uwsgi.signal_socket, C.uint8_t(signum))
|
||||
}
|
||||
|
||||
// set a user lock
|
||||
func Lock(num int) {
|
||||
C.uwsgi_user_lock(C.int(num));
|
||||
}
|
||||
|
||||
// unset a user lock
|
||||
func Unlock(num int) {
|
||||
C.uwsgi_user_unlock(C.int(num));
|
||||
}
|
||||
|
||||
// add a timer
|
||||
func AddTimer(signum int, seconds int) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if int(C.uwsgi_add_timer(C.uint8_t(signum), C.int(seconds))) == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// add a red black timer
|
||||
func AddRbTimer(signum int, seconds int) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if int(C.uwsgi_signal_add_rb_timer(C.uint8_t(signum), C.int(seconds), C.int(0))) == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// check if a signal is registered
|
||||
func SignalRegistered(signum int) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if int(C.uwsgi_signal_registered(C.uint8_t(signum))) == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// register a signal
|
||||
func RegisterSignal(signum int, who string, handler func(int)) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if uwsgi_modifier1 == -1 {
|
||||
c_go := C.CString("go")
|
||||
defer C.free(unsafe.Pointer(c_go))
|
||||
uwsgi_modifier1 = int(C.uwsgi_plugin_modifier1(c_go))
|
||||
if uwsgi_modifier1 == -1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
c_who := C.CString(who)
|
||||
defer C.free(unsafe.Pointer(c_who))
|
||||
if int(C.uwsgi_register_signal(C.uint8_t(signum), c_who, unsafe.Pointer(&handler), C.uint8_t(uwsgi_modifier1))) == 0 {
|
||||
uwsgi_signals_gc[signum] = &handler
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func Alarm(alarm string, msg string) {
|
||||
a := C.CString(alarm)
|
||||
defer C.free(unsafe.Pointer(a))
|
||||
m := C.CString(msg)
|
||||
defer C.free(unsafe.Pointer(m))
|
||||
ml := len(msg)
|
||||
C.uwsgi_alarm_trigger(a, m, C.size_t(ml))
|
||||
}
|
||||
|
||||
// get an item from the cache
|
||||
func CacheGet(key string, cache string) []byte {
|
||||
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
var vl C.uint64_t = C.uint64_t(0)
|
||||
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
var p []byte
|
||||
|
||||
c_value := C.uwsgi_cache_magic_get(k, C.uint16_t(kl), &vl, (*C.uint64_t)(nil), c)
|
||||
|
||||
if c_value != nil {
|
||||
p = C.GoBytes((unsafe.Pointer)(c_value), C.int(vl))
|
||||
} else {
|
||||
p = nil
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// remove an intem from the cache
|
||||
func CacheDel(key string, cache string) bool {
|
||||
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
if int(C.uwsgi_cache_magic_del(k, C.uint16_t(kl), c)) < 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// check if an item exists in the cache
|
||||
func CacheExists(key string, cache string) bool {
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
if int(C.uwsgi_cache_magic_exists(k, C.uint16_t(kl), c)) == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// put an item in the cache
|
||||
func CacheSetFlags(key string, p []byte, expires uint64, flags int, cache string) bool {
|
||||
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
v := unsafe.Pointer(&p[0])
|
||||
vl := len(p)
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
if int(C.uwsgi_cache_magic_set(k, C.uint16_t(kl), (*C.char)(v), C.uint64_t(vl), C.uint64_t(expires), C.uint64_t(flags), c)) < 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func CacheSet(key string, p []byte, expires uint64, cache string) bool {
|
||||
return CacheSetFlags(key, p, expires, 0, cache);
|
||||
}
|
||||
|
||||
func CacheUpdate(key string, p []byte, expires uint64, cache string) bool {
|
||||
return CacheSetFlags(key, p, expires, 2, cache);
|
||||
}
|
||||
|
||||
// get the current worker id
|
||||
func WorkerId() int {
|
||||
return int(C.uwsgi.mywid)
|
||||
}
|
||||
|
||||
// get the current mule id
|
||||
func MuleId() int {
|
||||
return int(C.uwsgi.muleid)
|
||||
}
|
||||
|
||||
// get the current logsize (if available)
|
||||
func LogSize() int64 {
|
||||
return int64(C.uwsgi.shared.logsize)
|
||||
}
|
||||
|
||||
func PostFork(hook func()) {
|
||||
uwsgi_post_fork_hook = hook
|
||||
}
|
||||
|
||||
func PostInit(hook func()) {
|
||||
uwsgi_post_init_hook = hook
|
||||
}
|
||||
|
||||
func RequestHandler(hook func(http.ResponseWriter, *http.Request)) {
|
||||
uwsgi_default_request_handler = hook
|
||||
}
|
||||
|
||||
func Handler(handler http.Handler) {
|
||||
uwsgi_default_handler = handler
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
C -> go and go -> C bridges
|
||||
|
||||
*/
|
||||
|
||||
//export uwsgi_go_helper_post_fork
|
||||
func uwsgi_go_helper_post_fork() {
|
||||
if uwsgi_post_fork_hook != nil {
|
||||
uwsgi_post_fork_hook()
|
||||
}
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_post_init
|
||||
func uwsgi_go_helper_post_init() {
|
||||
if uwsgi_post_init_hook != nil {
|
||||
uwsgi_post_init_hook()
|
||||
}
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_env_new
|
||||
func uwsgi_go_helper_env_new(wsgi_req *C.struct_wsgi_request) *map[string]string {
|
||||
var env map[string]string
|
||||
env = make(map[string]string)
|
||||
// track env to avoid it being garbage collected...
|
||||
uwsgi_env_gc[wsgi_req] = &env
|
||||
return &env
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_env_add
|
||||
func uwsgi_go_helper_env_add(env *map[string]string, k *C.char, kl C.int, v *C.char, vl C.int) {
|
||||
var mk string = C.GoStringN(k, kl)
|
||||
var mv string = C.GoStringN(v, vl)
|
||||
(*env)[mk] = mv
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
http.* implementations
|
||||
|
||||
*/
|
||||
|
||||
type ResponseWriter struct {
|
||||
r *http.Request
|
||||
wsgi_req *C.struct_wsgi_request
|
||||
headers http.Header
|
||||
wroteHeader bool
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) Write(p []byte) (n int, err error) {
|
||||
if !w.wroteHeader {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
m := len(p)
|
||||
C.uwsgi_response_write_body_do(w.wsgi_req, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(m))
|
||||
return m+n, err
|
||||
}
|
||||
|
||||
// TODO fix it !!!
|
||||
func (w *ResponseWriter) WriteHeader(status int) {
|
||||
codestring := http.StatusText(status)
|
||||
var tmp_buf string = strconv.Itoa(status) + " " + codestring
|
||||
c_status := C.CString(tmp_buf)
|
||||
defer C.free(unsafe.Pointer(c_status))
|
||||
C.uwsgi_response_prepare_headers(w.wsgi_req, c_status, C.uint16_t(len(tmp_buf)) )
|
||||
if w.headers.Get("Content-Type") == "" {
|
||||
w.headers.Set("Content-Type", "text/html; charset=utf-8")
|
||||
}
|
||||
for k := range w.headers {
|
||||
hk_c := C.CString(k)
|
||||
defer C.free(unsafe.Pointer(hk_c))
|
||||
for _, v := range w.headers[k] {
|
||||
v = strings.NewReplacer("\n", " ", "\r", " ").Replace(v)
|
||||
v = strings.TrimSpace(v)
|
||||
hv_c := C.CString(v)
|
||||
defer C.free(unsafe.Pointer(hv_c))
|
||||
C.uwsgi_response_add_header(w.wsgi_req, hk_c, C.uint16_t(len(k)), hv_c, C.uint16_t(len(v)))
|
||||
}
|
||||
}
|
||||
w.wroteHeader = true
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) Header() http.Header {
|
||||
return w.headers
|
||||
}
|
||||
|
||||
|
||||
type BodyReader struct {
|
||||
wsgi_req *C.struct_wsgi_request
|
||||
}
|
||||
|
||||
// there is no close in request body
|
||||
func (br *BodyReader) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (br *BodyReader) Read(p []byte) (n int, err error) {
|
||||
m := len(p)
|
||||
var rlen C.ssize_t = C.ssize_t(0)
|
||||
c_body := C.uwsgi_request_body_read(br.wsgi_req, C.ssize_t(m), &rlen)
|
||||
if (c_body == C.uwsgi.empty) {
|
||||
err = io.EOF;
|
||||
return 0, err
|
||||
} else if (c_body != nil) {
|
||||
C.memcpy(unsafe.Pointer(&p[0]), unsafe.Pointer(c_body), C.size_t(rlen))
|
||||
return int(rlen), err
|
||||
}
|
||||
err = io.ErrUnexpectedEOF
|
||||
rlen = 0
|
||||
return int(rlen), err
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_request
|
||||
func uwsgi_go_helper_request(env *map[string]string, wsgi_req *C.struct_wsgi_request) {
|
||||
httpReq, err := cgi.RequestFromMap(*env)
|
||||
if err != nil {
|
||||
} else {
|
||||
httpReq.Body = &BodyReader{wsgi_req}
|
||||
w := ResponseWriter{httpReq, wsgi_req,http.Header{},false}
|
||||
if uwsgi_default_request_handler != nil {
|
||||
uwsgi_default_request_handler(&w, httpReq)
|
||||
} else if uwsgi_default_handler != nil {
|
||||
uwsgi_default_handler.ServeHTTP(&w, httpReq)
|
||||
} else {
|
||||
http.DefaultServeMux.ServeHTTP(&w, httpReq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_version
|
||||
func uwsgi_go_helper_version() *C.char {
|
||||
return C.CString(runtime.Version())
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_signal_handler
|
||||
func uwsgi_go_helper_signal_handler(signum int, handler *func(int)) int {
|
||||
(*handler)(signum)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_run_core
|
||||
func uwsgi_go_helper_run_core(core_id int) {
|
||||
go C.simple_loop_run_int(C.int(core_id))
|
||||
}
|
||||
|
||||
/*
|
||||
the main function, running the uWSGI server via libuwsgi.so
|
||||
*/
|
||||
func Run() {
|
||||
argc := len(os.Args) + 1
|
||||
argv := C.uwsgi_go_helper_create_argv(C.int(argc))
|
||||
for i, s := range os.Args {
|
||||
C.uwsgi_go_helper_set_argv(argv, C.int(i), C.CString(s))
|
||||
}
|
||||
C.uwsgi_init(C.int(argc-1), argv, nil)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import os
|
||||
NAME='go'
|
||||
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = []
|
||||
GCC_LIST = ['go_plugin']
|
||||
|
||||
def post_build(config):
|
||||
os.environ['GOPATH'] = 'plugins/go'
|
||||
cflags = ['-I'+os.getcwd()]
|
||||
for c in config.cflags:
|
||||
if not c.startswith('-DUWSGI_BUILD_DATE') and not c.startswith('-DUWSGI_CFLAGS'):
|
||||
cflags.append(c)
|
||||
|
||||
cflags.append('-Wno-implicit-function-declaration')
|
||||
cflags.append('-Wno-implicit-int')
|
||||
cflags.append('-Wno-unused-function')
|
||||
cflags.append('-Wno-unused-variable')
|
||||
|
||||
os.environ['CGO_CFLAGS'] = ' '.join(cflags).replace('\\"', '')
|
||||
base = os.path.dirname(config.get('bin_name'))
|
||||
if not base:
|
||||
base = "."
|
||||
os.environ['CGO_LDFLAGS'] = '-L' + base + ' -L'+os.getcwd() + ' -luwsgi'
|
||||
if os.system("go install uwsgi") != 0:
|
||||
os._exit(1)
|
||||
print("*** uwsgi go module available in $GOPATH %s/plugins/go ***" % os.getcwd())
|
||||
@@ -1,543 +0,0 @@
|
||||
#include "../erlang/erlang.h"
|
||||
#include "../python/uwsgi_python.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
extern struct uwsgi_erlang uerl;
|
||||
extern struct uwsgi_python up;
|
||||
|
||||
ei_cnode *pyerl_cnode;
|
||||
|
||||
PyObject *pyerl_close(PyObject * self, PyObject * args) {
|
||||
|
||||
int fd;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:erlang_close", &fd)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_connect(PyObject * self, PyObject * args) {
|
||||
|
||||
char *node = NULL;
|
||||
int fd;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:erlang_connect", &node)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = ei_connect(pyerl_cnode, node);
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
return PyInt_FromLong(fd);
|
||||
|
||||
}
|
||||
|
||||
int py_to_erl(PyObject *, ei_x_buff*);
|
||||
|
||||
PyObject *erl_to_py(ei_x_buff* x) {
|
||||
|
||||
int etype, esize, arity;
|
||||
long long num;
|
||||
double fnum;
|
||||
char *atom, *binary;
|
||||
long bin_size;
|
||||
PyObject *pobj;
|
||||
PyObject *zero;
|
||||
erlang_pid epid;
|
||||
int i;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
switch(etype) {
|
||||
case ERL_SMALL_INTEGER_EXT:
|
||||
case ERL_INTEGER_EXT:
|
||||
case ERL_SMALL_BIG_EXT:
|
||||
case ERL_LARGE_BIG_EXT:
|
||||
ei_decode_longlong(x->buff, &x->index, &num);
|
||||
return PyLong_FromLong(num);
|
||||
case ERL_FLOAT_EXT:
|
||||
ei_decode_double(x->buff, &x->index, &fnum);
|
||||
return PyFloat_FromDouble(fnum);
|
||||
case ERL_STRING_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
ei_decode_string(x->buff, &x->index, atom);
|
||||
pobj = PyString_FromString(atom);
|
||||
free(atom);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_ATOM_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
ei_decode_atom(x->buff, &x->index, atom);
|
||||
#ifndef PyUnicode_FromString
|
||||
zero = PyString_FromString(atom);
|
||||
pobj = PyUnicode_FromObject(zero);
|
||||
Py_DECREF(zero);
|
||||
#else
|
||||
pobj = PyUnicode_FromString(atom);
|
||||
#endif
|
||||
free(atom);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_SMALL_TUPLE_EXT:
|
||||
case ERL_LARGE_TUPLE_EXT:
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
pobj = PyTuple_New(arity);
|
||||
for(i=0;i<arity;i++) {
|
||||
zero = erl_to_py(x);
|
||||
PyTuple_SetItem(pobj, i, zero);
|
||||
Py_DECREF(zero);
|
||||
}
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_LIST_EXT:
|
||||
case ERL_NIL_EXT:
|
||||
ei_decode_list_header(x->buff, &x->index, &arity);
|
||||
if (!arity) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
pobj = PyList_New(0);
|
||||
for(i=0;i<arity+1;i++) {
|
||||
zero = erl_to_py(x);
|
||||
PyList_Append(pobj, zero);
|
||||
Py_DECREF(zero);
|
||||
}
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_BINARY_EXT:
|
||||
binary = uwsgi_malloc(esize);
|
||||
ei_decode_binary(x->buff, &x->index, binary, &bin_size);
|
||||
pobj = PyString_FromStringAndSize(binary, bin_size);
|
||||
free(binary);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_PID_EXT:
|
||||
ei_decode_pid(x->buff, &x->index, &epid);
|
||||
pobj = PyTuple_New(3);
|
||||
PyTuple_SetItem(pobj, 0, PyInt_FromLong(epid.num));
|
||||
PyTuple_SetItem(pobj, 1, PyInt_FromLong(epid.serial));
|
||||
PyTuple_SetItem(pobj, 2, PyInt_FromLong(epid.creation));
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
default:
|
||||
ei_skip_term(x->buff, &x->index);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
PyObject *pyerl_lock(PyObject * self, PyObject * args) {
|
||||
|
||||
uwsgi_lock(uerl.lock);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_unlock(PyObject * self, PyObject * args) {
|
||||
|
||||
uwsgi_unlock(uerl.lock);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_send(PyObject * self, PyObject * args) {
|
||||
PyObject *node;
|
||||
PyObject *reg;
|
||||
char *cnode;
|
||||
PyObject *pobj;
|
||||
ei_x_buff x;
|
||||
int fd;
|
||||
int close_fd = 0;
|
||||
erlang_pid epid;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO:erlang_send", &node, ®, &pobj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyString_Check(node)) {
|
||||
cnode = PyString_AsString(node);
|
||||
fd = ei_connect(pyerl_cnode, cnode);
|
||||
close_fd = 1;
|
||||
}
|
||||
else if (PyInt_Check(node)) {
|
||||
fd = PyInt_AsLong(node);
|
||||
}
|
||||
else {
|
||||
return PyErr_Format(PyExc_ValueError, "invalid erlang node/descriptor");
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
|
||||
ei_x_new_with_version(&x);
|
||||
|
||||
if (py_to_erl(pobj, &x) < 0) {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Unsupported object in Python->Erlang translation");
|
||||
}
|
||||
|
||||
|
||||
if (PyTuple_Check(reg) && PyTuple_Size(reg) == 3) {
|
||||
epid.num = PyInt_AsLong( PyTuple_GetItem(reg, 0) );
|
||||
epid.serial = PyInt_AsLong( PyTuple_GetItem(reg, 1) );
|
||||
epid.creation = PyInt_AsLong( PyTuple_GetItem(reg, 2) );
|
||||
ei_send(fd, &epid, x.buff, x.index);
|
||||
}
|
||||
else if (PyString_Check(reg)) {
|
||||
ei_reg_send(pyerl_cnode, fd, PyString_AsString(reg), x.buff, x.index);
|
||||
}
|
||||
else {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid Erlang process");
|
||||
}
|
||||
|
||||
return PyInt_FromLong(fd);
|
||||
}
|
||||
|
||||
PyObject *pyerl_sr(PyObject * self, PyObject * args) {
|
||||
|
||||
PyObject *node;
|
||||
PyObject *reg;
|
||||
char *cnode;
|
||||
PyObject *pobj;
|
||||
ei_x_buff x;
|
||||
int fd;
|
||||
int close_fd = 0;
|
||||
erlang_msg em;
|
||||
erlang_pid epid;
|
||||
int eversion;
|
||||
PyObject *res;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO:erlang_sr", &node, ®, &pobj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyString_Check(node)) {
|
||||
cnode = PyString_AsString(node);
|
||||
fd = ei_connect(pyerl_cnode, cnode);
|
||||
close_fd = 1;
|
||||
}
|
||||
else if (PyInt_Check(node)) {
|
||||
fd = PyInt_AsLong(node);
|
||||
}
|
||||
else {
|
||||
return PyErr_Format(PyExc_ValueError, "invalid erlang node/descriptor");
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
|
||||
|
||||
ei_x_new_with_version(&x);
|
||||
|
||||
if (py_to_erl(pobj, &x) < 0) {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Unsupported object in Python->Erlang translation");
|
||||
}
|
||||
|
||||
|
||||
if (PyTuple_Check(reg) && PyTuple_Size(reg) == 3) {
|
||||
epid.num = PyInt_AsLong( PyTuple_GetItem(reg, 0) );
|
||||
epid.serial = PyInt_AsLong( PyTuple_GetItem(reg, 1) );
|
||||
epid.creation = PyInt_AsLong( PyTuple_GetItem(reg, 2) );
|
||||
ei_send(fd, &epid, x.buff, x.index);
|
||||
}
|
||||
else if (PyString_Check(reg)) {
|
||||
ei_reg_send(pyerl_cnode, fd, PyString_AsString(reg), x.buff, x.index);
|
||||
}
|
||||
else {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid Erlang process");
|
||||
}
|
||||
|
||||
recv:
|
||||
ei_x_free(&x);
|
||||
|
||||
ei_x_new(&x);
|
||||
|
||||
if (ei_xreceive_msg(fd, &em, &x) == ERL_MSG) {
|
||||
|
||||
if (em.msgtype == ERL_TICK) {
|
||||
goto recv;
|
||||
}
|
||||
x.index = 0;
|
||||
ei_decode_version(x.buff, &x.index, &eversion);
|
||||
res = erl_to_py(&x);
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return res;
|
||||
}
|
||||
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
void pyerl_call_registered(void *func, ei_x_buff *x) {
|
||||
|
||||
PyObject *pyargs = PyTuple_New(1);
|
||||
|
||||
PyTuple_SetItem(pyargs, 0, erl_to_py(x));
|
||||
|
||||
python_call((PyObject *) func, pyargs, 0, NULL);
|
||||
}
|
||||
|
||||
PyObject *pyerl_register_process(PyObject * self, PyObject * args) {
|
||||
|
||||
char *name;
|
||||
PyObject *callable;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sO:erlang_register_process", &name, &callable)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strlen(name) > 0xff-1)
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid erlang process name");
|
||||
|
||||
struct uwsgi_erlang_process *uep = uerl.uep, *old_uep;
|
||||
|
||||
if (!uep) {
|
||||
uerl.uep = uwsgi_malloc(sizeof(struct uwsgi_erlang_process));
|
||||
uep = uerl.uep;
|
||||
}
|
||||
else {
|
||||
while(uep) {
|
||||
old_uep = uep;
|
||||
uep = uep->next;
|
||||
}
|
||||
|
||||
uep = uwsgi_malloc(sizeof(struct uwsgi_erlang_process));
|
||||
old_uep->next = uep;
|
||||
}
|
||||
|
||||
strcpy(uep->name, name);
|
||||
uep->plugin = pyerl_call_registered;
|
||||
uep->func = callable;
|
||||
uep->next = NULL;
|
||||
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
PyObject *pyerl_recv(PyObject * self, PyObject * args) {
|
||||
|
||||
ei_x_buff x;
|
||||
erlang_msg em;
|
||||
PyObject *res;
|
||||
int eversion;
|
||||
int fd;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:erlang_recv", &fd)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
recv:
|
||||
ei_x_new(&x);
|
||||
|
||||
if (ei_xreceive_msg(fd, &em, &x) == ERL_MSG) {
|
||||
|
||||
if (em.msgtype == ERL_TICK) {
|
||||
ei_x_free(&x);
|
||||
goto recv;
|
||||
}
|
||||
x.index = 0;
|
||||
ei_decode_version(x.buff, &x.index, &eversion);
|
||||
res = erl_to_py(&x);
|
||||
ei_x_free(&x);
|
||||
return res;
|
||||
}
|
||||
|
||||
ei_x_free(&x);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_rpc(PyObject * self, PyObject * args) {
|
||||
|
||||
PyObject *node;
|
||||
char *mod, *fun;
|
||||
char *cnode;
|
||||
PyObject *pobj;
|
||||
ei_x_buff x;
|
||||
ei_x_buff xr;
|
||||
int fd;
|
||||
int close_fd = 0;
|
||||
int eversion;
|
||||
PyObject *res;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OssO:erlang_rpc", &node, &mod, &fun, &pobj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyString_Check(node)) {
|
||||
cnode = PyString_AsString(node);
|
||||
fd = ei_connect(pyerl_cnode, cnode);
|
||||
close_fd = 1;
|
||||
}
|
||||
else if (PyInt_Check(node)) {
|
||||
fd = PyInt_AsLong(node);
|
||||
}
|
||||
else {
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid erlang node/descriptor");
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
ei_x_new(&x);
|
||||
|
||||
if (py_to_erl(pobj, &x) < 0) {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Unsupported object in Python->Erlang translation");
|
||||
}
|
||||
|
||||
|
||||
ei_x_new(&xr);
|
||||
if (ei_rpc(pyerl_cnode, fd, mod, fun, x.buff, x.index, &xr) < 0) {
|
||||
if (close_fd) close(fd);
|
||||
ei_x_free(&x);
|
||||
ei_x_free(&xr);
|
||||
return PyErr_Format(PyExc_ValueError, "Error in Erlang rpc");
|
||||
}
|
||||
|
||||
xr.index = 0;
|
||||
ei_decode_version(xr.buff, &xr.index, &eversion);
|
||||
|
||||
res = erl_to_py(&xr);
|
||||
|
||||
if (close_fd) close(fd);
|
||||
ei_x_free(&x);
|
||||
ei_x_free(&xr);
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyMethodDef uwsgi_pyerl_methods[] = {
|
||||
{"erlang_connect", pyerl_connect, METH_VARARGS, ""},
|
||||
{"erlang_close", pyerl_close, METH_VARARGS, ""},
|
||||
{"erlang_send_message", pyerl_send, METH_VARARGS, ""},
|
||||
{"erlang_send", pyerl_send, METH_VARARGS, ""},
|
||||
{"erlang_recv_message", pyerl_recv, METH_VARARGS, ""},
|
||||
{"erlang_recv", pyerl_recv, METH_VARARGS, ""},
|
||||
{"erlang_sr", pyerl_sr, METH_VARARGS, ""},
|
||||
{"erlang_rpc", pyerl_rpc, METH_VARARGS, ""},
|
||||
{"erlang_lock", pyerl_lock, METH_VARARGS, ""},
|
||||
{"erlang_unlock", pyerl_unlock, METH_VARARGS, ""},
|
||||
{"erlang_register_process", pyerl_register_process, METH_VARARGS, ""},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
void py_erl_init_functions() {
|
||||
|
||||
PyMethodDef *uwsgi_function;
|
||||
|
||||
PyDict_SetItemString(up.embedded_dict, "erlang_node", PyString_FromString(ei_thisnodename(pyerl_cnode)));
|
||||
|
||||
for (uwsgi_function = uwsgi_pyerl_methods; uwsgi_function->ml_name != NULL; uwsgi_function++) {
|
||||
PyObject *func = PyCFunction_New(uwsgi_function, NULL);
|
||||
PyDict_SetItemString(up.embedded_dict, uwsgi_function->ml_name, func);
|
||||
Py_DECREF(func);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int py_to_erl(PyObject *pobj, ei_x_buff *x) {
|
||||
int i;
|
||||
PyObject *pobj2;
|
||||
|
||||
if (pobj == NULL || pobj == Py_None) {
|
||||
ei_x_encode_empty_list(x);
|
||||
}
|
||||
else if (PyString_Check(pobj)) {
|
||||
ei_x_encode_binary(x, PyString_AsString(pobj), PyString_Size(pobj));
|
||||
}
|
||||
else if (PyUnicode_Check(pobj)) {
|
||||
ei_x_encode_atom(x, PyString_AsString(pobj));
|
||||
}
|
||||
else if (PyInt_Check(pobj)) {
|
||||
ei_x_encode_long(x, PyInt_AsLong(pobj));
|
||||
}
|
||||
else if (PyList_Check(pobj)) {
|
||||
if (PyList_Size(pobj) > 0) {
|
||||
ei_x_encode_list_header(x, PyList_Size(pobj));
|
||||
for (i = 0; i < PyList_Size(pobj); i++) {
|
||||
pobj2 = PyList_GetItem(pobj, i);
|
||||
if (py_to_erl(pobj2, x) < 0) return -1;
|
||||
}
|
||||
}
|
||||
ei_x_encode_empty_list(x);
|
||||
}
|
||||
else if (PyTuple_Check(pobj)) {
|
||||
ei_x_encode_tuple_header(x, PyTuple_Size(pobj));
|
||||
for (i = 0; i < PyTuple_Size(pobj); i++) {
|
||||
pobj2 = PyTuple_GetItem(pobj, i);
|
||||
if (py_to_erl(pobj2, x) < 0) return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return x->index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pyerl_init() {
|
||||
|
||||
up.extension = py_erl_init_functions;
|
||||
|
||||
if (!uerl.name) {
|
||||
pyerl_cnode = uwsgi_malloc(sizeof(ei_cnode));
|
||||
memset(pyerl_cnode, 0, sizeof(ei_cnode));
|
||||
if (ei_connect_init(pyerl_cnode, "uwsgi", NULL, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_log("Erlang C-Node name: %s\n",ei_thisnodename(pyerl_cnode));
|
||||
}
|
||||
else {
|
||||
pyerl_cnode = &uerl.cnode;
|
||||
}
|
||||
|
||||
uwsgi_log("enabled Python<->Erlang bridge\n");
|
||||
|
||||
}
|
||||
|
||||
struct uwsgi_plugin pyerl_plugin = {
|
||||
|
||||
.post_init = pyerl_init,
|
||||
};
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import os
|
||||
from distutils import sysconfig
|
||||
|
||||
NAME='pyerl'
|
||||
|
||||
ERLANGPATH = os.environ.get('UWSGICONFIG_ERLANGPATH', 'erl')
|
||||
|
||||
includedir = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, include)])\" -s erlang halt").read().rstrip()
|
||||
libpath = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, lib)])\" -s erlang halt").read().rstrip()
|
||||
|
||||
CFLAGS = [ '-I' + includedir, '-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True)]
|
||||
LDFLAGS = [ '-L' + libpath ]
|
||||
|
||||
LIBS = ['-lei']
|
||||
|
||||
GCC_LIST = ['pyerl']
|
||||
+1
-1
@@ -533,7 +533,7 @@ void async_loop() {
|
||||
continue;
|
||||
}
|
||||
// re-add timer
|
||||
async_add_timeout(uwsgi.wsgi_req, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
async_add_timeout(uwsgi.wsgi_req, uwsgi.socket_timeout);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -340,7 +340,7 @@ int uwsgi_buffer_send(struct uwsgi_buffer *ub, int fd) {
|
||||
char *ptr = ub->buf;
|
||||
|
||||
while (remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(fd, uwsgi.socket_timeout);
|
||||
if (ret > 0) {
|
||||
ssize_t len = write(fd, ptr, remains);
|
||||
if (len > 0) {
|
||||
|
||||
+14
-14
@@ -1483,7 +1483,7 @@ char *uwsgi_cache_magic_get(char *key, uint16_t keylen, uint64_t *vallen, uint64
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return NULL;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
@@ -1495,7 +1495,7 @@ char *uwsgi_cache_magic_get(char *key, uint16_t keylen, uint64_t *vallen, uint64
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return NULL;
|
||||
@@ -1526,7 +1526,7 @@ char *uwsgi_cache_magic_get(char *key, uint16_t keylen, uint64_t *vallen, uint64
|
||||
}
|
||||
|
||||
// read the raw value from the socket
|
||||
if (uwsgi_read_whole_true_nb(fd, ub->buf, ucmc.size, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_read_whole_true_nb(fd, ub->buf, ucmc.size, uwsgi.socket_timeout)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return NULL;
|
||||
@@ -1585,7 +1585,7 @@ int uwsgi_cache_magic_exists(char *key, uint16_t keylen, char *cache) {
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return 0;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return 0;
|
||||
@@ -1597,7 +1597,7 @@ int uwsgi_cache_magic_exists(char *key, uint16_t keylen, char *cache) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return 0;
|
||||
@@ -1652,7 +1652,7 @@ int uwsgi_cache_magic_set(char *key, uint16_t keylen, char *value, uint64_t vall
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
@@ -1670,7 +1670,7 @@ int uwsgi_cache_magic_set(char *key, uint16_t keylen, char *value, uint64_t vall
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, value, vallen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, value, vallen, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return -1;
|
||||
@@ -1730,7 +1730,7 @@ int uwsgi_cache_magic_del(char *key, uint16_t keylen, char *cache) {
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
@@ -1742,7 +1742,7 @@ int uwsgi_cache_magic_del(char *key, uint16_t keylen, char *cache) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return -1;
|
||||
@@ -1803,7 +1803,7 @@ int uwsgi_cache_magic_clear(char *cache) {
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
@@ -1815,7 +1815,7 @@ int uwsgi_cache_magic_clear(char *cache) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return -1;
|
||||
@@ -1859,7 +1859,7 @@ void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *uc) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (uwsgi_write_nb(fd, ub->buf, ub->pos, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_write_nb(fd, ub->buf, ub->pos, uwsgi.socket_timeout)) {
|
||||
uwsgi_buffer_destroy(ub);
|
||||
uwsgi_log("[cache-sync] unable to write to the cache server\n");
|
||||
close(fd);
|
||||
@@ -1867,7 +1867,7 @@ void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *uc) {
|
||||
}
|
||||
|
||||
size_t rlen = ub->pos;
|
||||
if (uwsgi_read_with_realloc(fd, &ub->buf, &rlen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], NULL, NULL)) {
|
||||
if (uwsgi_read_with_realloc(fd, &ub->buf, &rlen, uwsgi.socket_timeout, NULL, NULL)) {
|
||||
uwsgi_buffer_destroy(ub);
|
||||
uwsgi_log("[cache-sync] unable to read from the cache server\n");
|
||||
close(fd);
|
||||
@@ -1876,7 +1876,7 @@ void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *uc) {
|
||||
|
||||
uwsgi_hooked_parse(ub->buf, rlen, cache_sync_hook, uc);
|
||||
|
||||
if (uwsgi_read_nb(fd, (char *) uc->items, uc->filesize, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_read_nb(fd, (char *) uc->items, uc->filesize, uwsgi.socket_timeout)) {
|
||||
uwsgi_buffer_destroy(ub);
|
||||
close(fd);
|
||||
uwsgi_log("[cache-sync] unable to read from the cache server\n");
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ extern struct uwsgi_server uwsgi;
|
||||
static ssize_t uwsgi_chunked_input_recv(struct wsgi_request *wsgi_req, int timeout, int nb) {
|
||||
|
||||
if (timeout == 0) timeout = uwsgi.chunked_input_timeout;
|
||||
if (timeout == 0) timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT];
|
||||
if (timeout == 0) timeout = uwsgi.socket_timeout;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
|
||||
+1
-1
@@ -1889,7 +1889,7 @@ void emperor_send_stats(int fd) {
|
||||
size_t remains = us->pos;
|
||||
off_t pos = 0;
|
||||
while (remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
goto end0;
|
||||
}
|
||||
|
||||
+7
-7
@@ -117,11 +117,11 @@ void uwsgi_init_default() {
|
||||
uwsgi.max_vars = MAX_VARS;
|
||||
uwsgi.vec_size = 4 + 1 + (4 * MAX_VARS);
|
||||
|
||||
uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 4;
|
||||
uwsgi.shared->options[UWSGI_OPTION_LOGGING] = 1;
|
||||
uwsgi.socket_timeout = 4;
|
||||
uwsgi.logging_options.enabled = 1;
|
||||
|
||||
// a workers hould be running for at least 10 seconds
|
||||
uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] = 10;
|
||||
uwsgi.min_worker_lifetime = 10;
|
||||
|
||||
uwsgi.shared->spooler_frequency = 30;
|
||||
|
||||
@@ -413,7 +413,7 @@ void sanitize_args() {
|
||||
uwsgi.cores = uwsgi.threads;
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
if (!uwsgi.post_buffering) {
|
||||
uwsgi_log(" *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** \n");
|
||||
}
|
||||
@@ -449,13 +449,13 @@ void sanitize_args() {
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME] > 0 && uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] >= uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME]) {
|
||||
if (uwsgi.max_worker_lifetime > 0 && uwsgi.min_worker_lifetime >= uwsgi.max_worker_lifetime) {
|
||||
uwsgi_log("invalid min-worker-lifetime value (%d), must be lower than max-worker-lifetime (%d)\n",
|
||||
uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME], uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME]);
|
||||
uwsgi.min_worker_lifetime, uwsgi.max_worker_lifetime);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (uwsgi.cheaper_rss_limit_soft && uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] != 1 && uwsgi.force_get_memusage != 1) {
|
||||
if (uwsgi.cheaper_rss_limit_soft && uwsgi.logging_options.memory_report != 1 && uwsgi.force_get_memusage != 1) {
|
||||
uwsgi_log("enabling cheaper-rss-limit-soft requires enabling also memory-report\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ int uwsgi_waitfd_event(int fd, int timeout, int event) {
|
||||
struct pollfd upoll;
|
||||
|
||||
if (!timeout)
|
||||
timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT];
|
||||
timeout = uwsgi.socket_timeout;
|
||||
|
||||
timeout = timeout * 1000;
|
||||
if (timeout < 0)
|
||||
|
||||
+9
-9
@@ -573,7 +573,7 @@ void uwsgi_log_reopen() {
|
||||
|
||||
void log_request(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int log_it = uwsgi.shared->options[UWSGI_OPTION_LOGGING];
|
||||
int log_it = uwsgi.logging_options.enabled;
|
||||
|
||||
if (wsgi_req->do_not_log)
|
||||
return;
|
||||
@@ -583,25 +583,25 @@ void log_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
/* conditional logging */
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_ZERO] && wsgi_req->response_size == 0) {
|
||||
if (uwsgi.logging_options.zero && wsgi_req->response_size == 0) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW] && (uint32_t) wsgi_req_time >= uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW]) {
|
||||
if (uwsgi.logging_options.slow && (uint32_t) wsgi_req_time >= uwsgi.logging_options.slow) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_4xx] && (wsgi_req->status >= 400 && wsgi_req->status <= 499)) {
|
||||
if (uwsgi.logging_options._4xx && (wsgi_req->status >= 400 && wsgi_req->status <= 499)) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_5xx] && (wsgi_req->status >= 500 && wsgi_req->status <= 599)) {
|
||||
if (uwsgi.logging_options._5xx && (wsgi_req->status >= 500 && wsgi_req->status <= 599)) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_BIG] && (wsgi_req->response_size >= uwsgi.shared->options[UWSGI_OPTION_LOG_BIG])) {
|
||||
if (uwsgi.logging_options.big && (wsgi_req->response_size >= uwsgi.logging_options.big)) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SENDFILE] && wsgi_req->via == UWSGI_VIA_SENDFILE) {
|
||||
if (uwsgi.logging_options.sendfile && wsgi_req->via == UWSGI_VIA_SENDFILE) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_IOERROR] && wsgi_req->read_errors > 0 && wsgi_req->write_errors > 0) {
|
||||
if (uwsgi.logging_options.ioerror && wsgi_req->read_errors > 0 && wsgi_req->write_errors > 0) {
|
||||
goto logit;
|
||||
}
|
||||
|
||||
@@ -686,7 +686,7 @@ void uwsgi_logit_simple(struct wsgi_request *wsgi_req) {
|
||||
logvecpos++;
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1) {
|
||||
if (uwsgi.logging_options.memory_report == 1) {
|
||||
rlen = snprintf(mempkt, 4096, "{address space usage: %lld bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ", (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024,
|
||||
(unsigned long long) uwsgi.workers[uwsgi.mywid].rss_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].rss_size / 1024 / 1024);
|
||||
logvec[logvecpos].iov_base = mempkt;
|
||||
|
||||
+4
-6
@@ -241,13 +241,11 @@ static void master_check_listen_queue() {
|
||||
}
|
||||
if (uwsgi_sock->queue > 0 && uwsgi_sock->queue >= uwsgi_sock->max_queue) {
|
||||
uwsgi_log_verbose("*** uWSGI listen queue of socket \"%s\" (fd: %d) full !!! (%llu/%llu) ***\n", uwsgi_sock->name, uwsgi_sock->fd, (unsigned long long) uwsgi_sock->queue, (unsigned long long) uwsgi_sock->max_queue);
|
||||
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]++;
|
||||
}
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
}
|
||||
|
||||
uwsgi.shared->load = load;
|
||||
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS] = uwsgi.shared->load;
|
||||
if (uwsgi.vassal_sos_backlog > 0 && uwsgi.has_emperor) {
|
||||
if (uwsgi.shared->load >= (uint64_t) uwsgi.vassal_sos_backlog) {
|
||||
// ask emperor for help
|
||||
@@ -613,10 +611,10 @@ int master_loop(char **argv, char **environ) {
|
||||
if (diedpid == 0) {
|
||||
|
||||
/* all processes ok, doing status scan after N seconds */
|
||||
check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
check_interval = uwsgi.master_interval;
|
||||
if (!check_interval) {
|
||||
check_interval = 1;
|
||||
uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL] = 1;
|
||||
uwsgi.master_interval = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -715,10 +713,10 @@ int master_loop(char **argv, char **environ) {
|
||||
// check for idle
|
||||
uwsgi_master_check_idle();
|
||||
|
||||
check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
check_interval = uwsgi.master_interval;
|
||||
if (!check_interval) {
|
||||
check_interval = 1;
|
||||
uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL] = 1;
|
||||
uwsgi.master_interval = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -169,9 +169,9 @@ int uwsgi_master_check_workers_deadline() {
|
||||
}
|
||||
}
|
||||
// check if worker was running longer than allowed lifetime
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME] > 0) {
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.min_worker_lifetime > 0) {
|
||||
uint64_t lifetime = uwsgi_now() - uwsgi.workers[i].last_spawn;
|
||||
if (lifetime > uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME] && uwsgi.workers[i].manage_next_request == 1) {
|
||||
if (lifetime > uwsgi.min_worker_lifetime && uwsgi.workers[i].manage_next_request == 1) {
|
||||
uwsgi_log("worker %d lifetime reached, it was running for %llu second(s)\n", i, (unsigned long long) lifetime);
|
||||
uwsgi.workers[i].manage_next_request = 0;
|
||||
kill(uwsgi.workers[i].pid, SIGWINCH);
|
||||
|
||||
+4
-4
@@ -101,7 +101,7 @@ int uwsgi_calc_cheaper(void) {
|
||||
|
||||
int i;
|
||||
static time_t last_check = 0;
|
||||
int check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
int check_interval = uwsgi.master_interval;
|
||||
|
||||
if (!last_check)
|
||||
last_check = uwsgi_now();
|
||||
@@ -332,7 +332,7 @@ int uwsgi_cheaper_algo_backlog(int can_spawn) {
|
||||
|
||||
int i;
|
||||
#ifdef __linux__
|
||||
int backlog = uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS];
|
||||
int backlog = uwsgi.shared->load;
|
||||
#else
|
||||
int backlog = 0;
|
||||
#endif
|
||||
@@ -728,9 +728,9 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
|
||||
goto end;
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue", (unsigned long long) uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS]))
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue", (unsigned long long) uwsgi.shared->load))
|
||||
goto end;
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue_errors", (unsigned long long) uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]))
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue_errors", (unsigned long long) uwsgi.shared->load))
|
||||
goto end;
|
||||
#endif
|
||||
|
||||
|
||||
+4
-4
@@ -476,8 +476,8 @@ int uwsgi_postbuffer_do_in_mem(struct wsgi_request *wsgi_req) {
|
||||
char *ptr = wsgi_req->post_buffering_buf;
|
||||
|
||||
while (remains > 0) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
inc_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
ssize_t rlen = wsgi_req->socket->proto_read_body(wsgi_req, ptr, remains);
|
||||
@@ -550,8 +550,8 @@ int uwsgi_postbuffer_do_in_disk(struct wsgi_request *wsgi_req) {
|
||||
while (post_remains > 0) {
|
||||
|
||||
// during post buffering we need to constantly reset the harakiri
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
inc_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
// we use the already available post buffering buffer to read chunks....
|
||||
|
||||
+4
-4
@@ -117,7 +117,7 @@ char *uwsgi_do_rpc(char *node, char *func, uint8_t argc, char *argv[], uint16_t
|
||||
return NULL;
|
||||
|
||||
// wait for connection;
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
@@ -156,14 +156,14 @@ char *uwsgi_do_rpc(char *node, char *func, uint8_t argc, char *argv[], uint16_t
|
||||
}
|
||||
|
||||
// ok the request is ready, let's send it in non blocking way
|
||||
if (uwsgi_write_true_nb(fd, buffer, buffer_size+4, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_write_true_nb(fd, buffer, buffer_size+4, uwsgi.socket_timeout)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
// ok time to wait for the response in non blocking way
|
||||
size_t rlen = buffer_size+4;
|
||||
uint8_t modifier2 = 0;
|
||||
if (uwsgi_read_with_realloc(fd, &buffer, &rlen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], NULL, &modifier2)) {
|
||||
if (uwsgi_read_with_realloc(fd, &buffer, &rlen, uwsgi.socket_timeout, NULL, &modifier2)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ char *uwsgi_do_rpc(char *node, char *func, uint8_t argc, char *argv[], uint16_t
|
||||
rlen = content_len;
|
||||
|
||||
// read the raw value from the socket
|
||||
if (uwsgi_read_whole_true_nb(fd, buffer, rlen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_read_whole_true_nb(fd, buffer, rlen, uwsgi.socket_timeout)) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-9
@@ -45,21 +45,21 @@ int uwsgi_signal_handler(uint8_t sig) {
|
||||
uwsgi.workers[uwsgi.mywid].sig = 1;
|
||||
uwsgi.workers[uwsgi.mywid].signum = sig;
|
||||
uwsgi.workers[uwsgi.mywid].signals++;
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
}
|
||||
else if (uwsgi.muleid > 0) {
|
||||
uwsgi.mules[uwsgi.muleid - 1].sig = 1;
|
||||
uwsgi.mules[uwsgi.muleid - 1].signum = sig;
|
||||
uwsgi.mules[uwsgi.muleid - 1].signals++;
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI] > 0) {
|
||||
set_mule_harakiri(uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.mules > 0) {
|
||||
set_mule_harakiri(uwsgi.harakiri_options.mules);
|
||||
}
|
||||
}
|
||||
else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(uwsgi.harakiri_options.spoolers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ int uwsgi_signal_handler(uint8_t sig) {
|
||||
}
|
||||
}
|
||||
else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(0);
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ int uwsgi_remote_signal_send(char *addr, uint8_t sig) {
|
||||
uh.pktsize = 0;
|
||||
uh.modifier2 = sig;
|
||||
|
||||
int fd = uwsgi_connect(addr, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
int fd = uwsgi_connect(addr, uwsgi.socket_timeout, 0);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
@@ -279,7 +279,7 @@ int uwsgi_remote_signal_send(char *addr, uint8_t sig) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], NULL);
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.socket_timeout, NULL);
|
||||
|
||||
close(fd);
|
||||
return ret;
|
||||
|
||||
+1
-1
@@ -750,7 +750,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
|
||||
if (!uwsgi.no_defer_accept) {
|
||||
|
||||
#ifdef __linux__
|
||||
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], sizeof(int))) {
|
||||
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.socket_timeout, sizeof(int))) {
|
||||
uwsgi_error("TCP_DEFER_ACCEPT setsockopt()");
|
||||
}
|
||||
// OSX has no SO_ACCEPTFILTER !!!
|
||||
|
||||
+3
-3
@@ -552,11 +552,11 @@ void spooler_manage_task(struct uwsgi_spooler *uspool, char *dir, char *task) {
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (uwsgi.p[i]->spooler) {
|
||||
time_t now = uwsgi_now();
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(uwsgi.harakiri_options.spoolers);
|
||||
}
|
||||
ret = uwsgi.p[i]->spooler(task, spool_buf, uh.pktsize, body, body_len);
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(0);
|
||||
}
|
||||
if (ret == 0)
|
||||
|
||||
+1
-1
@@ -379,7 +379,7 @@ void uwsgi_send_stats(int fd, struct uwsgi_stats *(*func) (void)) {
|
||||
size_t remains = us->pos;
|
||||
off_t pos = 0;
|
||||
while (remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
goto end0;
|
||||
}
|
||||
|
||||
+15
-15
@@ -47,7 +47,7 @@ void inc_harakiri(int sec) {
|
||||
uwsgi.workers[uwsgi.mywid].harakiri += sec;
|
||||
}
|
||||
else {
|
||||
alarm(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] + sec);
|
||||
alarm(uwsgi.harakiri_options.workers + sec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +588,7 @@ void uwsgi_as_root() {
|
||||
exit(1);
|
||||
}
|
||||
#ifdef __linux__
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG]) {
|
||||
if (uwsgi.logging_options.memory_report) {
|
||||
uwsgi_log("*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n");
|
||||
}
|
||||
#endif
|
||||
@@ -620,7 +620,7 @@ void uwsgi_as_root() {
|
||||
uwsgi_error("pivot_root()");
|
||||
exit(1);
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG]) {
|
||||
if (uwsgi.logging_options.memory_report) {
|
||||
uwsgi_log("*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n");
|
||||
}
|
||||
free(arg);
|
||||
@@ -1028,7 +1028,7 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
uwsgi.workers[uwsgi.mywid].avg_response_time = (uwsgi.workers[uwsgi.mywid].avg_response_time + tmp_rt) / 2;
|
||||
|
||||
// get memory usage
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
get_memusage(&rss, &vsz);
|
||||
uwsgi.workers[uwsgi.mywid].vsz_size = vsz;
|
||||
uwsgi.workers[uwsgi.mywid].rss_size = rss;
|
||||
@@ -1108,7 +1108,7 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
// defunct process reaper
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_REAPER] == 1) {
|
||||
if (uwsgi.reaper == 1) {
|
||||
while (waitpid(WAIT_ANY, &waitpid_status, WNOHANG) > 0);
|
||||
}
|
||||
|
||||
@@ -1160,16 +1160,16 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
// yes, this is pretty useless but we cannot ensure all of the plugin have the same behaviour
|
||||
uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].in_request = 0;
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS] > 0 && uwsgi.workers[uwsgi.mywid].delta_requests >= uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS]
|
||||
&& (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] * 1000000)) {
|
||||
if (uwsgi.max_requests > 0 && uwsgi.workers[uwsgi.mywid].delta_requests >= uwsgi.max_requests
|
||||
&& (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.min_worker_lifetime * 1000000)) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
if (uwsgi.reload_on_as && (rlim_t) vsz >= uwsgi.reload_on_as && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] * 1000000)) {
|
||||
if (uwsgi.reload_on_as && (rlim_t) vsz >= uwsgi.reload_on_as && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.min_worker_lifetime * 1000000)) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
if (uwsgi.reload_on_rss && (rlim_t) rss >= uwsgi.reload_on_rss && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] * 1000000)) {
|
||||
if (uwsgi.reload_on_rss && (rlim_t) rss >= uwsgi.reload_on_rss && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.min_worker_lifetime * 1000000)) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
@@ -1345,13 +1345,13 @@ int wsgi_req_async_recv(struct wsgi_request *wsgi_req) {
|
||||
if (event_queue_add_fd_read(uwsgi.async_queue, wsgi_req->fd) < 0)
|
||||
return -1;
|
||||
|
||||
async_add_timeout(wsgi_req, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
async_add_timeout(wsgi_req, uwsgi.socket_timeout);
|
||||
uwsgi.async_proto_fd_table[wsgi_req->fd] = wsgi_req;
|
||||
}
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1382,8 +1382,8 @@ int wsgi_req_recv(int queue, struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
@@ -3859,7 +3859,7 @@ int uwsgi_send_http_stats(int fd) {
|
||||
|
||||
char buf[4096];
|
||||
|
||||
int ret = uwsgi_waitfd(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
|
||||
|
||||
+12
-33
@@ -76,13 +76,13 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"processes", required_argument, 'p', "spawn the specified number of workers/processes", uwsgi_opt_set_int, &uwsgi.numproc, 0},
|
||||
{"workers", required_argument, 'p', "spawn the specified number of workers/processes", uwsgi_opt_set_int, &uwsgi.numproc, 0},
|
||||
{"thunder-lock", no_argument, 0, "serialize accept() usage (if possible)", uwsgi_opt_true, &uwsgi.use_thunder_lock, 0},
|
||||
{"harakiri", required_argument, 't', "set harakiri timeout", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_HARAKIRI, 0},
|
||||
{"harakiri", required_argument, 't', "set harakiri timeout", uwsgi_opt_set_int, &uwsgi.harakiri_options.workers, 0},
|
||||
{"harakiri-verbose", no_argument, 0, "enable verbose mode for harakiri", uwsgi_opt_true, &uwsgi.harakiri_verbose, 0},
|
||||
{"harakiri-no-arh", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0},
|
||||
{"no-harakiri-arh", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0},
|
||||
{"no-harakiri-after-req-hook", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0},
|
||||
{"backtrace-depth", required_argument, 0, "set backtrace depth", uwsgi_opt_set_int, &uwsgi.backtrace_depth, 0},
|
||||
{"mule-harakiri", required_argument, 0, "set harakiri timeout for mule tasks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MULE_HARAKIRI, 0},
|
||||
{"mule-harakiri", required_argument, 0, "set harakiri timeout for mule tasks", uwsgi_opt_set_int, &uwsgi.harakiri_options.mules, 0},
|
||||
#ifdef UWSGI_XML
|
||||
{"xmlconfig", required_argument, 'x', "load config from xml file", uwsgi_opt_load_xml, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"xml", required_argument, 'x', "load config from xml file", uwsgi_opt_load_xml, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
@@ -164,9 +164,9 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"max-vars", required_argument, 'v', "set the amount of internal iovec/vars structures", uwsgi_opt_max_vars, NULL, 0},
|
||||
{"max-apps", required_argument, 0, "set the maximum number of per-worker applications", uwsgi_opt_set_int, &uwsgi.max_apps, 0},
|
||||
{"buffer-size", required_argument, 'b', "set internal buffer size", uwsgi_opt_set_16bit, &uwsgi.buffer_size, 0},
|
||||
{"memory-report", no_argument, 'm', "enable memory report", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_MEMORY_DEBUG, 0},
|
||||
{"memory-report", no_argument, 'm', "enable memory report", uwsgi_opt_true, &uwsgi.logging_options.memory_report, 0},
|
||||
{"profiler", required_argument, 0, "enable the specified profiler", uwsgi_opt_set_str, &uwsgi.profiler, 0},
|
||||
{"cgi-mode", no_argument, 'c', "force CGI-mode for plugins supporting it", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_CGI_MODE, 0},
|
||||
{"cgi-mode", no_argument, 'c', "force CGI-mode for plugins supporting it", uwsgi_opt_true, &uwsgi.cgi_mode, 0},
|
||||
{"abstract-socket", no_argument, 'a', "force UNIX socket in abstract mode (Linux only)", uwsgi_opt_true, &uwsgi.abstract_socket, 0},
|
||||
{"chmod-socket", optional_argument, 'C', "chmod-socket", uwsgi_opt_chmod_socket, NULL, 0},
|
||||
{"chmod", optional_argument, 'C', "chmod-socket", uwsgi_opt_chmod_socket, NULL, 0},
|
||||
@@ -248,8 +248,8 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"print-sym", required_argument, 0, "print content of the specified binary symbol", uwsgi_print_sym, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"print-symbol", required_argument, 0, "print content of the specified binary symbol", uwsgi_print_sym, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
{"reaper", no_argument, 'r', "call waitpid(-1,...) after each request to get rid of zombies", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_REAPER, 0},
|
||||
{"max-requests", required_argument, 'R', "reload workers after the specified amount of managed requests", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MAX_REQUESTS, 0},
|
||||
{"reaper", no_argument, 'r', "call waitpid(-1,...) after each request to get rid of zombies", uwsgi_opt_dyn_true, uwsgi_reaper, 0},
|
||||
{"max-requests", required_argument, 'R', "reload workers after the specified amount of managed requests", uwsgi_opt_set_64bit, uwsgi.max_requests, 0},
|
||||
{"min-worker-lifetime", required_argument, 0, "number of seconds worker must run before being reloaded (default is 60)", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MIN_WORKER_LIFETIME, 0},
|
||||
{"max-worker-lifetime", required_argument, 0, "reload workers after the specified amount of seconds (default is disabled)", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MAX_WORKER_LIFETIME, 0},
|
||||
|
||||
@@ -610,7 +610,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"sni-regexp", required_argument, 0, "add an SNI-governed SSL context (the key is a regexp)", uwsgi_opt_sni, NULL, 0},
|
||||
#endif
|
||||
#endif
|
||||
{"check-interval", required_argument, 0, "set the interval (in seconds) of master checks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MASTER_INTERVAL, 0},
|
||||
{"check-interval", required_argument, 0, "set the interval (in seconds) of master checks", uwsgi_opt_set_int, uwsgi.master_internal, UWSGI_OPT_MASTER},
|
||||
{"forkbomb-delay", required_argument, 0, "sleep for the specified number of seconds when a forkbomb is detected", uwsgi_opt_set_int, &uwsgi.forkbomb_delay, UWSGI_OPT_MASTER},
|
||||
{"binary-path", required_argument, 0, "force binary path", uwsgi_opt_set_str, &uwsgi.binary_path, 0},
|
||||
{"privileged-binary-patch", required_argument, 0, "patch the uwsgi binary with a new command (before privileges drop)", uwsgi_opt_set_str, &uwsgi.privileged_binary_patch, 0},
|
||||
@@ -677,7 +677,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"log-date", optional_argument, 0, "prefix logs with date or a strftime string", uwsgi_opt_log_date, NULL, 0},
|
||||
{"log-prefix", optional_argument, 0, "prefix logs with a string", uwsgi_opt_log_date, NULL, 0},
|
||||
|
||||
{"log-zero", no_argument, 0, "log responses without body", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_ZERO, 0},
|
||||
{"log-zero", no_argument, 0, "log responses without body", uwsgi_opt_true, uwsgi.logging_options.zero, 0},
|
||||
{"log-slow", required_argument, 0, "log requests slower than the specified number of milliseconds", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_LOG_SLOW, 0},
|
||||
{"log-4xx", no_argument, 0, "log requests with a 4xx response", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_4xx, 0},
|
||||
{"log-5xx", no_argument, 0, "log requests with a 5xx response", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_5xx, 0},
|
||||
@@ -1375,7 +1375,7 @@ void what_i_am_doing() {
|
||||
#else
|
||||
ctime_r((const time_t *) &wsgi_req->start_of_request_in_sec, ctime_storage);
|
||||
#endif
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
if (uwsgi.harakiri_options.workers > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
uwsgi_log("HARAKIRI: --- uWSGI worker %d core %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, i, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage);
|
||||
}
|
||||
else {
|
||||
@@ -1392,14 +1392,14 @@ void what_i_am_doing() {
|
||||
#else
|
||||
ctime_r((const time_t *) &wsgi_req->start_of_request_in_sec, ctime_storage);
|
||||
#endif
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
if (uwsgi.harakiri_options.workers > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
uwsgi_log("HARAKIRI: --- uWSGI worker %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("SIGUSR2: --- uWSGI worker %d (pid: %d) is managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage);
|
||||
}
|
||||
}
|
||||
else if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now() && uwsgi.workers[uwsgi.mywid].sig) {
|
||||
else if (uwsgi.harakiri_options.workers > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now() && uwsgi.workers[uwsgi.mywid].sig) {
|
||||
uwsgi_log("HARAKIRI: --- uWSGI worker %d (pid: %d) WAS handling signal %d ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, uwsgi.workers[uwsgi.mywid].signum);
|
||||
}
|
||||
}
|
||||
@@ -3222,7 +3222,7 @@ void uwsgi_worker_run() {
|
||||
}
|
||||
|
||||
// setup UNIX signals for the worker
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && !uwsgi.master_process) {
|
||||
if (uwsgi.harakiri_options.workers > 0 && !uwsgi.master_process) {
|
||||
signal(SIGALRM, (void *) &harakiri);
|
||||
}
|
||||
uwsgi_unix_signal(SIGHUP, gracefully_kill);
|
||||
@@ -3820,27 +3820,6 @@ void uwsgi_opt_set_megabytes(char *opt, char *value, void *key) {
|
||||
*ptr = (uint64_t)strtoul(value, NULL, 10) * 1024 * 1024;
|
||||
}
|
||||
|
||||
void uwsgi_opt_set_dyn(char *opt, char *value, void *key) {
|
||||
|
||||
long *fake_ptr = (long *) key;
|
||||
uint8_t dyn_opt_id = (long) fake_ptr;
|
||||
uwsgi.shared->options[dyn_opt_id] = atoi(value);
|
||||
}
|
||||
|
||||
void uwsgi_opt_dyn_true(char *opt, char *value, void *key) {
|
||||
|
||||
long *fake_ptr = (long *) key;
|
||||
uint8_t dyn_opt_id = (long) fake_ptr;
|
||||
uwsgi.shared->options[dyn_opt_id] = 1;
|
||||
}
|
||||
|
||||
void uwsgi_opt_dyn_false(char *opt, char *value, void *key) {
|
||||
|
||||
long *fake_ptr = (long *) key;
|
||||
uint8_t dyn_opt_id = (long) fake_ptr;
|
||||
uwsgi.shared->options[dyn_opt_id] = 0;
|
||||
}
|
||||
|
||||
void uwsgi_opt_set_str(char *opt, char *value, void *key) {
|
||||
char **ptr = (char **) key;
|
||||
if (!value) {
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
/* uwsgi ADMIN|10 */
|
||||
int uwsgi_request_admin(struct wsgi_request *wsgi_req) {
|
||||
|
||||
uint32_t opt_value = 0;
|
||||
|
||||
if (wsgi_req->uh->pktsize != 0 && wsgi_req->uh->pktsize != 4)
|
||||
return UWSGI_OK;
|
||||
|
||||
// write request
|
||||
if (wsgi_req->uh->pktsize == 4) {
|
||||
memcpy(&opt_value, wsgi_req->buffer, 4);
|
||||
uwsgi_log( "setting internal option %d to %d\n", wsgi_req->uh->modifier2, opt_value);
|
||||
uwsgi.shared->options[wsgi_req->uh->modifier2] = opt_value;
|
||||
|
||||
// ACK
|
||||
wsgi_req->uh->modifier1 = 255;
|
||||
wsgi_req->uh->pktsize = 0;
|
||||
wsgi_req->uh->modifier2 = 1;
|
||||
uwsgi_response_write_body_do(wsgi_req, (char *)wsgi_req->uh , 4);
|
||||
}
|
||||
// get request
|
||||
else {
|
||||
uwsgi_log( "internal option %d = %d\n", wsgi_req->uh->modifier2, uwsgi.shared->options[wsgi_req->uh->modifier2]);
|
||||
|
||||
wsgi_req->uh->modifier1 = 10;
|
||||
wsgi_req->uh->pktsize = 4;
|
||||
uwsgi_response_write_body_do(wsgi_req, (char *)wsgi_req->uh , 4);
|
||||
uwsgi_response_write_body_do(wsgi_req, (char *) &uwsgi.shared->options[wsgi_req->uh->modifier2], 4);
|
||||
}
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
|
||||
struct uwsgi_plugin admin_plugin = {
|
||||
|
||||
.name = "admin",
|
||||
.modifier1 = 10,
|
||||
.request = uwsgi_request_admin,
|
||||
|
||||
};
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
NAME='admin'
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = []
|
||||
|
||||
GCC_LIST = ['admin_plugin']
|
||||
@@ -281,7 +281,7 @@ static int carbon_push_stats(int retry_cycle, time_t now) {
|
||||
total_busyness += worker_busyness;
|
||||
u_carbon.was_busy[i-1] = 0;
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
// only running workers are counted in total memory stats and if memory-report option is enabled
|
||||
total_rss += uwsgi.workers[i].rss_size;
|
||||
total_vsz += uwsgi.workers[i].vsz_size;
|
||||
@@ -294,7 +294,7 @@ static int carbon_push_stats(int retry_cycle, time_t now) {
|
||||
wok = carbon_write(fd, "%s%s.%s.worker%d.requests %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) uwsgi.workers[i].requests, (unsigned long long) now);
|
||||
if (!wok) goto clear;
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
wok = carbon_write(fd, "%s%s.%s.worker%d.rss_size %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) uwsgi.workers[i].rss_size, (unsigned long long) now);
|
||||
if (!wok) goto clear;
|
||||
|
||||
@@ -327,7 +327,7 @@ static int carbon_push_stats(int retry_cycle, time_t now) {
|
||||
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
wok = carbon_write(fd, "%s%s.%s.rss_size %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, (unsigned long long) total_rss, (unsigned long long) now);
|
||||
if (!wok) goto clear;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ static void uwsgi_opt_setup_gevent(char *opt, char *value, void *null) {
|
||||
|
||||
// set async mode
|
||||
uwsgi_opt_set_int(opt, value, &uwsgi.async);
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] < 30) {
|
||||
uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 30;
|
||||
if (uwsgi.socket_timeout < 30) {
|
||||
uwsgi.socket_timeout = 30;
|
||||
}
|
||||
// set loop engine
|
||||
uwsgi.loop = "gevent";
|
||||
|
||||
@@ -124,7 +124,7 @@ done:
|
||||
ums = (struct uwsgi_mongodb_state *) ul->data;
|
||||
|
||||
if (ums->fd == -1) {
|
||||
ums->fd = uwsgi_connect(ums->address, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
ums->fd = uwsgi_connect(ums->address, uwsgi.socket_timeout, 0);
|
||||
}
|
||||
|
||||
if (ums->fd == -1) return -1;
|
||||
|
||||
@@ -26,7 +26,7 @@ int nagios() {
|
||||
}
|
||||
|
||||
|
||||
int fd = uwsgi_connect(uwsgi.sockets->name, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
int fd = uwsgi_connect(uwsgi.sockets->name, uwsgi.socket_timeout, 0);
|
||||
if (fd < 0) {
|
||||
fprintf(stdout, "UWSGI CRITICAL: could not connect() to workers %s\n", strerror(errno));
|
||||
if (errno == EPERM || errno == EACCES) {
|
||||
@@ -45,7 +45,7 @@ int nagios() {
|
||||
}
|
||||
|
||||
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &buf);
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.socket_timeout, &buf);
|
||||
|
||||
if (ret == -2) {
|
||||
fprintf(stdout, "UWSGI CRITICAL: timed out waiting for response\n");
|
||||
|
||||
@@ -1801,7 +1801,7 @@ static void uwsgi_python_harakiri(int wid) {
|
||||
if (fd < 1)
|
||||
goto exit;
|
||||
|
||||
int ret = uwsgi_waitfd(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@@ -174,7 +174,18 @@ char *uwsgi_encode_pydict(PyObject * pydict, uint16_t * size) {
|
||||
|
||||
static PyObject *py_uwsgi_listen_queue(PyObject * self, PyObject * args) {
|
||||
|
||||
return PyInt_FromLong(uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS]);
|
||||
int id = 0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|i:listen_queue", &id)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi_get_socket_by_num(id);
|
||||
if (!uwsgi_sock) {
|
||||
return PyErr_Format(PyExc_ValueError, "unable to find socket %d", id);
|
||||
}
|
||||
|
||||
return PyInt_FromLong(uwsgi_sock->queue);
|
||||
}
|
||||
|
||||
static PyObject *py_uwsgi_close(PyObject * self, PyObject * args) {
|
||||
@@ -1931,46 +1942,6 @@ PyObject *py_uwsgi_spooler_pid(PyObject * self, PyObject * args) {
|
||||
}
|
||||
|
||||
|
||||
PyObject *py_uwsgi_get_option(PyObject * self, PyObject * args) {
|
||||
int opt_id;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:get_option", &opt_id)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyInt_FromLong(uwsgi.shared->options[(uint8_t) opt_id]);
|
||||
}
|
||||
|
||||
PyObject *py_uwsgi_set_option(PyObject * self, PyObject * args) {
|
||||
int opt_id;
|
||||
int value;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii:set_option", &opt_id, &value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uwsgi.shared->options[(uint8_t) opt_id] = (uint32_t) value;
|
||||
return PyInt_FromLong(value);
|
||||
}
|
||||
|
||||
PyObject *py_uwsgi_has_hook(PyObject * self, PyObject * args) {
|
||||
int modifier1;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:has_hook", &modifier1)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
if (uwsgi.shared->hooks[modifier1] != unconfigured_hook) {
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
}
|
||||
*/
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *py_uwsgi_connect(PyObject * self, PyObject * args) {
|
||||
|
||||
char *socket_name = NULL;
|
||||
@@ -2221,21 +2192,6 @@ PyObject *py_uwsgi_stop(PyObject * self, PyObject * args) {
|
||||
return Py_True;
|
||||
}
|
||||
|
||||
|
||||
/* blocking hint */
|
||||
PyObject *py_uwsgi_set_blocking(PyObject * self, PyObject * args) {
|
||||
|
||||
if (uwsgi.master_process) {
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
}
|
||||
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
PyObject *py_uwsgi_request_id(PyObject * self, PyObject * args) {
|
||||
return PyLong_FromUnsignedLongLong(uwsgi.workers[uwsgi.mywid].requests);
|
||||
}
|
||||
@@ -2437,11 +2393,6 @@ static PyMethodDef uwsgi_advanced_methods[] = {
|
||||
{"workers", py_uwsgi_workers, METH_VARARGS, ""},
|
||||
{"masterpid", py_uwsgi_masterpid, METH_VARARGS, ""},
|
||||
{"total_requests", py_uwsgi_total_requests, METH_VARARGS, ""},
|
||||
{"getoption", py_uwsgi_get_option, METH_VARARGS, ""},
|
||||
{"get_option", py_uwsgi_get_option, METH_VARARGS, ""},
|
||||
{"setoption", py_uwsgi_set_option, METH_VARARGS, ""},
|
||||
{"set_option", py_uwsgi_set_option, METH_VARARGS, ""},
|
||||
{"sorry_i_need_to_block", py_uwsgi_set_blocking, METH_VARARGS, ""},
|
||||
{"request_id", py_uwsgi_request_id, METH_VARARGS, ""},
|
||||
{"worker_id", py_uwsgi_worker_id, METH_VARARGS, ""},
|
||||
{"mule_id", py_uwsgi_mule_id, METH_VARARGS, ""},
|
||||
@@ -2482,7 +2433,6 @@ static PyMethodDef uwsgi_advanced_methods[] = {
|
||||
{"offload", py_uwsgi_offload, METH_VARARGS, ""},
|
||||
{"set_warning_message", py_uwsgi_warning, METH_VARARGS, ""},
|
||||
{"mem", py_uwsgi_mem, METH_VARARGS, ""},
|
||||
{"has_hook", py_uwsgi_has_hook, METH_VARARGS, ""},
|
||||
{"logsize", py_uwsgi_logsize, METH_VARARGS, ""},
|
||||
#ifdef UWSGI_SSL
|
||||
{"i_am_the_lord", py_uwsgi_i_am_the_lord, METH_VARARGS, ""},
|
||||
|
||||
@@ -68,7 +68,7 @@ static int uwsgi_routing_func_http(struct wsgi_request *wsgi_req, struct uwsgi_r
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi_proxy_nb(wsgi_req, ub_addr->buf, ub, remains, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_proxy_nb(wsgi_req, ub_addr->buf, ub, remains, uwsgi.socket_timeout)) {
|
||||
uwsgi_log("error routing request to http server %s\n", ub_addr->buf);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ end:
|
||||
|
||||
struct uwsgi_buffer *uwsgi_proto_base_prepare_headers(struct wsgi_request *wsgi_req, char *s, uint16_t sl) {
|
||||
struct uwsgi_buffer *ub = NULL;
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_CGI_MODE] == 0) {
|
||||
if (uwsgi.cgi_mode == 0) {
|
||||
if (wsgi_req->protocol_len) {
|
||||
ub = uwsgi_buffer_new(wsgi_req->protocol_len + 1 + sl + 2);
|
||||
if (uwsgi_buffer_append(ub, wsgi_req->protocol, wsgi_req->protocol_len)) goto end;
|
||||
|
||||
+3
-3
@@ -245,7 +245,7 @@ int uwsgi_proto_fastcgi_write(struct wsgi_request *wsgi_req, char *buf, size_t l
|
||||
fr.reserved = 0;
|
||||
fr.cl0 = (uint8_t) (fcgi_len & 0xff);
|
||||
fr.cl1 = (uint8_t) ((fcgi_len >> 8) & 0xff);
|
||||
if (uwsgi_write_true_nb(wsgi_req->fd, (char *) &fr, sizeof(struct fcgi_record), uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_write_true_nb(wsgi_req->fd, (char *) &fr, sizeof(struct fcgi_record), uwsgi.socket_timeout)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -278,7 +278,7 @@ void uwsgi_proto_fastcgi_close(struct wsgi_request *wsgi_req) {
|
||||
end_request[3] = sid[0];
|
||||
end_request[10] = sid[1];
|
||||
end_request[11] = sid[0];
|
||||
(void) uwsgi_write_true_nb(wsgi_req->fd, end_request, 24, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
(void) uwsgi_write_true_nb(wsgi_req->fd, end_request, 24, uwsgi.socket_timeout);
|
||||
uwsgi_proto_base_close(wsgi_req);
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ int uwsgi_proto_fastcgi_sendfile(struct wsgi_request *wsgi_req, int fd, size_t p
|
||||
fr.reserved = 0;
|
||||
fr.cl0 = (uint8_t) (fcgi_len & 0xff);
|
||||
fr.cl1 = (uint8_t) ((fcgi_len >> 8) & 0xff);
|
||||
if (uwsgi_write_true_nb(wsgi_req->fd, (char *) &fr, sizeof(struct fcgi_record), uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_write_true_nb(wsgi_req->fd, (char *) &fr, sizeof(struct fcgi_record), uwsgi.socket_timeout)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,8 +429,8 @@ struct uwsgi_lock_ops {
|
||||
#define uwsgi_wlock(x) uwsgi.lock_ops.wlock(x)
|
||||
#define uwsgi_rwunlock(x) uwsgi.lock_ops.rwunlock(x)
|
||||
|
||||
#define uwsgi_wait_read_req(x) uwsgi.wait_read_hook(x->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) ; x->switches++
|
||||
#define uwsgi_wait_write_req(x) uwsgi.wait_write_hook(x->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]) ; x->switches++
|
||||
#define uwsgi_wait_read_req(x) uwsgi.wait_read_hook(x->fd, uwsgi.socket_timeout) ; x->switches++
|
||||
#define uwsgi_wait_write_req(x) uwsgi.wait_write_hook(x->fd, uwsgi.socket_timeout) ; x->switches++
|
||||
|
||||
#ifdef UWSGI_PCRE
|
||||
#include <pcre.h>
|
||||
@@ -854,29 +854,6 @@ struct uwsgi_opt {
|
||||
#include <machine/endian.h>
|
||||
#endif
|
||||
|
||||
#define UWSGI_OPTION_LOGGING 0
|
||||
#define UWSGI_OPTION_MAX_REQUESTS 1
|
||||
#define UWSGI_OPTION_SOCKET_TIMEOUT 2
|
||||
#define UWSGI_OPTION_MEMORY_DEBUG 3
|
||||
#define UWSGI_OPTION_MASTER_INTERVAL 4
|
||||
#define UWSGI_OPTION_HARAKIRI 5
|
||||
#define UWSGI_OPTION_CGI_MODE 6
|
||||
#define UWSGI_OPTION_THREADS 7
|
||||
#define UWSGI_OPTION_REAPER 8
|
||||
#define UWSGI_OPTION_LOG_ZERO 9
|
||||
#define UWSGI_OPTION_LOG_SLOW 10
|
||||
#define UWSGI_OPTION_LOG_4xx 11
|
||||
#define UWSGI_OPTION_LOG_5xx 12
|
||||
#define UWSGI_OPTION_LOG_BIG 13
|
||||
#define UWSGI_OPTION_LOG_SENDFILE 14
|
||||
#define UWSGI_OPTION_BACKLOG_STATUS 15
|
||||
#define UWSGI_OPTION_BACKLOG_ERRORS 16
|
||||
#define UWSGI_OPTION_SPOOLER_HARAKIRI 17
|
||||
#define UWSGI_OPTION_MULE_HARAKIRI 18
|
||||
#define UWSGI_OPTION_MAX_WORKER_LIFETIME 19
|
||||
#define UWSGI_OPTION_MIN_WORKER_LIFETIME 20
|
||||
#define UWSGI_OPTION_LOG_IOERROR 21
|
||||
|
||||
#define UWSGI_SPOOLER_EXTERNAL 1
|
||||
|
||||
#define UWSGI_MODIFIER_ADMIN_REQUEST 10
|
||||
@@ -1660,6 +1637,24 @@ void uwsgi_opt_load_config(char *, char *, void *);
|
||||
|
||||
struct uwsgi_metric;
|
||||
|
||||
struct uwsgi_logging_options {
|
||||
int enabled;
|
||||
int memory_report;
|
||||
int zero;
|
||||
int _4xx;
|
||||
int _5xx;
|
||||
int sendfile;
|
||||
int ioerror;
|
||||
uint32_t slow;
|
||||
uint64_t big;
|
||||
};
|
||||
|
||||
struct uwsgi_harakiri_options {
|
||||
int workers;
|
||||
int spoolers;
|
||||
int mules;
|
||||
};
|
||||
|
||||
struct uwsgi_server {
|
||||
|
||||
// store the machine hostname
|
||||
@@ -1683,6 +1678,15 @@ struct uwsgi_server {
|
||||
char *procname_master;
|
||||
char *procname;
|
||||
|
||||
struct uwsgi_logging_options logging_options;
|
||||
struct uwsgi_harakiri_options harakiri_options;
|
||||
int socket_timeout;
|
||||
int reaper;
|
||||
int cgi_mode;
|
||||
uint64_t max_requests;
|
||||
uint64_t min_worker_lifetime;
|
||||
uint64_t max_worker_lifetime;
|
||||
|
||||
// daemontools-like envdir
|
||||
struct uwsgi_string_list *envdirs;
|
||||
|
||||
@@ -2324,6 +2328,7 @@ struct uwsgi_server {
|
||||
|
||||
int master_process;
|
||||
int master_queue;
|
||||
int master_interval;
|
||||
|
||||
// mainly iseful for broodlord mode
|
||||
int vassal_sos_backlog;
|
||||
@@ -2725,8 +2730,6 @@ struct uwsgi_shared {
|
||||
//vga 80 x25 specific !
|
||||
char warning_message[81];
|
||||
|
||||
uint32_t options[256];
|
||||
|
||||
off_t logsize;
|
||||
|
||||
char snmp_community[72 + 1];
|
||||
|
||||
Reference in New Issue
Block a user