Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bytevia
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Michael Pastushkov
bytevia
Commits
b006c025
Commit
b006c025
authored
Sep 17, 2024
by
Michael Pastushkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
86bb5003
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
27 deletions
+31
-27
run_udp_client
+2
-2
src/bytevia.c
+25
-22
temp/test2.c
+4
-3
No files found.
run_udp_client
View file @
b006c025
#!/bin/sh
make clean
&&
make
&&
./bytevia
--local-port
=
1948
--remote-host
=
p4pn.net
--remote-port
=
1984
--proto
=
udp
--secret
=
52341
--fork
\ No newline at end of file
make clean
&&
make
&&
./bytevia
--local-port
=
1948
--remote-host
=
p4pn.net
--remote-port
=
1984
--proto
=
udp
--secret
=
52341
\ No newline at end of file
src/bytevia.c
View file @
b006c025
...
...
@@ -255,18 +255,6 @@ int wait_connection(void) {
perror
(
"wait_connection: accept()"
);
return
1
;
}
// if (options.fork && options.proto == SOCK_DGRAM && !is_child) {
// if (udp_fork(client_addr) == 1)
// continue;
// }
// fd_set io;
// FD_ZERO(&io);
// FD_SET(rc.client_socket, &io);
// if (select(rc.client_socket+1, &io, NULL, NULL, NULL) < 0) {
// if (errno != EINTR)
// perror("wait_connection: select()");
// return 1;
// }
}
else
{
rc
.
client_socket
=
accept
(
rc
.
server_socket
,
(
struct
sockaddr
*
)
&
rc
.
client_addr
,
&
client_addr_size
);
if
(
rc
.
client_socket
<
0
)
{
...
...
@@ -323,14 +311,25 @@ int add_udp_client(struct sockaddr_in client_addr, pid_t pid) {
if
(
clients
[
i
].
pid
==
0
)
{
clients
[
i
].
addr
=
client_addr
;
clients
[
i
].
pid
=
pid
;
return
0
;
}
}
return
-
1
;
/* No space for new clients */
}
printf
(
"client %s added ...
\n
"
,
inet_ntoa
(
client_addr
.
sin_addr
));
return
0
;
// Successfully added client
void
remove_udp_client
(
pid_t
pid
)
{
int
i
;
for
(
i
=
0
;
i
<
MAX_UDP_CLIENTS
;
i
++
)
{
if
(
clients
[
i
].
pid
==
pid
)
{
if
(
options
.
log
)
printf
(
"removing client %s, pid: %d
\n
"
,
inet_ntoa
(
clients
[
i
].
addr
.
sin_addr
),
pid
);
clients
[
i
].
pid
=
0
;
memset
(
&
clients
[
i
].
addr
,
0
,
sizeof
(
clients
[
i
].
addr
));
break
;
}
}
return
-
1
;
// No space for new clients
}
int
compare_clients
(
struct
sockaddr_in
client1
,
struct
sockaddr_in
client2
)
{
return
(
client1
.
sin_addr
.
s_addr
==
client2
.
sin_addr
.
s_addr
&&
client1
.
sin_port
==
client2
.
sin_port
);
...
...
@@ -340,7 +339,6 @@ int find_udp_client(struct sockaddr_in client_addr) {
int
i
;
for
(
i
=
0
;
i
<
MAX_UDP_CLIENTS
;
i
++
)
if
(
clients
[
i
].
pid
>
0
&&
compare_clients
(
clients
[
i
].
addr
,
client_addr
))
{
printf
(
"client %s found %d ...
\n
"
,
inet_ntoa
(
client_addr
.
sin_addr
),
i
);
return
i
;
}
return
-
1
;
...
...
@@ -443,17 +441,22 @@ int fork_udp() {
if
(
client_index
==
-
1
)
{
if
((
child_pid
=
fork
())
==
0
)
{
if
(
options
.
log
)
printf
(
"
forking for %s,
%d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
getpid
());
printf
(
"
request from %s, forking
%d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
getpid
());
run
();
exit
(
0
);
}
add_udp_client
(
rc
.
client_addr
,
child_pid
);
if
(
add_udp_client
(
rc
.
client_addr
,
child_pid
)
<
0
)
{
printf
(
"maximum clients %d reached:
\n
"
,
MAX_UDP_CLIENTS
);
}
// while (waitpid(-1, NULL, WNOHANG) > 0)
// ; /* Reap any zombie processes (clients that exited) */
// Reap any zombie processes (clients that exited)
while
((
child_pid
=
waitpid
(
-
1
,
NULL
,
WNOHANG
))
>
0
)
{
remove_udp_client
(
child_pid
);
}
}
else
{
printf
(
"existing udp client %s, handled by %d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
clients
[
client_index
].
pid
);
if
(
options
.
log
>
2
)
printf
(
"existing udp client %s, handled by %d ...
\n
"
,
inet_ntoa
(
rc
.
client_addr
.
sin_addr
),
clients
[
client_index
].
pid
);
}
return
1
;
}
...
...
temp/test2.c
View file @
b006c025
...
...
@@ -173,9 +173,10 @@ int main()
printf
(
"Existing client sent a request, handled by child process with PID: %d
\n
"
,
clients
[
client_index
].
pid
);
}
// Reap any zombie processes (clients that exited)
while
(
waitpid
(
-
1
,
NULL
,
WNOHANG
)
>
0
)
;
// // Reap any zombie processes (clients that exited)
// while ((child_pid = waitpid(-1, NULL, WNOHANG)) > 0) {
// remove_client_by_pid(child_pid);
// }
}
close
(
sockfd
);
...
...
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