mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-08-19 03:57:21 +00:00
ported http-socket to the new api
This commit is contained in:
+10
-10
@@ -1809,14 +1809,15 @@ setup_proto:
|
||||
requested_protocol = uwsgi.protocol;
|
||||
}
|
||||
|
||||
uwsgi_log("AAAAAAAA %s\n", requested_protocol);
|
||||
|
||||
if (requested_protocol && !strcmp("http", requested_protocol)) {
|
||||
uwsgi_sock->proto = uwsgi_proto_http_parser;
|
||||
uwsgi_sock->proto_accept = uwsgi_proto_base_accept;
|
||||
uwsgi_sock->proto_write = uwsgi_proto_uwsgi_write;
|
||||
uwsgi_sock->proto_write_headers = uwsgi_proto_uwsgi_write;
|
||||
uwsgi_sock->proto_sendfile = NULL;
|
||||
uwsgi_sock->proto_prepare_headers = uwsgi_proto_base_prepare_headers;
|
||||
uwsgi_sock->proto_add_header = uwsgi_proto_base_add_header;
|
||||
uwsgi_sock->proto_fix_headers = uwsgi_proto_base_fix_headers;
|
||||
uwsgi_sock->proto_write = uwsgi_proto_base_write;
|
||||
uwsgi_sock->proto_write_headers = uwsgi_proto_base_write;
|
||||
uwsgi_sock->proto_sendfile = uwsgi_proto_base_sendfile;
|
||||
uwsgi_sock->proto_close = uwsgi_proto_base_close;
|
||||
if (uwsgi.offload_threads > 0)
|
||||
uwsgi_sock->can_offload = 1;
|
||||
@@ -1840,13 +1841,12 @@ setup_proto:
|
||||
else {
|
||||
uwsgi_sock->proto = uwsgi_proto_uwsgi_parser;
|
||||
uwsgi_sock->proto_accept = uwsgi_proto_base_accept;
|
||||
uwsgi_log("AAAAAAAA\n");
|
||||
uwsgi_sock->proto_prepare_headers = uwsgi_proto_base_prepare_headers;
|
||||
uwsgi_sock->proto_add_header = uwsgi_proto_base_add_header;
|
||||
uwsgi_sock->proto_fix_headers = uwsgi_proto_uwsgi_fix_headers;
|
||||
uwsgi_sock->proto_write = uwsgi_proto_uwsgi_write;
|
||||
uwsgi_sock->proto_write_headers = uwsgi_proto_uwsgi_write;
|
||||
uwsgi_sock->proto_sendfile = uwsgi_proto_uwsgi_sendfile;
|
||||
uwsgi_sock->proto_fix_headers = uwsgi_proto_base_fix_headers;
|
||||
uwsgi_sock->proto_write = uwsgi_proto_base_write;
|
||||
uwsgi_sock->proto_write_headers = uwsgi_proto_base_write;
|
||||
uwsgi_sock->proto_sendfile = uwsgi_proto_base_sendfile;
|
||||
uwsgi_sock->proto_close = uwsgi_proto_base_close;
|
||||
if (uwsgi.offload_threads > 0)
|
||||
uwsgi_sock->can_offload = 1;
|
||||
|
||||
@@ -162,3 +162,45 @@ end:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_proto_base_write(struct wsgi_request * wsgi_req, char *buf, size_t len) {
|
||||
ssize_t wlen = write(wsgi_req->poll.fd, buf+wsgi_req->write_pos, len-wsgi_req->write_pos);
|
||||
if (wlen > 0) {
|
||||
wsgi_req->write_pos += wlen;
|
||||
if (wsgi_req->write_pos == len) {
|
||||
return UWSGI_OK;
|
||||
}
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
if (wlen < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int uwsgi_proto_base_sendfile(struct wsgi_request * wsgi_req, int fd, size_t pos, size_t len) {
|
||||
ssize_t wlen = uwsgi_sendfile_do(wsgi_req->poll.fd, fd, pos+wsgi_req->write_pos, len-wsgi_req->write_pos);
|
||||
uwsgi_log("wlen = %d\n", wlen);
|
||||
if (wlen > 0) {
|
||||
wsgi_req->write_pos += wlen;
|
||||
uwsgi_log("write_pos %d %d\n", wsgi_req->write_pos, len);
|
||||
if (wsgi_req->write_pos == len) {
|
||||
uwsgi_log("OK\n");
|
||||
return UWSGI_OK;
|
||||
}
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
if (wlen < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int uwsgi_proto_base_fix_headers(struct wsgi_request * wsgi_req) {
|
||||
return uwsgi_buffer_append(wsgi_req->headers, "\r\n", 2);
|
||||
}
|
||||
|
||||
|
||||
@@ -115,44 +115,3 @@ int uwsgi_proto_uwsgi_parser(struct wsgi_request *wsgi_req) {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int uwsgi_proto_uwsgi_write(struct wsgi_request * wsgi_req, char *buf, size_t len) {
|
||||
ssize_t wlen = write(wsgi_req->poll.fd, buf+wsgi_req->write_pos, len-wsgi_req->write_pos);
|
||||
if (wlen > 0) {
|
||||
wsgi_req->write_pos += wlen;
|
||||
if (wsgi_req->write_pos == len) {
|
||||
return UWSGI_OK;
|
||||
}
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
if (wlen < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int uwsgi_proto_uwsgi_sendfile(struct wsgi_request * wsgi_req, int fd, size_t pos, size_t len) {
|
||||
ssize_t wlen = uwsgi_sendfile_do(wsgi_req->poll.fd, fd, pos+wsgi_req->write_pos, len-wsgi_req->write_pos);
|
||||
uwsgi_log("wlen = %d\n", wlen);
|
||||
if (wlen > 0) {
|
||||
wsgi_req->write_pos += wlen;
|
||||
uwsgi_log("write_pos %d %d\n", wsgi_req->write_pos, len);
|
||||
if (wsgi_req->write_pos == len) {
|
||||
uwsgi_log("OK\n");
|
||||
return UWSGI_OK;
|
||||
}
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
if (wlen < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int uwsgi_proto_uwsgi_fix_headers(struct wsgi_request * wsgi_req) {
|
||||
return uwsgi_buffer_append(wsgi_req->headers, "\r\n", 2);
|
||||
}
|
||||
|
||||
@@ -2898,8 +2898,8 @@ size_t uwsgi_str_num(char *, int);
|
||||
|
||||
|
||||
int uwsgi_proto_uwsgi_parser(struct wsgi_request *);
|
||||
int uwsgi_proto_uwsgi_write(struct wsgi_request *, char *, size_t);
|
||||
int uwsgi_proto_uwsgi_write_header(struct wsgi_request *, char *, size_t);
|
||||
int uwsgi_proto_base_write(struct wsgi_request *, char *, size_t);
|
||||
int uwsgi_proto_base_write_header(struct wsgi_request *, char *, size_t);
|
||||
|
||||
int uwsgi_proto_http_parser(struct wsgi_request *);
|
||||
|
||||
@@ -3765,10 +3765,10 @@ int uwsgi_response_write_headers_do(struct wsgi_request *);
|
||||
struct uwsgi_buffer *uwsgi_proto_base_prepare_headers(struct wsgi_request *, char *, uint16_t);
|
||||
int uwsgi_response_write_body_do(struct wsgi_request *, char *, size_t);
|
||||
|
||||
int uwsgi_proto_uwsgi_sendfile(struct wsgi_request *, int, size_t, size_t);
|
||||
int uwsgi_proto_base_sendfile(struct wsgi_request *, int, size_t, size_t);
|
||||
|
||||
ssize_t uwsgi_sendfile_do(int, int, size_t, size_t);
|
||||
int uwsgi_proto_uwsgi_fix_headers(struct wsgi_request *);
|
||||
int uwsgi_proto_base_fix_headers(struct wsgi_request *);
|
||||
|
||||
void uwsgi_check_emperor(void);
|
||||
#ifdef UWSGI_AS_SHARED_LIBRARY
|
||||
|
||||
Reference in New Issue
Block a user