From a6184b30819f97085b9002485f2cb89473ac7694 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 12 May 2008 11:24:00 +0200 Subject: [PATCH] 1008: Moved post_fd to the struct connection. --- src/network/connection.c | 3 ++- src/network/connection.h | 1 + src/protocol/file/cgi.c | 11 +++++------ src/protocol/http/http.c | 20 +++++++++----------- src/protocol/http/http.h | 1 - 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/network/connection.c b/src/network/connection.c index 95fc5187..dd8d93a8 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -303,7 +303,7 @@ init_connection(struct uri *uri, struct uri *proxied_uri, struct uri *referrer, conn->cache_mode = cache_mode; conn->content_encoding = ENCODING_NONE; - conn->stream_pipes[0] = conn->stream_pipes[1] = -1; + conn->stream_pipes[0] = conn->stream_pipes[1] = conn->post_fd = -1; init_list(conn->downloads); conn->est_length = -1; conn->timer = TIMER_ID_UNDEF; @@ -494,6 +494,7 @@ done_connection(struct connection *conn) done_progress(conn->progress); if (conn->upload_progress) done_progress(conn->upload_progress); + if (conn->post_fd != -1) close(conn->post_fd); mem_free(conn); check_queue_bugs(); } diff --git a/src/network/connection.h b/src/network/connection.h index 0a98bc32..e796091e 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -54,6 +54,7 @@ struct connection { int tries; timer_id_T timer; int stream_pipes[2]; + int post_fd; /* used when POSTing files */ unsigned int running:1; unsigned int unrestartable:1; diff --git a/src/protocol/file/cgi.c b/src/protocol/file/cgi.c index b57533de..986513c5 100644 --- a/src/protocol/file/cgi.c +++ b/src/protocol/file/cgi.c @@ -126,7 +126,7 @@ send_big_files(struct socket *socket) } } if (n) add_bytes_to_string(&data, buffer, n); - + if (finish) { write_to_socket(socket, data.source, data.length, S_SENT, close_pipe_and_read); @@ -135,7 +135,7 @@ send_big_files(struct socket *socket) assert(end); *end = '\0'; - http->post_fd = open(big_file + 1, O_RDONLY); + conn->post_fd = open(big_file + 1, O_RDONLY); *end = BIG_FILE_CHAR; http->post_data = end + 1; socket->state = SOCKET_END_ONCLOSE; @@ -149,17 +149,16 @@ static void send_big_files2(struct socket *socket) { struct connection *conn = socket->conn; - struct http_connection_info *http = conn->info; unsigned char buffer[BIG_READ]; - int n = safe_read(http->post_fd, buffer, BIG_READ); + int n = safe_read(conn->post_fd, buffer, BIG_READ); if (n > 0) { socket->state = SOCKET_END_ONCLOSE; write_to_socket(socket, buffer, n, S_TRANS, send_big_files2); } else { - close(http->post_fd); - http->post_fd = -1; + close(conn->post_fd); + conn->post_fd = -1; send_big_files(socket); } } diff --git a/src/protocol/http/http.c b/src/protocol/http/http.c index 9087a90e..1530b19d 100644 --- a/src/protocol/http/http.c +++ b/src/protocol/http/http.c @@ -472,11 +472,9 @@ http_end_request(struct connection *conn, enum connection_state state, { shutdown_connection_stream(conn); if (conn->info) { - struct http_connection_info *http = conn->info; - - if (http->post_fd != -1) { - close(http->post_fd); - http->post_fd = -1; + if (conn->post_fd != -1) { + close(conn->post_fd); + conn->post_fd = -1; } } @@ -534,7 +532,7 @@ init_http_connection_info(struct connection *conn, int major, int minor, int clo http->sent_version.minor = minor; http->close = close; - http->post_fd = -1; + conn->post_fd = -1; /* The CGI code uses this too and blacklisting expects a host name. */ if (conn->proxied_uri->protocol != PROTOCOL_FILE) @@ -667,7 +665,7 @@ send_big_files(struct socket *socket) assert(end); *end = '\0'; - http->post_fd = open(big_file + 1, O_RDONLY); + conn->post_fd = open(big_file + 1, O_RDONLY); *end = BIG_FILE_CHAR; http->post_data = end + 1; socket->state = SOCKET_END_ONCLOSE; @@ -684,7 +682,7 @@ send_big_files2(struct socket *socket) struct connection *conn = socket->conn; struct http_connection_info *http = conn->info; unsigned char buffer[BIG_READ]; - int n = safe_read(http->post_fd, buffer, BIG_READ); + int n = safe_read(conn->post_fd, buffer, BIG_READ); if (n > 0) { socket->state = SOCKET_END_ONCLOSE; @@ -692,8 +690,8 @@ send_big_files2(struct socket *socket) write_to_socket(socket, buffer, n, S_TRANS, send_big_files2); } else { - close(http->post_fd); - http->post_fd = -1; + close(conn->post_fd); + conn->post_fd = -1; send_big_files(socket); } } @@ -1080,7 +1078,7 @@ http_send_header(struct socket *socket) if (big_files) { assert(!use_connect && post_data); - assert(http->post_fd == -1); + assert(conn->post_fd == -1); http->post_data = post_data; socket->state = SOCKET_END_ONCLOSE; if (!conn->upload_progress) diff --git a/src/protocol/http/http.h b/src/protocol/http/http.h index f911726c..278ad312 100644 --- a/src/protocol/http/http.h +++ b/src/protocol/http/http.h @@ -30,7 +30,6 @@ struct http_connection_info { size_t total_upload_length; size_t uploaded; unsigned char *post_data; - int post_fd; }; -- 2.11.4.GIT