Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@precise64 committed Apr 14, 2012
2 parents 315bcb7 + ed5a268 commit d934270
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 118 deletions.
43 changes: 22 additions & 21 deletions lock.c
Expand Up @@ -118,6 +118,27 @@ pid_t uwsgi_rwlock_fast_check(struct uwsgi_lock_item *uli) {
#endif
}


void uwsgi_lock_fast(struct uwsgi_lock_item *uli) {

#ifdef EOWNERDEAD
if (pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr) == EOWNERDEAD) {
uwsgi_log("[deadlock-detector] a process holding a robust mutex died. recovering...\n");
pthread_mutex_consistent_np((pthread_mutex_t *) uli->lock_ptr);
}
#else
pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr);
#endif
uli->pid = uwsgi.mypid;
}

void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) {

pthread_mutex_unlock((pthread_mutex_t *) uli->lock_ptr);
uli->pid = 0;

}

void uwsgi_rlock_fast(struct uwsgi_lock_item *uli) {
#ifdef OBSOLETE_LINUX_KERNEL
uwsgi_lock_fast(uli);
Expand Down Expand Up @@ -145,30 +166,10 @@ void uwsgi_rwunlock_fast(struct uwsgi_lock_item *uli) {
#endif
}

void uwsgi_lock_fast(struct uwsgi_lock_item *uli) {

#ifdef EOWNERDEAD
if (pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr) == EOWNERDEAD) {
uwsgi_log("[deadlock-detector] a process holding a robust mutex died. recovering...\n");
pthread_mutex_consistent_np((pthread_mutex_t *) uli->lock_ptr);
}
#else
pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr);
#endif
uli->pid = uwsgi.mypid;
}

void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) {

pthread_mutex_unlock((pthread_mutex_t *) uli->lock_ptr);
uli->pid = 0;

}

struct uwsgi_lock_item *uwsgi_rwlock_fast_init(char *id) {

#ifdef OBSOLETE_LINUX_KERNEL
return uwsgi_lock_fast_init(uli);
return uwsgi_lock_fast_init(id);
#else

pthread_rwlockattr_t attr;
Expand Down
1 change: 1 addition & 0 deletions master.c
Expand Up @@ -140,6 +140,7 @@ void *cache_sweeper_loop(void *noarg) {
}
};

return NULL;
}

void uwsgi_subscribe(char *subscription, uint8_t cmd) {
Expand Down
5 changes: 2 additions & 3 deletions plugins/php/php_plugin.c
Expand Up @@ -94,12 +94,11 @@ static int sapi_uwsgi_ub_write(const char *str, uint str_length TSRMLS_DC)
{
struct wsgi_request *wsgi_req = (struct wsgi_request *) SG(server_context);

ssize_t len = wsgi_req->socket->proto_write(wsgi_req, (char *) str, str_length);
if (len != (ssize_t) str_length) {
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, (char *) str, str_length);
if (wsgi_req->write_errors > 0) {
php_handle_aborted_connection();
return -1;
}
wsgi_req->response_size += len;
return str_length;
}

Expand Down
4 changes: 1 addition & 3 deletions plugins/psgi/psgi_response.c
Expand Up @@ -126,9 +126,7 @@ int psgi_response(struct wsgi_request *wsgi_req, AV *response) {
vi = (i*2)+base;
wsgi_req->hvec[vi].iov_base = "\r\n"; wsgi_req->hvec[vi].iov_len = 2;

if ( !(wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, vi+1)) ) {
uwsgi_error("writev()");
}
wsgi_req->headers_size += wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, vi+1);

hitem = av_fetch(response, 2, 0);

Expand Down
1 change: 1 addition & 0 deletions plugins/python/python_plugin.c
Expand Up @@ -552,6 +552,7 @@ void init_uwsgi_embedded_module() {
// just for safety
Py_INCREF(up.embedded_dict);


if (PyDict_SetItemString(up.embedded_dict, "version", PyString_FromString(UWSGI_VERSION))) {
PyErr_Print();
exit(1);
Expand Down
2 changes: 2 additions & 0 deletions plugins/python/uwsgi_python.h
Expand Up @@ -38,6 +38,8 @@
#define PyVarObject_HEAD_INIT(x, y) PyObject_HEAD_INIT(x) y,
#endif

#define uwsgi_py_write_set_exception(x) PyErr_SetString(PyExc_IOError, "write error");
#define uwsgi_py_write_exception(x) uwsgi_py_write_set_exception(x); PyErr_Print();

PyAPI_FUNC(PyObject *) PyMarshal_WriteObjectToString(PyObject *, int);
PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
Expand Down
22 changes: 14 additions & 8 deletions plugins/python/web3_subhandler.c
Expand Up @@ -134,7 +134,6 @@ void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_
int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {

PyObject *pychunk;
ssize_t wsize;

// ok its a yield
if (!wsgi_req->async_placeholder) {
Expand Down Expand Up @@ -168,11 +167,14 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {
Py_DECREF(spit_args);

if (PyString_Check((PyObject *)wsgi_req->async_placeholder)) {
if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(wsgi_req->async_placeholder), PyString_Size(wsgi_req->async_placeholder))) < 0) {
uwsgi_error("write()");
goto clear;
char *content = PyString_AsString(wsgi_req->async_placeholder);
size_t content_len = PyString_Size(wsgi_req->async_placeholder);
UWSGI_RELEASE_GIL
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
UWSGI_GET_GIL
if (wsgi_req->write_errors > 0) {
uwsgi_py_write_exception(wsgi_req);
}
wsgi_req->response_size += wsize;
goto clear;
}

Expand Down Expand Up @@ -208,12 +210,16 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) {


if (PyString_Check(pychunk)) {
if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
uwsgi_error("write()");
char *content = PyString_AsString(pychunk);
size_t content_len = PyString_Size(pychunk);
UWSGI_RELEASE_GIL
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
UWSGI_GET_GIL
if (wsgi_req->write_errors > 0) {
uwsgi_py_write_exception(wsgi_req);
Py_DECREF(pychunk);
goto clear;
}
wsgi_req->response_size += wsize;
}


Expand Down
4 changes: 4 additions & 0 deletions plugins/python/wsgi_handlers.c
Expand Up @@ -278,6 +278,10 @@ PyObject *py_uwsgi_write(PyObject * self, PyObject * args) {
UWSGI_RELEASE_GIL
wsgi_req->response_size = wsgi_req->socket->proto_write(wsgi_req, content, len);
UWSGI_GET_GIL
if (wsgi_req->write_errors > 0) {
uwsgi_py_write_set_exception(wsgi_req);
return NULL;
}
}

Py_INCREF(Py_None);
Expand Down
22 changes: 14 additions & 8 deletions plugins/python/wsgi_subhandler.c
Expand Up @@ -158,18 +158,20 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {

PyObject *pychunk;
ssize_t wsize;
#ifdef UWSGI_SENDFILE
ssize_t sf_len = 0;
#endif

// return or yield ?
if (PyString_Check((PyObject *)wsgi_req->async_result)) {
if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(wsgi_req->async_result), PyString_Size(wsgi_req->async_result))) < 0) {
uwsgi_error("write()");
goto clear;
char *content = PyString_AsString(wsgi_req->async_result);
size_t content_len = PyString_Size(wsgi_req->async_result);
UWSGI_RELEASE_GIL
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
UWSGI_GET_GIL
if (wsgi_req->write_errors > 0) {
uwsgi_py_write_exception(wsgi_req);
}
wsgi_req->response_size += wsize;
goto clear;
}

Expand Down Expand Up @@ -248,12 +250,16 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {


if (PyString_Check(pychunk)) {
if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
uwsgi_error("write()");
char *content = PyString_AsString(pychunk);
size_t content_len = PyString_Size(pychunk);
UWSGI_RELEASE_GIL
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
UWSGI_GET_GIL
if (wsgi_req->write_errors > 0) {
uwsgi_py_write_exception(wsgi_req);
Py_DECREF(pychunk);
goto clear;
}
wsgi_req->response_size += wsize;
}

#ifdef UWSGI_SENDFILE
Expand Down
13 changes: 3 additions & 10 deletions plugins/rack/rack_plugin.c
Expand Up @@ -520,18 +520,15 @@ VALUE call_dispatch(VALUE env) {
static VALUE send_body(VALUE obj) {

struct wsgi_request *wsgi_req = current_wsgi_req();
ssize_t len = 0;

//uwsgi_log("sending body\n");
if (TYPE(obj) == T_STRING) {
len = wsgi_req->socket->proto_write( wsgi_req, RSTRING_PTR(obj), RSTRING_LEN(obj));
wsgi_req->response_size += wsgi_req->socket->proto_write( wsgi_req, RSTRING_PTR(obj), RSTRING_LEN(obj));
}
else {
uwsgi_log("UNMANAGED BODY TYPE %d\n", TYPE(obj));
}

wsgi_req->response_size += len;

return Qnil;
}

Expand Down Expand Up @@ -765,9 +762,7 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) {
wsgi_req->hvec[5].iov_base = (char *) "\r\n";
wsgi_req->hvec[5].iov_len = 2 ;

if ( !(wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, 6)) ) {
uwsgi_error("writev()");
}
wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, 6);

headers = RARRAY_PTR(ret)[1] ;
if (rb_respond_to( headers, rb_intern("each") )) {
Expand All @@ -778,9 +773,7 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) {
}
}

if (wsgi_req->socket->proto_write(wsgi_req, (char *)"\r\n", 2) != 2) {
uwsgi_error("write()");
}
wsgi_req->socket->proto_write(wsgi_req, (char *)"\r\n", 2);

body = RARRAY_PTR(ret)[2] ;

Expand Down
38 changes: 29 additions & 9 deletions proto/fastcgi.c
Expand Up @@ -193,22 +193,42 @@ ssize_t uwsgi_proto_fastcgi_write(struct wsgi_request * wsgi_req, char *buf, siz
if (len <= 65535) {
rlen = write(wsgi_req->poll.fd, &fr, 8);
if (rlen <= 0) {
return rlen;
if (!uwsgi.ignore_write_errors) {
uwsgi_req_error("write()");
}
wsgi_req->write_errors++;
return 0;
}
return write(wsgi_req->poll.fd, buf, len);
rlen = write(wsgi_req->poll.fd, buf, len);
if (rlen <= 0) {
if (!uwsgi.ignore_write_errors) {
uwsgi_req_error("write()");
}
wsgi_req->write_errors++;
return 0;
}
return rlen;
}
else {
while(len > 0) {
chunk_len = UMIN(65535, len);
fr.cl = htons(chunk_len);
rlen = write(wsgi_req->poll.fd, &fr, 8);
if (rlen <= 0) {
return rlen;
}
if (rlen != 8) {
if (!uwsgi.ignore_write_errors) {
uwsgi_req_error("write()");
}
wsgi_req->write_errors++;
return 0;
}
rlen = write(wsgi_req->poll.fd, ptr, chunk_len);
if (rlen <= 0) {
return rlen;
}
if (rlen != 8) {
if (!uwsgi.ignore_write_errors) {
uwsgi_req_error("write()");
}
wsgi_req->write_errors++;
return 0;
}
ptr += rlen;
len -= rlen;
}
Expand All @@ -224,7 +244,7 @@ ssize_t uwsgi_proto_fastcgi_write_header(struct wsgi_request * wsgi_req, char *b
void uwsgi_proto_fastcgi_close(struct wsgi_request *wsgi_req) {

if (write(wsgi_req->poll.fd, FCGI_END_REQUEST, 24) <= 0) {
uwsgi_error("write()");
uwsgi_req_error("write()");
}

uwsgi_proto_base_close(wsgi_req);
Expand Down
16 changes: 0 additions & 16 deletions proto/http.c
Expand Up @@ -369,19 +369,3 @@ int uwsgi_proto_http_parser(struct wsgi_request *wsgi_req) {

return UWSGI_AGAIN;
}

ssize_t uwsgi_proto_http_writev_header(struct wsgi_request * wsgi_req, struct iovec * iovec, size_t iov_len) {
return writev(wsgi_req->poll.fd, iovec, iov_len);
}

ssize_t uwsgi_proto_http_writev(struct wsgi_request * wsgi_req, struct iovec * iovec, size_t iov_len) {
return writev(wsgi_req->poll.fd, iovec, iov_len);
}

ssize_t uwsgi_proto_http_write(struct wsgi_request * wsgi_req, char *buf, size_t len) {
return write(wsgi_req->poll.fd, buf, len);
}

ssize_t uwsgi_proto_http_write_header(struct wsgi_request * wsgi_req, char *buf, size_t len) {
return write(wsgi_req->poll.fd, buf, len);
}

0 comments on commit d934270

Please sign in to comment.