Rename socket_read_result to socket_result
parent
5de4fd071e
commit
cf1d164ec5
|
@ -29,7 +29,7 @@ int main(int argc, char* argv[]) {
|
|||
get_parts(dest, path_buffer, host_buffer);
|
||||
struct http_message req = build_basic_request("GET", host_buffer, path_buffer, port_num);
|
||||
struct response_info res;
|
||||
enum socket_read_result read_result = send_request(req, &res);
|
||||
enum socket_result read_result = send_request(req, &res);
|
||||
if (read_result != RESULT_OK) {
|
||||
printf("An error occured while opening the socket. Please try again.\n");
|
||||
} else {
|
||||
|
|
|
@ -106,9 +106,9 @@ static long long get_rtt(struct timeval pre_connect_time, struct timeval post_co
|
|||
* @param req The HTTP request to send
|
||||
* @param res_info A pointer to an already allocated response_info. res_info.contents must be freed by the caller.
|
||||
*
|
||||
* @return A socket_read_result representing the status of the response.
|
||||
* @return A socket_result representing the status of the response.
|
||||
*/
|
||||
enum socket_read_result send_request(struct http_message req, struct response_info *res_info) {
|
||||
enum socket_result send_request(struct http_message req, struct response_info *res_info) {
|
||||
struct addrinfo *addr_info;
|
||||
int addr_status = build_addr_info(req.address, req.port, &addr_info);
|
||||
if (addr_status != 0) {
|
||||
|
@ -149,7 +149,7 @@ enum socket_read_result send_request(struct http_message req, struct response_in
|
|||
// Send and process the request.
|
||||
send(socket_fd, req.contents, strlen(req.contents), 0);
|
||||
struct http_message res = {};
|
||||
enum socket_read_result result = get_all_remote_parts(socket_fd, TYPE_CLIENT, &res);
|
||||
enum socket_result result = get_all_remote_parts(socket_fd, TYPE_CLIENT, &res);
|
||||
res_info->contents = res.contents;
|
||||
close(socket_fd);
|
||||
free(res.start_line);
|
||||
|
|
|
@ -14,6 +14,6 @@ struct response_info {
|
|||
|
||||
struct http_message build_basic_request(const char *method, const char *host, const char *path, int port);
|
||||
void free_basic_request(struct http_message req);
|
||||
enum socket_read_result send_request(struct http_message req, struct response_info *res_info);
|
||||
enum socket_result send_request(struct http_message req, struct response_info *res_info);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -182,9 +182,9 @@ static char *read_body_until_eof(int socket_fd) {
|
|||
* @param type An indication of this socket is for a client or a server
|
||||
* @param message A http_message to store the output in.
|
||||
*
|
||||
* @return A socket_read_result indicating the result of the read.
|
||||
* @return A socket_result indicating the result of the read.
|
||||
*/
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, enum socket_type type, struct http_message *message) {
|
||||
enum socket_result get_all_remote_parts(int socket_fd, enum socket_type type, struct http_message *message) {
|
||||
ssize_t current_result_size = 0;
|
||||
char *result = NULL;
|
||||
char *buffer = malloc(BUFFER_SIZE * sizeof(char));
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#define HEADER_TRANSFER_ENCODING "Transfer-Encoding"
|
||||
|
||||
enum line_type {RESULT_START_LINE, RESULT_HEADER, RESULT_BLANK_LINE, RESULT_NO_LINE};
|
||||
enum socket_read_result {RESULT_OK, RESULT_MALFORMED, RESULT_READ_ERROR, RESULT_PROCESSING_ERROR, RESULT_WRITE_ERROR};
|
||||
enum socket_result {RESULT_OK, RESULT_MALFORMED, RESULT_READ_ERROR, RESULT_PROCESSING_ERROR, RESULT_WRITE_ERROR};
|
||||
enum socket_read_strategy {STRATEGY_CONTENT_LENGTH, STRATEGY_EOF, STRATEGY_UNDEFINED};
|
||||
enum socket_type {TYPE_CLIENT, TYPE_SERVER};
|
||||
struct line_read_result {
|
||||
|
@ -24,6 +24,6 @@ struct socket_read_info {
|
|||
long length;
|
||||
};
|
||||
|
||||
enum socket_read_result get_all_remote_parts(int socket_fd, enum socket_type type, struct http_message *message);
|
||||
enum socket_result get_all_remote_parts(int socket_fd, enum socket_type type, struct http_message *message);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -71,7 +71,7 @@ struct server_info setup(int port) {
|
|||
return info;
|
||||
}
|
||||
|
||||
enum socket_read_result serve_one_request(int sock_fd) {
|
||||
enum socket_result serve_one_request(int sock_fd) {
|
||||
int client_fd = accept(sock_fd, NULL, NULL);
|
||||
if (client_fd == -1) {
|
||||
return RESULT_WRITE_ERROR;
|
||||
|
|
|
@ -12,6 +12,6 @@ struct server_info {
|
|||
};
|
||||
|
||||
struct server_info setup(int port);
|
||||
enum socket_read_result serve_one_request(int sock_fd);
|
||||
enum socket_result serve_one_request(int sock_fd);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue