mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-04 16:08:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a37b3653f | ||
|
|
65ad341a31 | ||
|
|
bd31548903 | ||
|
|
dd536cf7ea | ||
|
|
efa27dfc6c | ||
|
|
91b14e0b34 | ||
|
|
74b3d25bcf | ||
|
|
3857e26e4c | ||
|
|
c7d3a27225 | ||
|
|
4f50b4aafc | ||
|
|
d172fb4909 | ||
|
|
c842bb4917 | ||
|
|
d6da6848be | ||
|
|
b1caf56f49 |
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env ruby
|
||||
cmd = File.expand_path "#{File.dirname(__FILE__)}/../ext/uwsgi/uwsgi.ruby"
|
||||
|
||||
exec(cmd, *ARGV)
|
||||
+51
-5
@@ -185,8 +185,24 @@ void uwsgi_imperial_monitor_directory(struct uwsgi_emperor_scanner *ues) {
|
||||
|
||||
while (c_ui) {
|
||||
if (c_ui->scanner == ues) {
|
||||
if (stat(c_ui->name, &st)) {
|
||||
emperor_stop(c_ui);
|
||||
if (c_ui->zerg) {
|
||||
char *colon = strrchr(c_ui->name, ':');
|
||||
if (!colon) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
else {
|
||||
char *filename = uwsgi_calloc(0xff);
|
||||
memcpy(filename, c_ui->name, colon - c_ui->name);
|
||||
if (stat(filename, &st)) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
free(filename);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (stat(c_ui->name, &st)) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
c_ui = c_ui->ui_next;
|
||||
@@ -245,9 +261,25 @@ void uwsgi_imperial_monitor_glob(struct uwsgi_emperor_scanner *ues) {
|
||||
|
||||
while (c_ui) {
|
||||
if (c_ui->scanner == ues) {
|
||||
if (stat(c_ui->name, &st)) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
if (c_ui->zerg) {
|
||||
char *colon = strrchr(c_ui->name, ':');
|
||||
if (!colon) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
else {
|
||||
char *filename = uwsgi_calloc(0xff);
|
||||
memcpy(filename, c_ui->name, colon - c_ui->name);
|
||||
if (stat(filename, &st)) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
free(filename);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (stat(c_ui->name, &st)) {
|
||||
emperor_stop(c_ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
c_ui = c_ui->ui_next;
|
||||
}
|
||||
@@ -548,6 +580,10 @@ void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, cha
|
||||
}
|
||||
}
|
||||
|
||||
if (n_ui->zerg) {
|
||||
uwsgi.emperor_broodlord_num++;
|
||||
}
|
||||
|
||||
// TODO pre-start hook
|
||||
|
||||
// a new uWSGI instance will start
|
||||
@@ -601,6 +637,16 @@ void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, cha
|
||||
}
|
||||
free(uef);
|
||||
|
||||
// add UWSGI_BROODLORD_NUM
|
||||
if (n_ui->zerg) {
|
||||
uef = uwsgi_num2str(uwsgi.emperor_broodlord_num);
|
||||
if (setenv("UWSGI_BROODLORD_NUM", uef, 1)) {
|
||||
uwsgi_error("setenv()");
|
||||
exit(1);
|
||||
}
|
||||
free(uef);
|
||||
}
|
||||
|
||||
if (n_ui->use_config) {
|
||||
uef = uwsgi_num2str(n_ui->pipe_config[1]);
|
||||
if (setenv("UWSGI_EMPEROR_FD_CONFIG", uef, 1)) {
|
||||
|
||||
+6
-1
@@ -41,6 +41,10 @@ struct uwsgi_gateway *register_gateway(char *name, void (*loop) (int, void *), v
|
||||
return ug;
|
||||
}
|
||||
|
||||
static void gateway_brutal_end() {
|
||||
_exit(UWSGI_END_CODE);
|
||||
}
|
||||
|
||||
void gateway_respawn(int id) {
|
||||
|
||||
pid_t gw_pid;
|
||||
@@ -65,6 +69,7 @@ void gateway_respawn(int id) {
|
||||
}
|
||||
#endif
|
||||
uwsgi.mypid = getpid();
|
||||
atexit(gateway_brutal_end);
|
||||
signal(SIGALRM, SIG_IGN);
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
signal(SIGINT, end_me);
|
||||
@@ -77,7 +82,7 @@ void gateway_respawn(int id) {
|
||||
|
||||
ug->loop(id, ug->data);
|
||||
// never here !!! (i hope)
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
ug->pid = gw_pid;
|
||||
|
||||
@@ -478,7 +478,9 @@ void uwsgi_lock_ipcsem(struct uwsgi_lock_item *uli) {
|
||||
|
||||
memcpy(&semid, uli->lock_ptr, sizeof(int));
|
||||
|
||||
retry:
|
||||
if (semop(semid, &sb, 1)) {
|
||||
if (errno == EINTR) goto retry;
|
||||
uwsgi_error("semop()");
|
||||
}
|
||||
}
|
||||
@@ -493,7 +495,9 @@ void uwsgi_unlock_ipcsem(struct uwsgi_lock_item *uli) {
|
||||
|
||||
memcpy(&semid, uli->lock_ptr, sizeof(int));
|
||||
|
||||
retry:
|
||||
if (semop(semid, &sb, 1)) {
|
||||
if (errno == EINTR) goto retry;
|
||||
uwsgi_error("semop()");
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"socket", required_argument, 's', "bind to the specified UNIX/TCP socket using default protocol", uwsgi_opt_add_socket, NULL, 0},
|
||||
{"uwsgi-socket", required_argument, 's', "bind to the specified UNIX/TCP socket using uwsgi protocol", uwsgi_opt_add_socket, "uwsgi", 0},
|
||||
{"http-socket", required_argument, 0, "bind to the specified UNIX/TCP socket using HTTP protocol", uwsgi_opt_add_socket, "http", 0},
|
||||
{"http-socket-modifier1", required_argument, 0, "force the specified modifier1 when using HTTP protocol", uwsgi_opt_set_64bit, &uwsgi.http_modifier1, 0},
|
||||
{"http-socket-modifier2", required_argument, 0, "force the specified modifier2 when using HTTP protocol", uwsgi_opt_set_64bit, &uwsgi.http_modifier2, 0},
|
||||
{"fastcgi-socket", required_argument, 0, "bind to the specified UNIX/TCP socket using FastCGI protocol", uwsgi_opt_add_socket, "fastcgi", 0},
|
||||
{"protocol", required_argument, 0, "force the specified protocol for default sockets", uwsgi_opt_set_str, &uwsgi.protocol, 0},
|
||||
{"socket-protocol", required_argument, 0, "force the specified protocol for default sockets", uwsgi_opt_set_str, &uwsgi.protocol, 0},
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
require 'net/http'
|
||||
|
||||
Net::HTTP.start("uwsgi.it") do |http|
|
||||
resp = http.get("/install")
|
||||
open("install.sh", "wb") do |file|
|
||||
file.write(resp.body)
|
||||
end
|
||||
end
|
||||
|
||||
system("bash install.sh rack #{Dir.pwd}/uwsgi.ruby")
|
||||
|
||||
open("Makefile", "w") do |file|
|
||||
file.write("all:\n")
|
||||
file.write("\t\n")
|
||||
end
|
||||
@@ -142,6 +142,7 @@ static int carbon_write(int fd, char *fmt,...) {
|
||||
|
||||
static void carbon_push_stats(int retry_cycle, time_t now) {
|
||||
struct carbon_server_list *usl = u_carbon.servers_data;
|
||||
if (!u_carbon.servers_data) return;
|
||||
int i;
|
||||
int fd;
|
||||
int wok;
|
||||
|
||||
@@ -834,23 +834,7 @@ void uwsgi_corerouter_loop(int id, void *data) {
|
||||
}
|
||||
|
||||
// not having a hook could mean a previous event in the loop cleared it...
|
||||
if (!hook) {
|
||||
// a single event cannot be unexpected..
|
||||
if (nevents == 1) {
|
||||
if (interesting_fd == cr_session->instance_fd) {
|
||||
uwsgi_log("[uwsgi-corerouter] BUG, unexpected event received from backend instance (fd: %d nevents: %d) !!!\n", interesting_fd, nevents);
|
||||
}
|
||||
else if (interesting_fd == cr_session->fd) {
|
||||
uwsgi_log("[uwsgi-corerouter] BUG, unexpected event received from client (fd: %d nevents: %d)!!!\n", interesting_fd, nevents);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("[uwsgi-corerouter] BUG, unexpected event received !!!\n");
|
||||
}
|
||||
corerouter_close_session(ucr, cr_session);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!hook) continue;
|
||||
// reset errno (as we use it for internal signalling)
|
||||
errno = 0;
|
||||
ssize_t ret = hook(cr_session);
|
||||
|
||||
@@ -230,7 +230,7 @@ ssize_t uwsgi_gevent_hook_input_read(struct wsgi_request *wsgi_req, char *tmp_bu
|
||||
}
|
||||
Py_DECREF(ret);
|
||||
|
||||
ret = PyObject_CallMethod(timer, "start", "OO", current, timer);
|
||||
ret = PyObject_CallMethod(timer, "again", "OO", current, timer);
|
||||
if (!ret) {
|
||||
stop_the_watchers_and_clear
|
||||
return -1;
|
||||
@@ -298,7 +298,7 @@ ssize_t uwsgi_gevent_hook_input_readline(struct wsgi_request *wsgi_req, char *re
|
||||
}
|
||||
Py_DECREF(ret);
|
||||
|
||||
ret = PyObject_CallMethod(timer, "start", "OO", current, timer);
|
||||
ret = PyObject_CallMethod(timer, "again", "OO", current, timer);
|
||||
if (!ret) {
|
||||
stop_the_watchers_and_clear
|
||||
return -1;
|
||||
@@ -364,7 +364,7 @@ void uwsgi_gevent_nb_write(struct wsgi_request *wsgi_req, PyObject *str) {
|
||||
}
|
||||
Py_DECREF(ret);
|
||||
|
||||
ret = PyObject_CallMethod(timer, "start", "OO", current, timer);
|
||||
ret = PyObject_CallMethod(timer, "again", "OO", current, timer);
|
||||
if (!ret) {
|
||||
stop_the_watchers_and_clear
|
||||
goto error;
|
||||
@@ -431,7 +431,7 @@ PyObject *uwsgi_gevent_wait(PyObject *watcher, PyObject *timer, PyObject *curren
|
||||
Py_DECREF(ret);
|
||||
|
||||
// start the timeout handler
|
||||
ret = PyObject_CallMethod(timer, "start", "OO", current, timer);
|
||||
ret = PyObject_CallMethod(timer, "again", "OO", current, timer);
|
||||
if (!ret) return NULL;
|
||||
Py_DECREF(ret);
|
||||
|
||||
|
||||
+10
-8
@@ -551,8 +551,8 @@ ssize_t hr_read_ssl_body(struct corerouter_session * cs) {
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
if (cs->event_hook_write) {
|
||||
uwsgi_cr_hook_write(cs, NULL);
|
||||
uwsgi_cr_hook_read(cs, hr_read_ssl_body);
|
||||
}
|
||||
uwsgi_cr_hook_read(cs, hr_read_ssl_body);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
@@ -560,8 +560,8 @@ ssize_t hr_read_ssl_body(struct corerouter_session * cs) {
|
||||
else if (err == SSL_ERROR_WANT_WRITE) {
|
||||
if (cs->event_hook_read) {
|
||||
uwsgi_cr_hook_read(cs, NULL);
|
||||
uwsgi_cr_hook_write(cs, hr_read_ssl_body);
|
||||
}
|
||||
uwsgi_cr_hook_write(cs, hr_read_ssl_body);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
@@ -625,16 +625,16 @@ ssize_t hr_write_ssl_response(struct corerouter_session * cs) {
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
if (cs->event_hook_write) {
|
||||
uwsgi_cr_hook_write(cs, NULL);
|
||||
uwsgi_cr_hook_read(cs, hr_write_ssl_response);
|
||||
}
|
||||
uwsgi_cr_hook_read(cs, hr_write_ssl_response);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
else if (err == SSL_ERROR_WANT_WRITE) {
|
||||
if (cs->event_hook_read) {
|
||||
uwsgi_cr_hook_read(cs, NULL);
|
||||
uwsgi_cr_hook_write(cs, hr_write_ssl_response);
|
||||
}
|
||||
uwsgi_cr_hook_write(cs, hr_write_ssl_response);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
@@ -839,16 +839,16 @@ ssize_t hr_send_expect_continue(struct corerouter_session * cs) {
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
if (cs->event_hook_write) {
|
||||
uwsgi_cr_hook_write(cs, NULL);
|
||||
uwsgi_cr_hook_read(cs, hr_write_ssl_response);
|
||||
}
|
||||
uwsgi_cr_hook_read(cs, hr_write_ssl_response);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
else if (err == SSL_ERROR_WANT_WRITE) {
|
||||
if (cs->event_hook_read) {
|
||||
uwsgi_cr_hook_read(cs, NULL);
|
||||
uwsgi_cr_hook_write(cs, hr_write_ssl_response);
|
||||
}
|
||||
uwsgi_cr_hook_write(cs, hr_write_ssl_response);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
@@ -949,8 +949,8 @@ ssize_t hr_recv_http_ssl(struct corerouter_session * cs) {
|
||||
if (err == SSL_ERROR_WANT_READ) {
|
||||
if (cs->event_hook_write) {
|
||||
uwsgi_cr_hook_write(cs, NULL);
|
||||
uwsgi_cr_hook_read(cs, hr_recv_http_ssl);
|
||||
}
|
||||
uwsgi_cr_hook_read(cs, hr_recv_http_ssl);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
@@ -958,8 +958,8 @@ ssize_t hr_recv_http_ssl(struct corerouter_session * cs) {
|
||||
else if (err == SSL_ERROR_WANT_WRITE) {
|
||||
if (cs->event_hook_read) {
|
||||
uwsgi_cr_hook_read(cs, NULL);
|
||||
uwsgi_cr_hook_write(cs, hr_recv_http_ssl);
|
||||
}
|
||||
uwsgi_cr_hook_write(cs, hr_recv_http_ssl);
|
||||
errno = EINPROGRESS;
|
||||
return -1;
|
||||
}
|
||||
@@ -1125,6 +1125,8 @@ void hr_session_ssl_close(struct corerouter_session *cs) {
|
||||
X509_free(hs->ssl_client_cert);
|
||||
}
|
||||
|
||||
// clear the errors (otherwise they could be propagated)
|
||||
ERR_clear_error();
|
||||
SSL_free(hs->ssl);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
#include <jni.h>
|
||||
|
||||
struct uwsgi_jvm {
|
||||
|
||||
struct uwsgi_string_list *classpath;
|
||||
|
||||
JNIEnv *env;
|
||||
char *class;
|
||||
jclass main_class;
|
||||
|
||||
jclass str_class;
|
||||
jclass ht_class;
|
||||
jclass fd_class;
|
||||
};
|
||||
|
||||
|
||||
jmethodID uwsgi_jvm_get_method_id(jclass, char *, char *);
|
||||
jmethodID uwsgi_jvm_get_static_method_id(jclass, char *, char *);
|
||||
jclass uwsgi_jvm_get_class(char *);
|
||||
jclass uwsgi_jvm_get_object_class(jobject);
|
||||
int uwsgi_jvm_exception(void);
|
||||
|
||||
jobject uwsgi_jvm_str_new(char *, int );
|
||||
jobject uwsgi_jvm_str(char *);
|
||||
|
||||
jobject uwsgi_jvm_array_get(jobject , int );
|
||||
jobject uwsgi_jvm_ht_new(void);
|
||||
jobject uwsgi_jvm_ht_put(jobject, jobject, jobject);
|
||||
|
||||
jobject uwsgi_jvm_fd(int);
|
||||
|
||||
char *uwsgi_jvm_str2c(jobject);
|
||||
int uwsgi_jvm_strlen2c(jobject);
|
||||
@@ -1,210 +0,0 @@
|
||||
#include "jvm.h"
|
||||
|
||||
/*
|
||||
|
||||
with javap -s -p <class>
|
||||
you can get method signatures
|
||||
|
||||
This plugin is the core for all of the JVM-based ones
|
||||
|
||||
*/
|
||||
|
||||
struct uwsgi_jvm ujvm;
|
||||
|
||||
struct uwsgi_option uwsgi_jvm_options[] = {
|
||||
{"jvm-main-class", required_argument, 0, "load the specified class", uwsgi_opt_set_str, &ujvm.class, 0},
|
||||
{"jvm-classpath", required_argument, 0, "add the specified directory to the classpath", uwsgi_opt_add_string_list, &ujvm.classpath, 0},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
int uwsgi_jvm_exception(void) {
|
||||
|
||||
if ((*ujvm.env)->ExceptionOccurred(ujvm.env)) {
|
||||
(*ujvm.env)->ExceptionDescribe(ujvm.env);
|
||||
(*ujvm.env)->ExceptionClear(ujvm.env);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
jclass uwsgi_jvm_get_object_class(jobject obj) {
|
||||
return (*ujvm.env)->GetObjectClass(ujvm.env, obj);
|
||||
}
|
||||
|
||||
jclass uwsgi_jvm_get_class(char *name) {
|
||||
|
||||
jclass my_class = (*ujvm.env)->FindClass(ujvm.env, name);
|
||||
|
||||
if (uwsgi_jvm_exception()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return my_class;
|
||||
}
|
||||
|
||||
jmethodID uwsgi_jvm_get_method_id(jclass cls, char *name, char *signature) {
|
||||
|
||||
jmethodID mid;
|
||||
|
||||
mid = (*ujvm.env)->GetMethodID(ujvm.env, cls, name, signature);
|
||||
|
||||
return mid;
|
||||
}
|
||||
|
||||
jmethodID uwsgi_jvm_get_static_method_id(jclass cls, char *name, char *signature) {
|
||||
|
||||
jmethodID mid;
|
||||
|
||||
mid = (*ujvm.env)->GetStaticMethodID(ujvm.env, cls, name, signature);
|
||||
|
||||
return mid;
|
||||
}
|
||||
|
||||
jobject uwsgi_jvm_str_new(char *str, int len) {
|
||||
|
||||
jbyteArray ba;
|
||||
static jmethodID str_new_mid = 0;
|
||||
|
||||
if (!str_new_mid) {
|
||||
str_new_mid = uwsgi_jvm_get_method_id(ujvm.str_class, "<init>", "([BLjava/lang/String;)V");
|
||||
}
|
||||
|
||||
ba = (*ujvm.env)->NewByteArray(ujvm.env, len);
|
||||
(*ujvm.env)->SetByteArrayRegion(ujvm.env, ba, 0, len, (jbyte *) str);
|
||||
return (*ujvm.env)->NewObject(ujvm.env, ujvm.str_class, str_new_mid, ba,
|
||||
(*ujvm.env)->NewStringUTF(ujvm.env, "UTF-8"));
|
||||
}
|
||||
|
||||
jobject uwsgi_jvm_str(char *str) {
|
||||
return (*ujvm.env)->NewStringUTF(ujvm.env, str);
|
||||
}
|
||||
|
||||
|
||||
int jvm_init(void) {
|
||||
|
||||
jint res;
|
||||
JavaVM *jvm;
|
||||
JavaVMInitArgs vm_args;
|
||||
JavaVMOption options[1];
|
||||
jmethodID mmid;
|
||||
|
||||
char *old_cp = NULL ;
|
||||
|
||||
|
||||
vm_args.version = JNI_VERSION_1_2;
|
||||
|
||||
JNI_GetDefaultJavaVMInitArgs(&vm_args);
|
||||
|
||||
options[0].optionString = "-Djava.class.path=.";
|
||||
|
||||
struct uwsgi_string_list *cp = ujvm.classpath;
|
||||
while(cp) {
|
||||
if (old_cp) {
|
||||
options[0].optionString = uwsgi_concat3(old_cp, ":", cp->value);
|
||||
free(old_cp);
|
||||
}
|
||||
else {
|
||||
options[0].optionString = uwsgi_concat3(options[0].optionString, ":", cp->value);
|
||||
}
|
||||
old_cp = options[0].optionString ;
|
||||
cp = cp->next;
|
||||
}
|
||||
|
||||
vm_args.options = options;
|
||||
vm_args.nOptions = 1;
|
||||
|
||||
res = JNI_CreateJavaVM(&jvm, (void **) &ujvm.env, &vm_args);
|
||||
|
||||
if (res) {
|
||||
uwsgi_log("unable to initialize JVM\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uwsgi_log("JVM initialized\n");
|
||||
|
||||
if (ujvm.class) {
|
||||
ujvm.main_class = uwsgi_jvm_get_class(ujvm.class);
|
||||
if (!ujvm.main_class) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
mmid = uwsgi_jvm_get_static_method_id(ujvm.main_class, "main", "([Ljava/lang/String;)V");
|
||||
if (mmid) {
|
||||
(*ujvm.env)->CallStaticVoidMethod(ujvm.env, ujvm.main_class, mmid);
|
||||
uwsgi_jvm_exception();
|
||||
}
|
||||
}
|
||||
|
||||
ujvm.str_class = uwsgi_jvm_get_class("java/lang/String");
|
||||
ujvm.ht_class = uwsgi_jvm_get_class("java/util/Hashtable");
|
||||
ujvm.fd_class = uwsgi_jvm_get_class("java/io/FileDescriptor");
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
jobject uwsgi_jvm_array_get(jobject obj, int index) {
|
||||
return (*ujvm.env)->GetObjectArrayElement(ujvm.env, obj, index);
|
||||
}
|
||||
|
||||
jobject uwsgi_jvm_ht_new() {
|
||||
static jmethodID htimid = 0;
|
||||
|
||||
if (!htimid) {
|
||||
htimid = uwsgi_jvm_get_method_id(ujvm.ht_class, "<init>", "()V");
|
||||
}
|
||||
|
||||
return (*ujvm.env)->NewObject(ujvm.env, ujvm.ht_class, htimid);
|
||||
}
|
||||
|
||||
jobject uwsgi_jvm_ht_put(jobject obj, jobject key, jobject val) {
|
||||
|
||||
static jmethodID htpmid = 0 ;
|
||||
|
||||
if (!htpmid) {
|
||||
htpmid = uwsgi_jvm_get_method_id(ujvm.ht_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
}
|
||||
|
||||
return (*ujvm.env)->CallObjectMethod(ujvm.env, obj, htpmid, key, val);
|
||||
}
|
||||
|
||||
jobject uwsgi_jvm_fd(int fd) {
|
||||
|
||||
jobject fd_obj;
|
||||
static jmethodID fd_mid = 0;
|
||||
static jfieldID fd_field = 0 ;
|
||||
|
||||
if (!fd_mid) {
|
||||
fd_mid = uwsgi_jvm_get_method_id( ujvm.fd_class, "<init>", "()V");
|
||||
}
|
||||
|
||||
fd_obj = (*ujvm.env)->NewObject(ujvm.env, ujvm.fd_class, fd_mid);
|
||||
|
||||
if (!fd_field) {
|
||||
fd_field = (*ujvm.env)->GetFieldID(ujvm.env, ujvm.fd_class, "fd", "I");
|
||||
}
|
||||
|
||||
(*ujvm.env)->SetIntField(ujvm.env, fd_obj, fd_field, fd);
|
||||
|
||||
return fd_obj;
|
||||
}
|
||||
|
||||
char *uwsgi_jvm_str2c(jobject obj) {
|
||||
|
||||
return (char *) (*ujvm.env)->GetStringUTFChars(ujvm.env, obj, NULL);
|
||||
}
|
||||
|
||||
int uwsgi_jvm_strlen2c(jobject obj) {
|
||||
|
||||
return (*ujvm.env)->GetStringUTFLength(ujvm.env, obj);
|
||||
}
|
||||
|
||||
struct uwsgi_plugin jvm_plugin = {
|
||||
|
||||
.name = "jvm",
|
||||
.init = jvm_init,
|
||||
.options = uwsgi_jvm_options,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import os,sys
|
||||
|
||||
NAME='jvm'
|
||||
|
||||
# Snow Leopard
|
||||
#JVM_INCPATH = "/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers/"
|
||||
#JVM_LIBPATH = "/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Libraries/ -framework JavaVM"
|
||||
|
||||
# FreeBSD openjdk7 example
|
||||
# env UWSGICONFIG_JVM_INCPATH="/usr/local/openjdk7/include -I/usr/local/openjdk7/include/freebsd/" UWSGICONFIG_JVM_LIBPATH="/usr/local/openjdk7/jre/lib/amd64/server" python uwsgiconfig.py --plugin plugins/jvm
|
||||
|
||||
# NexentaOS example
|
||||
# UWSGICONFIG_JVM_INCPATH="/usr/java/include -I /usr/java/include/solaris" UWSGICONFIG_JVM_LIBPATH="/usr/java/jre/lib/i386/" python uwsgiconfig.py --plugin plugins/jvm
|
||||
|
||||
# Ubuntu
|
||||
JVM_INCPATH = "/usr/lib/jvm/java-6-openjdk/include/ -I/usr/lib/jvm/java-6-openjdk/include/linux"
|
||||
JVM_LIBPATH = "/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/"
|
||||
|
||||
try:
|
||||
JVM_INCPATH = os.environ['UWSGICONFIG_JVM_INCPATH']
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
JVM_LIBPATH = os.environ['UWSGICONFIG_JVM_LIBPATH']
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
JVM_INCPATH = os.environ['UWSGICONFIG_JVM_INCPATH']
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
JVM_LIBPATH = os.environ['UWSGICONFIG_JVM_LIBPATH']
|
||||
except:
|
||||
pass
|
||||
|
||||
CFLAGS = ['-I' + JVM_INCPATH]
|
||||
LDFLAGS = ['-L' + JVM_LIBPATH]
|
||||
LIBS = ['-ljvm']
|
||||
GCC_LIST = ['jvm_plugin']
|
||||
|
||||
if os.environ.has_key('LD_RUN_PATH'):
|
||||
os.environ['LD_RUN_PATH'] += ':' + JVM_LIBPATH
|
||||
else:
|
||||
os.environ['LD_RUN_PATH'] = JVM_LIBPATH
|
||||
@@ -1,117 +0,0 @@
|
||||
#include "../jvm/jvm.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
extern struct uwsgi_jvm ujvm;
|
||||
|
||||
void uwsgi_jwsgi_init(void) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
int uwsgi_jwsgi_request(struct wsgi_request *wsgi_req) {
|
||||
|
||||
jmethodID jmid;
|
||||
int i;
|
||||
jobject env;
|
||||
jobject hkey, hval;
|
||||
jobject response;
|
||||
|
||||
jobject status;
|
||||
jobject headers, header;
|
||||
jobject body;
|
||||
|
||||
jclass hc;
|
||||
|
||||
jmethodID hh_size, hh_get;
|
||||
int hlen;
|
||||
|
||||
if (!wsgi_req->uh.pktsize) {
|
||||
uwsgi_log("Invalid JWSGI request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi_parse_vars(wsgi_req)) {
|
||||
uwsgi_log("Invalid JWSGI request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
jmid = uwsgi_jvm_get_static_method_id(ujvm.main_class, "jwsgi", "(Ljava/util/Hashtable;)[Ljava/lang/Object;");
|
||||
|
||||
uwsgi_log("jwsgi method id = %d\n", jmid);
|
||||
|
||||
env = uwsgi_jvm_ht_new();
|
||||
uwsgi_jvm_exception();
|
||||
|
||||
for(i=0;i<wsgi_req->var_cnt;i++) {
|
||||
|
||||
uwsgi_jvm_ht_put(env,
|
||||
uwsgi_jvm_str_new(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len),
|
||||
uwsgi_jvm_str_new(wsgi_req->hvec[i+1].iov_base, wsgi_req->hvec[i+1].iov_len)
|
||||
);
|
||||
|
||||
// check if something is going wrong during hashtable fill
|
||||
uwsgi_jvm_exception();
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
uwsgi_log("env created\n");
|
||||
|
||||
uwsgi_jvm_ht_put(env, uwsgi_jvm_str("jwsgi.input"), uwsgi_jvm_fd(wsgi_req->poll.fd));
|
||||
|
||||
uwsgi_log("jwsgi.input created\n");
|
||||
|
||||
response = (*ujvm.env)->CallObjectMethod(ujvm.env, ujvm.main_class, jmid, env);
|
||||
uwsgi_jvm_exception();
|
||||
|
||||
uwsgi_log("RESPONSE SIZE %d\n", (*ujvm.env)->GetArrayLength(ujvm.env, response));
|
||||
|
||||
status = uwsgi_jvm_array_get(response, 0);
|
||||
uwsgi_jvm_exception();
|
||||
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, wsgi_req->protocol, wsgi_req->protocol_len);
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, " ", 1);
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, uwsgi_jvm_str2c(status), uwsgi_jvm_strlen2c(status));
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, "\r\n", 2);
|
||||
|
||||
|
||||
headers = uwsgi_jvm_array_get(response, 1);
|
||||
hc = uwsgi_jvm_get_object_class(headers);
|
||||
hh_size = uwsgi_jvm_get_method_id(hc, "size","()I");
|
||||
hh_get = uwsgi_jvm_get_method_id(hc, "get","(I)Ljava/lang/Object;");
|
||||
|
||||
hlen = (*ujvm.env)->CallIntMethod(ujvm.env, headers, hh_size);
|
||||
|
||||
for(i=0;i<hlen;i++) {
|
||||
header = (*ujvm.env)->CallObjectMethod(ujvm.env, headers, hh_get, i);
|
||||
hkey = uwsgi_jvm_array_get(header, 0);
|
||||
hval = uwsgi_jvm_array_get(header, 1);
|
||||
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, uwsgi_jvm_str2c(hkey), uwsgi_jvm_strlen2c(hkey));
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, ": ", 2);
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, uwsgi_jvm_str2c(hval), uwsgi_jvm_strlen2c(hval));
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, "\r\n", 2);
|
||||
}
|
||||
|
||||
wsgi_req->headers_size += write(wsgi_req->poll.fd, "\r\n", 2);
|
||||
|
||||
body = uwsgi_jvm_array_get(response, 2);
|
||||
|
||||
wsgi_req->response_size = write(wsgi_req->poll.fd, (*ujvm.env)->GetStringUTFChars(ujvm.env, body, NULL), (*ujvm.env)->GetStringUTFLength(ujvm.env, body));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void uwsgi_jwsgi_after_request(struct wsgi_request *wsgi_req) {
|
||||
log_request(wsgi_req);
|
||||
}
|
||||
|
||||
struct uwsgi_plugin jwsgi_plugin = {
|
||||
|
||||
.name = "jwsgi",
|
||||
.modifier1 = 8,
|
||||
.request = uwsgi_jwsgi_request,
|
||||
.after_request = uwsgi_jwsgi_after_request,
|
||||
};
|
||||
@@ -1,22 +0,0 @@
|
||||
import os,sys
|
||||
|
||||
NAME='jwsgi'
|
||||
|
||||
# Snow Leopard
|
||||
#JVM_INCPATH = "/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers/"
|
||||
#JVM_LIBPATH = "/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Libraries/ -framework JavaVM"
|
||||
|
||||
# Ubuntu
|
||||
JVM_INCPATH = "/usr/lib/jvm/java-6-sun-1.6.0.15/include/ -I/usr/lib/jvm/java-6-sun-1.6.0.15/include/linux"
|
||||
JVM_LIBPATH = "/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/i386/server/"
|
||||
|
||||
|
||||
CFLAGS = ['-I' + JVM_INCPATH]
|
||||
LDFLAGS = ['-L' + JVM_LIBPATH]
|
||||
LIBS = ['-ljvm']
|
||||
GCC_LIST = ['jwsgi_plugin']
|
||||
|
||||
if os.environ.has_key('LD_RUN_PATH'):
|
||||
os.environ['LD_RUN_PATH'] += ':' + JVM_LIBPATH
|
||||
else:
|
||||
os.environ['LD_RUN_PATH'] = JVM_LIBPATH
|
||||
+60
-17
@@ -133,30 +133,70 @@ static char *encode_lua_table(lua_State *L, int index, uint16_t *size) {
|
||||
|
||||
static int uwsgi_api_cache_set(lua_State *L) {
|
||||
|
||||
int args = lua_gettop(L);
|
||||
int args = lua_gettop(L);
|
||||
const char *key ;
|
||||
const char *value ;
|
||||
uint64_t expires = 0;
|
||||
size_t vallen;
|
||||
size_t vallen;
|
||||
|
||||
if (!uwsgi.cache_max_items) goto error;
|
||||
|
||||
|
||||
if (args > 1) {
|
||||
if (args > 1) {
|
||||
|
||||
key = lua_tolstring(L, 1, NULL);
|
||||
value = lua_tolstring(L, 2, &vallen);
|
||||
if (args > 2) {
|
||||
expires = lua_tonumber(L, 3);
|
||||
}
|
||||
key = lua_tolstring(L, 1, NULL);
|
||||
value = lua_tolstring(L, 2, &vallen);
|
||||
if (args > 2) {
|
||||
expires = lua_tonumber(L, 3);
|
||||
}
|
||||
|
||||
uwsgi_cache_set((char *)key, strlen(key), (char *)value, (uint16_t) vallen, expires, 0);
|
||||
|
||||
}
|
||||
uwsgi_wlock(uwsgi.cache_lock);
|
||||
uwsgi_cache_set((char *)key, strlen(key), (char *)value, (uint16_t) vallen, expires, 0);
|
||||
uwsgi_rwunlock(uwsgi.cache_lock);
|
||||
}
|
||||
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
error:
|
||||
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static int uwsgi_api_cache_update(lua_State *L) {
|
||||
|
||||
int args = lua_gettop(L);
|
||||
const char *key ;
|
||||
const char *value ;
|
||||
uint64_t expires = 0;
|
||||
size_t vallen;
|
||||
|
||||
if (!uwsgi.cache_max_items) goto error;
|
||||
|
||||
|
||||
if (args > 1) {
|
||||
|
||||
key = lua_tolstring(L, 1, NULL);
|
||||
value = lua_tolstring(L, 2, &vallen);
|
||||
if (args > 2) {
|
||||
expires = lua_tonumber(L, 3);
|
||||
}
|
||||
|
||||
uwsgi_wlock(uwsgi.cache_lock);
|
||||
uwsgi_cache_set((char *)key, strlen(key), (char *)value,
|
||||
(uint16_t) vallen, expires,
|
||||
UWSGI_CACHE_FLAG_UPDATE);
|
||||
uwsgi_rwunlock(uwsgi.cache_lock);
|
||||
|
||||
}
|
||||
|
||||
error:
|
||||
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static int uwsgi_api_register_signal(lua_State *L) {
|
||||
|
||||
int args = lua_gettop(L);
|
||||
@@ -184,23 +224,25 @@ static int uwsgi_api_cache_get(lua_State *L) {
|
||||
char *value ;
|
||||
uint64_t valsize;
|
||||
const char *key ;
|
||||
|
||||
lca(L, 1);
|
||||
|
||||
if (!uwsgi.cache_max_items) goto error;
|
||||
|
||||
if (lua_isstring(L, 1)) {
|
||||
|
||||
key = lua_tolstring(L, 1, NULL);
|
||||
uwsgi_rlock(uwsgi.cache_lock);
|
||||
value = uwsgi_cache_get((char *)key, strlen(key), &valsize);
|
||||
|
||||
if (value) {
|
||||
lua_pushlstring(L, value, valsize);
|
||||
uwsgi_rwunlock(uwsgi.cache_lock);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uwsgi_rwunlock(uwsgi.cache_lock);
|
||||
}
|
||||
|
||||
error:
|
||||
lua_pushnil(L);
|
||||
|
||||
return 1;
|
||||
|
||||
}
|
||||
@@ -349,6 +391,7 @@ static const luaL_reg uwsgi_api[] = {
|
||||
{"send_message", uwsgi_api_send_message},
|
||||
{"cache_get", uwsgi_api_cache_get},
|
||||
{"cache_set", uwsgi_api_cache_set},
|
||||
{"cache_update", uwsgi_api_cache_update},
|
||||
{"register_signal", uwsgi_api_register_signal},
|
||||
{"register_rpc", uwsgi_api_register_rpc},
|
||||
{"lock", uwsgi_api_lock},
|
||||
|
||||
@@ -34,10 +34,18 @@ else:
|
||||
CFLAGS.append('-I' + archdir + '/' + arch)
|
||||
CFLAGS.append('-I' + includedir + '/' + arch)
|
||||
|
||||
|
||||
LDFLAGS = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['LDFLAGS']\"" % rbconfig).read().rstrip().split()
|
||||
|
||||
libpath = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['libdir']\"" % rbconfig).read().rstrip()
|
||||
LDFLAGS.append('-L' + libpath )
|
||||
os.environ['LD_RUN_PATH'] = libpath
|
||||
LIBS = os.popen(RUBYPATH + " -e \"require 'rbconfig';print '-l' + %s::CONFIG['RUBY_SO_NAME']\"" % rbconfig).read().rstrip().split()
|
||||
|
||||
has_shared = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['ENABLE_SHARED']\"" % rbconfig).read().rstrip()
|
||||
|
||||
LIBS = os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['LIBS']\"" % rbconfig).read().rstrip().split()
|
||||
|
||||
if has_shared == 'yes':
|
||||
LDFLAGS.append('-L' + libpath )
|
||||
os.environ['LD_RUN_PATH'] = libpath
|
||||
LIBS.append(os.popen(RUBYPATH + " -e \"require 'rbconfig';print '-l' + %s::CONFIG['RUBY_SO_NAME']\"" % rbconfig).read().rstrip())
|
||||
else:
|
||||
GCC_LIST.append("%s/%s" % (libpath, os.popen(RUBYPATH + " -e \"require 'rbconfig';print %s::CONFIG['LIBRUBY_A']\"" % rbconfig).read().rstrip()))
|
||||
|
||||
|
||||
@@ -338,6 +338,8 @@ int uwsgi_proto_http_parser(struct wsgi_request *wsgi_req) {
|
||||
memcpy(post_tail, ptr, remains);
|
||||
}
|
||||
http_parse(wsgi_req, ptr);
|
||||
wsgi_req->uh.modifier1 = uwsgi.http_modifier1;
|
||||
wsgi_req->uh.modifier2 = uwsgi.http_modifier2;
|
||||
//is there a Content_Length ?
|
||||
if (wsgi_req->post_cl > 0) {
|
||||
wsgi_req->async_post = tmpfile();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'uwsgi'
|
||||
s.license = 'GPL-2'
|
||||
s.version = `python -c "import uwsgiconfig as uc; print uc.uwsgi_version"`.sub(/-dev-.*/,'')
|
||||
s.date = '2013-03-02'
|
||||
s.summary = "uWSGI"
|
||||
s.description = "The uWSGI server for Ruby/Rack"
|
||||
s.authors = ["Unbit"]
|
||||
s.email = 'info@unbit.it'
|
||||
s.extensions = ['ext/uwsgi/extconf.rb']
|
||||
s.files = []
|
||||
s.require_paths = ['.']
|
||||
s.executables << 'uwsgi'
|
||||
s.homepage = 'http://projects.unbit.it/uwsgi'
|
||||
end
|
||||
@@ -1309,6 +1309,9 @@ struct uwsgi_server {
|
||||
|
||||
int reuse_port;
|
||||
|
||||
uint64_t http_modifier1;
|
||||
uint64_t http_modifier2;
|
||||
|
||||
// enable lazy mode
|
||||
int lazy;
|
||||
// enable lazy-apps mode
|
||||
@@ -1356,6 +1359,7 @@ struct uwsgi_server {
|
||||
pid_t emperor_pid;
|
||||
int emperor_broodlord;
|
||||
int emperor_broodlord_count;
|
||||
uint64_t emperor_broodlord_num;
|
||||
char *emperor_stats;
|
||||
int emperor_stats_fd;
|
||||
struct uwsgi_string_list *vassals_templates;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
# uWSGI build system
|
||||
|
||||
uwsgi_version = '1.4.7'
|
||||
uwsgi_version = '1.4.9'
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
Reference in New Issue
Block a user