struct connection *connmgr_accept(int fd) { struct sockaddr_in sai; int new_fd; unsigned int len = sizeof(sai); struct connection *c; long c_id; new_fd = accept(fd, (struct sockaddr *)&sai, &len); if (-1 == new_fd) { perror("accept"); return NULL; } c_id = http_open_connection(new_fd); c = cos_map_lookup(&conn_map, c_id); if (NULL == c) http_close_connection(c_id); return c; }
struct HttpResponse *executeRequest(struct Host *host, struct HttpRequest *request) { debug("execute request %s:%d", host->url, host->port); int sockfd = http_open_connection(host->url, host->port); if (sockfd == -1) { return NULL; } const char *connection_type = dict_get_case(request->headers, "Connection"); debug("connection_type: %s", connection_type); if (http_send_request(sockfd, request) != 0) { return NULL; } struct HttpResponse *response; int http_error = http_receive_response(sockfd, &response); if (http_error != HTTP_SUCCESS) { debug("http error: executeRequest"); } debug("Close socket."); close(sockfd); return response; }