mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 13:41:28 +00:00
removed the probe subsystem
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
int connect_prober_callback(int interesting_fd, struct uwsgi_signal_probe *up) {
|
||||
|
||||
// is this a timeout event ?
|
||||
if (interesting_fd == -1) {
|
||||
// am i wating for something ?
|
||||
if (up->fd != -1) {
|
||||
if (up->cycles > (uint64_t) up->timeout) {
|
||||
// reset the cycle
|
||||
up->cycles = 0;
|
||||
close(up->fd);
|
||||
up->fd = -1;
|
||||
// state = NOOP
|
||||
up->state = 0;
|
||||
// avoid duplicated events
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ok register a new event
|
||||
else {
|
||||
if ((up->cycles % up->freq) == 0) {
|
||||
up->fd = uwsgi_connect(up->args, -1, 1);
|
||||
if (up->fd != -1) {
|
||||
// status = CONNECTING
|
||||
up->state = 1;
|
||||
event_queue_add_fd_write(uwsgi.master_queue, up->fd);
|
||||
return 0;
|
||||
}
|
||||
// signal the bad event (if not already bad)
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (up->fd != -1) {
|
||||
// is this event for me ?
|
||||
if (interesting_fd == up->fd) {
|
||||
// uselsess here (we have only one state), only to show a good practice
|
||||
// check the state
|
||||
if (up->state == 1) {
|
||||
if (uwsgi_is_bad_connection(up->fd)) {
|
||||
// signal the bad connection (if needed)
|
||||
up->cycles = 0;
|
||||
close(up->fd);
|
||||
up->fd = -1;
|
||||
// state = NOOP
|
||||
up->state = 0;
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// this is a good connection
|
||||
up->cycles = 0;
|
||||
close(up->fd);
|
||||
up->fd = -1;
|
||||
// state = NOOP
|
||||
up->state = 0;
|
||||
if (up->bad) {
|
||||
up->bad = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// default action
|
||||
return 0;
|
||||
}
|
||||
|
||||
int probeconnect_init() {
|
||||
|
||||
uwsgi_probe_register(&uwsgi.probes, "connect", connect_prober_callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_plugin probeconnect_plugin = {
|
||||
|
||||
.init = probeconnect_init,
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
NAME='probeconnect'
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = []
|
||||
|
||||
GCC_LIST = ['connectprobe']
|
||||
@@ -1,132 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
#include <libpq-fe.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
int pg_prober_callback(int, struct uwsgi_signal_probe *);
|
||||
int probepg_init(void);
|
||||
|
||||
int pg_prober_callback(int interesting_fd, struct uwsgi_signal_probe *up) {
|
||||
|
||||
// is this a timeout event ?
|
||||
if (interesting_fd == -1) {
|
||||
// am i wating for something ?
|
||||
if (up->fd != -1) {
|
||||
if (up->cycles > (uint64_t) up->timeout) {
|
||||
// reset the cycle
|
||||
up->cycles = 0;
|
||||
PQfinish((PGconn *) up->data);
|
||||
up->fd = -1;
|
||||
// state = NOOP
|
||||
up->state = 0;
|
||||
// avoid duplicated events
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// ok register a new event
|
||||
else {
|
||||
if ((up->cycles % up->freq) == 0) {
|
||||
up->last_event = event_queue_write();
|
||||
up->data = (void *) PQconnectStart(up->args);
|
||||
if (up->data) {
|
||||
// status = CONNECTING
|
||||
up->state = PQstatus((PGconn *) up->data);
|
||||
if (up->state == CONNECTION_BAD)
|
||||
goto bad;
|
||||
up->fd = PQsocket((PGconn *) up->data);
|
||||
event_queue_add_fd_write(uwsgi.master_queue, up->fd);
|
||||
return 0;
|
||||
}
|
||||
bad:
|
||||
// signal the bad event (if not already bad)
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (up->fd != -1) {
|
||||
// is this event for me ?
|
||||
if (interesting_fd == up->fd) {
|
||||
// check the state
|
||||
up->state = PQstatus((PGconn *) up->data);
|
||||
if (up->state == CONNECTION_BAD) {
|
||||
// signal the bad connection (if needed)
|
||||
up->cycles = 0;
|
||||
PQfinish((PGconn *) up->data);
|
||||
up->fd = -1;
|
||||
up->state = 0;
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else if (up->state == CONNECTION_OK) {
|
||||
up->cycles = 0;
|
||||
PQfinish((PGconn *) up->data);
|
||||
up->fd = -1;
|
||||
// state = NOOP
|
||||
up->state = 0;
|
||||
if (up->bad) {
|
||||
up->bad = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
// still wait...
|
||||
else {
|
||||
PostgresPollingStatusType wait_type = PQconnectPoll((PGconn *) up->data);
|
||||
// the connection is good
|
||||
if (wait_type == PGRES_POLLING_ACTIVE || wait_type == PGRES_POLLING_FAILED || wait_type == PGRES_POLLING_OK) {
|
||||
if (wait_type == PGRES_POLLING_ACTIVE)
|
||||
wait_type = PQconnectPoll((PGconn *) up->data);
|
||||
up->cycles = 0;
|
||||
up->fd = -1;
|
||||
// state = NOOP
|
||||
up->state = 0;
|
||||
PQfinish((PGconn *) up->data);
|
||||
if (wait_type == PGRES_POLLING_FAILED) {
|
||||
if (!up->bad) {
|
||||
up->bad = 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (up->bad) {
|
||||
up->bad = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (wait_type == PGRES_POLLING_READING) {
|
||||
event_queue_del_fd(uwsgi.master_queue, up->fd, up->last_event);
|
||||
event_queue_add_fd_read(uwsgi.master_queue, up->fd);
|
||||
up->last_event = event_queue_read();
|
||||
}
|
||||
else if (wait_type == PGRES_POLLING_WRITING) {
|
||||
event_queue_del_fd(uwsgi.master_queue, up->fd, up->last_event);
|
||||
event_queue_add_fd_write(uwsgi.master_queue, up->fd);
|
||||
up->last_event = event_queue_write();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// default action
|
||||
return 0;
|
||||
}
|
||||
|
||||
int probepg_init() {
|
||||
|
||||
uwsgi_probe_register(&uwsgi.probes, "pg", pg_prober_callback);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_plugin probepg_plugin = {
|
||||
|
||||
.init = probepg_init,
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
import os
|
||||
|
||||
NAME='probepg'
|
||||
CFLAGS = os.popen('pg_config --cflags').read().rstrip().split()
|
||||
CFLAGS.append('-I' + os.popen('pg_config --includedir').read().rstrip())
|
||||
LDFLAGS = os.popen('pg_config --ldflags').read().rstrip().split()
|
||||
LIBS = ['-L' + os.popen('pg_config --libdir').read().rstrip(), '-lpq']
|
||||
|
||||
GCC_LIST = ['pgprobe']
|
||||
@@ -210,26 +210,6 @@ PyObject *py_uwsgi_add_cron(PyObject * self, PyObject * args) {
|
||||
}
|
||||
|
||||
|
||||
PyObject *py_uwsgi_add_probe(PyObject * self, PyObject * args) {
|
||||
|
||||
uint8_t uwsgi_signal;
|
||||
int timeout = 0;
|
||||
int freq = 0;
|
||||
char *probe, *probe_args;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "Bss|ii:add_probe", &uwsgi_signal, &probe, &probe_args, &timeout, &freq)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (uwsgi_add_probe(uwsgi_signal, probe, probe_args, timeout, freq))
|
||||
return PyErr_Format(PyExc_ValueError, "unable to add probe");
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject *py_uwsgi_add_timer(PyObject * self, PyObject * args) {
|
||||
|
||||
uint8_t uwsgi_signal;
|
||||
@@ -2444,7 +2424,6 @@ static PyMethodDef uwsgi_advanced_methods[] = {
|
||||
{"signal_received", py_uwsgi_signal_received, METH_VARARGS, ""},
|
||||
{"add_file_monitor", py_uwsgi_add_file_monitor, METH_VARARGS, ""},
|
||||
{"add_timer", py_uwsgi_add_timer, METH_VARARGS, ""},
|
||||
{"add_probe", py_uwsgi_add_probe, METH_VARARGS, ""},
|
||||
{"add_rb_timer", py_uwsgi_add_rb_timer, METH_VARARGS, ""},
|
||||
{"add_cron", py_uwsgi_add_cron, METH_VARARGS, ""},
|
||||
|
||||
|
||||
+94
-25
@@ -1,67 +1,119 @@
|
||||
#include "v8_uwsgi.h"
|
||||
|
||||
extern struct uwsgi_v8 uv8;
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
static v8::Handle<v8::Value> uwsgi_v8_commonjs_require_do(char *filename) {
|
||||
/*
|
||||
|
||||
support .js
|
||||
support .so files (TeaJS)
|
||||
|
||||
*/
|
||||
static void uwsgi_v8_commonjs_require_do(char *filename, v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
|
||||
|
||||
size_t len = 0;
|
||||
char *code = uwsgi_open_and_read(filename, &len, 1, NULL);
|
||||
|
||||
// we re-create every time an "exports" object to emulate a local object
|
||||
v8::Local<v8::Object> exports = v8::Object::New();
|
||||
v8::Context::GetCurrent()->Global()->Set(v8::String::New("exports"), exports);
|
||||
|
||||
// we do not use TryCatch as we directly use stderr and simply exit with error code 1
|
||||
v8::Handle<v8::Script> script = v8::Script::Compile( v8::String::New(code), v8::String::New(filename) );
|
||||
free(code);
|
||||
if (script.IsEmpty()) {
|
||||
exit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> result = script->Run();
|
||||
if (result.IsEmpty()) {
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
return exports;
|
||||
script->Run();
|
||||
}
|
||||
|
||||
static void uwsgi_v8_commonjs_require_teajs_do(char *filename, v8::Local<v8::Object> exports, v8::Local<v8::Object> module) {
|
||||
|
||||
void *handle = dlopen(filename, RTLD_LAZY);
|
||||
if (!handle) {
|
||||
uwsgi_log("error opening teajs module %s: %s\n", filename, dlerror());
|
||||
return;
|
||||
}
|
||||
typedef void (*init_t)(v8::Handle<v8::Function>, v8::Handle<v8::Object>, v8::Handle<v8::Object>);
|
||||
init_t func = (init_t) dlsym(handle, "init");
|
||||
if (!func) {
|
||||
uwsgi_log("unable to find teajs module init function\n");
|
||||
return;
|
||||
}
|
||||
func(v8::Handle<v8::Function>::Cast(v8::Context::GetCurrent()->Global()->Get(v8::String::New("require"))), exports, module);
|
||||
}
|
||||
|
||||
|
||||
static v8::Handle<v8::Value> uwsgi_v8_commonjs_require(const v8::Arguments& args) {
|
||||
if (args.Length() > 0) {
|
||||
v8::String::Utf8Value module_name(args[0]->ToString());
|
||||
char *id = (char *)"pippo";
|
||||
// we re-create every time an "exports" object to emulate a local object
|
||||
v8::Local<v8::Object> exports = v8::Object::New();
|
||||
v8::Context::GetCurrent()->Global()->Set(v8::String::New("exports"), exports);
|
||||
v8::Local<v8::Object> module = v8::Object::New();
|
||||
v8::Context::GetCurrent()->Global()->Set(v8::String::New("module"), module);
|
||||
module->Set(v8::String::New("id"), v8::String::New(id));
|
||||
// ok lets start searching the module
|
||||
if (uwsgi_is_file(*module_name)) {
|
||||
return uwsgi_v8_commonjs_require_do(*module_name);
|
||||
if (!uwsgi_endswith(*module_name, (char *)".js")) {
|
||||
uwsgi_v8_commonjs_require_do(*module_name, exports, module);
|
||||
return exports;
|
||||
}
|
||||
else if (!uwsgi_endswith(*module_name, (char *)".so")) {
|
||||
uwsgi_v8_commonjs_require_teajs_do(*module_name, exports, module);
|
||||
return exports;
|
||||
}
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
// try appending .js extension
|
||||
if (!uwsgi_endswith(*module_name, (char *)".js")) {
|
||||
char *tmp_filename = uwsgi_concat2(*module_name, (char *)".js");
|
||||
// try appending .js/.so extension
|
||||
if (!uwsgi_endswith(*module_name, (char *)".js") && !uwsgi_endswith(*module_name, (char *)".so")) {
|
||||
char *tmp_filename = uwsgi_concat2(*module_name, (char *)".so");
|
||||
if (uwsgi_is_file(tmp_filename)) {
|
||||
uwsgi_v8_commonjs_require_teajs_do(tmp_filename, exports, module);
|
||||
free(tmp_filename);
|
||||
return exports;
|
||||
}
|
||||
free(tmp_filename);
|
||||
tmp_filename = uwsgi_concat2(*module_name, (char *)".js");
|
||||
if (uwsgi_is_file(tmp_filename)) {
|
||||
v8::Handle<v8::Value> ret = uwsgi_v8_commonjs_require_do(tmp_filename);
|
||||
uwsgi_v8_commonjs_require_do(tmp_filename, exports, module);
|
||||
free(tmp_filename);
|
||||
return ret;
|
||||
return exports;
|
||||
}
|
||||
free(tmp_filename);
|
||||
}
|
||||
}
|
||||
|
||||
// let's start searching in the modules search path
|
||||
struct uwsgi_string_list *usl = uv8.module_paths;
|
||||
while(usl) {
|
||||
char *tmp_filename = uwsgi_concat3(usl->value, (char *)"/", *module_name);
|
||||
if (uwsgi_is_file(tmp_filename)) {
|
||||
v8::Handle<v8::Value> ret = uwsgi_v8_commonjs_require_do(tmp_filename);
|
||||
if (!uwsgi_endswith(tmp_filename, (char *)".js")) {
|
||||
uwsgi_v8_commonjs_require_do(tmp_filename, exports, module);
|
||||
}
|
||||
else if (!uwsgi_endswith(tmp_filename, (char *)".so")) {
|
||||
uwsgi_v8_commonjs_require_teajs_do(tmp_filename, exports, module);
|
||||
}
|
||||
else {
|
||||
free(tmp_filename);
|
||||
return v8::Undefined();
|
||||
}
|
||||
free(tmp_filename);
|
||||
return ret;
|
||||
return exports;
|
||||
}
|
||||
free(tmp_filename);
|
||||
if (!uwsgi_endswith(*module_name, (char *)".js")) {
|
||||
if (!uwsgi_endswith(*module_name, (char *)".js") && !uwsgi_endswith(*module_name, (char *)".so")) {
|
||||
tmp_filename = uwsgi_concat4(usl->value, (char *)"/", *module_name, (char *)".so");
|
||||
if (uwsgi_is_file(tmp_filename)) {
|
||||
uwsgi_v8_commonjs_require_teajs_do(tmp_filename, exports, module);
|
||||
free(tmp_filename);
|
||||
return exports;
|
||||
}
|
||||
tmp_filename = uwsgi_concat4(usl->value, (char *)"/", *module_name, (char *)".js");
|
||||
if (uwsgi_is_file(tmp_filename)) {
|
||||
v8::Handle<v8::Value> ret = uwsgi_v8_commonjs_require_do(tmp_filename);
|
||||
uwsgi_v8_commonjs_require_do(tmp_filename, exports, module);
|
||||
free(tmp_filename);
|
||||
return ret;
|
||||
return exports;
|
||||
}
|
||||
free(tmp_filename);
|
||||
}
|
||||
free(tmp_filename);
|
||||
usl = usl->next;
|
||||
@@ -70,6 +122,23 @@ static v8::Handle<v8::Value> uwsgi_v8_commonjs_require(const v8::Arguments& args
|
||||
return v8::Undefined();
|
||||
}
|
||||
|
||||
void uwsgi_v8_fill_commonjs(v8::Persistent<v8::Context> context) {
|
||||
context->Enter();
|
||||
v8::Handle<v8::Object> system = context->Global()->Get(v8::String::New("system"))->ToObject();
|
||||
v8::Handle<v8::Array> args = v8::Array::New();
|
||||
int i;
|
||||
for(i=0;i<uwsgi.argc;i++) {
|
||||
args->Set(v8::Integer::New(i), v8::String::New(uwsgi.argv[i]));
|
||||
}
|
||||
system->Set(v8::String::New("args"), args);
|
||||
v8::Handle<v8::Object> env = v8::Object::New();
|
||||
system->Set(v8::String::New("env"), env);
|
||||
}
|
||||
|
||||
void uwsgi_v8_add_commonjs(v8::Handle<v8::ObjectTemplate> global) {
|
||||
// the require function (Modules/1.1)
|
||||
global->Set(v8::String::New("require"), v8::FunctionTemplate::New(uwsgi_v8_commonjs_require));
|
||||
// the system namespace (System/1.0)
|
||||
v8::Handle<v8::ObjectTemplate> system = v8::ObjectTemplate::New();
|
||||
global->Set(v8::String::New("system"), system);
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ static v8::Handle<v8::Value> uwsgi_v8_api_log(const v8::Arguments& args) {
|
||||
}
|
||||
|
||||
void uwsgi_v8_add_commonjs(v8::Handle<v8::ObjectTemplate>);
|
||||
void uwsgi_v8_fill_commonjs(v8::Persistent<v8::Context>);
|
||||
|
||||
static v8::Persistent<v8::Context> uwsgi_v8_new_isolate(int core_id) {
|
||||
// create a new isolate
|
||||
@@ -159,6 +160,9 @@ static v8::Persistent<v8::Context> uwsgi_v8_new_isolate(int core_id) {
|
||||
|
||||
// create a new context
|
||||
v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
|
||||
|
||||
uwsgi_v8_fill_commonjs(context);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user