Add sock_init()
This commit is contained in:
@ -315,13 +315,14 @@ int proxy_init(proxy_ctx_t **proxy_ptr, http_req *req, http_res *res, http_statu
|
|||||||
retry = 0;
|
retry = 0;
|
||||||
tries++;
|
tries++;
|
||||||
|
|
||||||
proxy->proxy.socket = socket(AF_INET6, SOCK_STREAM, 0);
|
int fd;
|
||||||
if (proxy->proxy.socket < 0) {
|
if ((fd = socket(AF_INET6, SOCK_STREAM, 0)) == -1) {
|
||||||
error("Unable to create socket");
|
error("Unable to create socket");
|
||||||
res->status = http_get_status(500);
|
res->status = http_get_status(500);
|
||||||
ctx->origin = INTERNAL;
|
ctx->origin = INTERNAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
sock_init(&proxy->proxy, fd, 0);
|
||||||
|
|
||||||
if (sock_set_socket_timeout(&proxy->proxy, 1) != 0 || sock_set_timeout(&proxy->proxy, SERVER_TIMEOUT_INIT) != 0)
|
if (sock_set_socket_timeout(&proxy->proxy, 1) != 0 || sock_set_timeout(&proxy->proxy, SERVER_TIMEOUT_INIT) != 0)
|
||||||
goto proxy_timeout_err;
|
goto proxy_timeout_err;
|
||||||
|
@ -60,6 +60,15 @@ const char *sock_error_str(unsigned long err) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sock_init(sock *s, int fd, int enc) {
|
||||||
|
s->socket = fd;
|
||||||
|
s->enc = enc;
|
||||||
|
s->ts_start = clock_micros();
|
||||||
|
s->ts_last = s->ts_start;
|
||||||
|
s->timeout_us = -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int sock_set_socket_timeout_micros(sock *s, long recv_micros, long send_micros) {
|
int sock_set_socket_timeout_micros(sock *s, long recv_micros, long send_micros) {
|
||||||
struct timeval recv_to = {.tv_sec = recv_micros / 1000000, .tv_usec = recv_micros % 1000000},
|
struct timeval recv_to = {.tv_sec = recv_micros / 1000000, .tv_usec = recv_micros % 1000000},
|
||||||
send_to = {.tv_sec = send_micros / 1000000, .tv_usec = send_micros % 1000000};
|
send_to = {.tv_sec = send_micros / 1000000, .tv_usec = send_micros % 1000000};
|
||||||
|
@ -33,6 +33,8 @@ void sock_error(sock *s, int ret);
|
|||||||
|
|
||||||
const char *sock_error_str(unsigned long err);
|
const char *sock_error_str(unsigned long err);
|
||||||
|
|
||||||
|
int sock_init(sock *s, int fd, int enc);
|
||||||
|
|
||||||
int sock_set_socket_timeout_micros(sock *s, long recv_micros, long send_micros);
|
int sock_set_socket_timeout_micros(sock *s, long recv_micros, long send_micros);
|
||||||
|
|
||||||
int sock_set_socket_timeout(sock *s, double sec);
|
int sock_set_socket_timeout(sock *s, double sec);
|
||||||
|
@ -135,10 +135,7 @@ static void accept_cb(void *arg) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
client->socket = client_fd;
|
sock_init(client, client_fd, (i == 1));
|
||||||
client->enc = (i == 1);
|
|
||||||
client->ts_start = clock_micros();
|
|
||||||
client->ts_last = client->ts_start;
|
|
||||||
client_ctx->cnx_s = client->ts_start;
|
client_ctx->cnx_s = client->ts_start;
|
||||||
client_ctx->cnx_e = -1, client_ctx->req_s = -1, client_ctx->req_e = -1, client_ctx->res_ts = -1;
|
client_ctx->cnx_e = -1, client_ctx->req_s = -1, client_ctx->req_e = -1, client_ctx->res_ts = -1;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user