Conversation
new file: README.md new file: include/calculation.h new file: include/http_request.h new file: include/http_response.h new file: include/server.h new file: include/utils.h new file: src/core/calculation.c new file: src/core/http_request.c new file: src/core/http_response.c new file: src/core/server.c new file: src/main.c new file: src/utils/utils.c new file: tests/client.c new file: tests/test.sh
takumihara
reviewed
Mar 20, 2026
| if (!pointer) { | ||
| log_exit("Memory allocation failed for %zu bytes", size); | ||
| } | ||
| memset(pointer, 0, size); |
|
|
||
| static char *server_receive_request(int client_socket) { | ||
| char *buffer = xmalloc(BUFFER_SIZE); | ||
| ssize_t bytes_read = read(client_socket, buffer, BUFFER_SIZE - 1); |
There was a problem hiding this comment.
read が1回で全部のデータを読んでくれるかは分からないです。\r\n\r\n がくるまでloopで回すのが正しいです
| if (request->method_len != 3 || strncmp(request->method, "GET", 3) != 0) { | ||
| response_build_error(response, sizeof(response), | ||
| HTTP_BAD_REQUEST, "Only GET method is supported"); | ||
| if (write(client_socket, response, strlen(response)) < 0) { |
| is_shutdown_requested = 1; | ||
| } | ||
|
|
||
| static void server_signal_setup(void) { |
There was a problem hiding this comment.
せっかくなので、 SIGPIPE のハンドリングも入れてもいいかもです!
Comment on lines
+47
to
+48
| if (write(client_socket, response, strlen(response)) < 0) { | ||
| log_error("Failed to send response: %s", strerror(errno)); |
There was a problem hiding this comment.
errno が EINTR の場合は、エラーログをが出さないほうが綺麗かもです
Comment on lines
+22
to
+23
| matched = sscanf(uri_buffer, "/calc?query=%d%c%d", | ||
| out_operand1, out_op_char, out_operand2); |
There was a problem hiding this comment.
query が最初のquery parameterになるかは分からないですよね?
/calc?utm_source=google&query=1+2
Comment on lines
+22
to
+23
| matched = sscanf(uri_buffer, "/calc?query=%d%c%d", | ||
| out_operand1, out_op_char, out_operand2); |
There was a problem hiding this comment.
例えば、 query=2147483648+1がここにきたらどうなりますか?
| log_exit("Missing required arguments.\nUsage: ./http_server <port_number>"); | ||
| } | ||
|
|
||
| port_number = atoi(argv[1]); |
Comment on lines
+61
to
+63
| if (argc != 3) { | ||
| printf("usage: %s [ip address] [port]\n", argv[0]); | ||
| } |
| * ネットワーク処理 | ||
| * ==================================================================== */ | ||
|
|
||
| static int server_socket_create(int port) { |
There was a problem hiding this comment.
static 関数なのでファイルスコープに閉じているため、server_ プレフィックスは不要かもしれないです。また、verb から始める命名(create_socket)にすると、何をする関数かが一目で分かりやすくなります。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.