Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
c12.2.0-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eazy-template
c12.2.0-template
Commits
17639659
Commit
17639659
authored
Sep 15, 2025
by
xiezhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
731707c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
hello_world.c
hello_world.c
+9
-4
No files found.
hello_world.c
View file @
17639659
...
...
@@ -4,6 +4,7 @@
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
...
...
@@ -15,6 +16,7 @@ volatile sig_atomic_t keep_running = 1;
// Signal handler function
void
handle_signal
(
int
sig
)
{
(
void
)
sig
;
// Suppress unused parameter warning
keep_running
=
0
;
}
...
...
@@ -73,9 +75,9 @@ int main() {
exit
(
EXIT_FAILURE
);
}
// Set socket options to reuse address
and port
// Set socket options to reuse address
int
opt
=
1
;
if
(
setsockopt
(
server_fd
,
SOL_SOCKET
,
SO_REUSEADDR
|
SO_REUSEPORT
,
&
opt
,
sizeof
(
opt
)))
{
if
(
setsockopt
(
server_fd
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
opt
,
sizeof
(
opt
)))
{
perror
(
"setsockopt failed"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -124,8 +126,11 @@ int main() {
get_time_string
(
time_buffer
,
sizeof
(
time_buffer
));
printf
(
"[%s] Request from %s
\n
"
,
time_buffer
,
client_ip
);
read
(
new_socket
,
buffer
,
BUFFER_SIZE
);
write
(
new_socket
,
http_response
,
strlen
(
http_response
));
ssize_t
bytes_read
=
read
(
new_socket
,
buffer
,
BUFFER_SIZE
);
(
void
)
bytes_read
;
// Suppress unused variable warning
ssize_t
bytes_written
=
write
(
new_socket
,
http_response
,
strlen
(
http_response
));
(
void
)
bytes_written
;
// Suppress unused variable warning
close
(
new_socket
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment