mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-04 16:08:31 +00:00
ported router_uwsgi to the new api
This commit is contained in:
@@ -44,48 +44,32 @@ int uwsgi_routing_func_uwsgi_remote(struct wsgi_request *wsgi_req, struct uwsgi_
|
||||
uwsgi_req_append(wsgi_req, "UWSGI_APPID", 11, ur->data2, ur->data2_len);
|
||||
}
|
||||
|
||||
size_t remains = wsgi_req->post_cl - wsgi_req->proto_parser_remains;
|
||||
|
||||
struct uwsgi_buffer *ub = uwsgi_buffer_new(4 + wsgi_req->uh->pktsize + wsgi_req->proto_parser_remains);
|
||||
if (uwsgi_buffer_append(ub, (char *) uh, 4)) goto end;
|
||||
if (uwsgi_buffer_append(ub, wsgi_req->buffer, uh->pktsize)) goto end;
|
||||
uh->pktsize = wsgi_req->uh->pktsize;
|
||||
if (wsgi_req->proto_parser_remains > 0) {
|
||||
if (uwsgi_buffer_append(ub, wsgi_req->proto_parser_remains_buf, wsgi_req->proto_parser_remains)) {
|
||||
goto end;
|
||||
}
|
||||
wsgi_req->proto_parser_remains = 0;
|
||||
}
|
||||
|
||||
// ok now if have offload threads, directly use them
|
||||
if (wsgi_req->socket->can_offload) {
|
||||
struct uwsgi_buffer *ub = uwsgi_buffer_new(4 + wsgi_req->uh->pktsize);
|
||||
if (ub) {
|
||||
uh->pktsize = wsgi_req->uh->pktsize;
|
||||
if (uwsgi_buffer_append(ub, (char *) uh, 4)) goto bad;
|
||||
if (uwsgi_buffer_append(ub, wsgi_req->buffer, uh->pktsize)) goto bad;
|
||||
if (!uwsgi_offload_request_net_do(wsgi_req, addr, ub)) {
|
||||
wsgi_req->via = UWSGI_VIA_OFFLOAD;
|
||||
return UWSGI_ROUTE_BREAK;
|
||||
}
|
||||
bad:
|
||||
uwsgi_buffer_destroy(ub);
|
||||
if (!uwsgi_offload_request_net_do(wsgi_req, addr, ub)) {
|
||||
wsgi_req->via = UWSGI_VIA_OFFLOAD;
|
||||
return UWSGI_ROUTE_BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_fd = uwsgi_connect(addr, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
if (uwsgi_fd < 0) {
|
||||
uwsgi_log("unable to connect to host %s\n", addr);
|
||||
return UWSGI_ROUTE_NEXT;
|
||||
}
|
||||
|
||||
int post_fd = wsgi_req->fd;
|
||||
if (wsgi_req->post_file) {
|
||||
post_fd = fileno(wsgi_req->post_file);
|
||||
}
|
||||
|
||||
if (uwsgi_send_message(uwsgi_fd, uh->modifier1, uh->modifier2, wsgi_req->buffer, wsgi_req->uh->pktsize, post_fd, wsgi_req->post_cl, 0) < 0) {
|
||||
uwsgi_log("unable to send uwsgi request to host %s", addr);
|
||||
return UWSGI_ROUTE_NEXT;
|
||||
}
|
||||
|
||||
ssize_t ret = uwsgi_pipe(uwsgi_fd, wsgi_req->fd, 0);
|
||||
if (ret > 0) {
|
||||
wsgi_req->response_size += ret;
|
||||
}
|
||||
else {
|
||||
uwsgi_log("unable to manage uwsgi route response for %s\n", addr);
|
||||
}
|
||||
|
||||
close(uwsgi_fd);
|
||||
if (uwsgi_proxy_nb(wsgi_req, addr, ub, remains, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
uwsgi_log("error routing request to uwsgi server %s\n", addr);
|
||||
}
|
||||
end:
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return UWSGI_ROUTE_BREAK;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user