Commit cd45d6a9 by Michael Pastushkov

udp fork work in progress

parent 6dc78e67
#!/bin/sh
make clean && make && ./bytevia --local-port=1984 --remote-host=p4pn.net --remote-port=1948 --proto=udp --secret=52341
\ No newline at end of file
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
#!/bin/sh
make clean && make && ./bytevia --local-port=1984 --remote-host=127.0.0.1 --remote-port=1948 --mode=server --proto=udp --secret=52341
\ No newline at end of file
make clean && make && ./bytevia --local-port=1984 --remote-host=127.0.0.1 --remote-port=1948 --mode=server --proto=udp --secret=52341 --fork
\ No newline at end of file
......@@ -244,16 +244,24 @@ int wait_connection(void) {
#else
unsigned int client_addr_size;
#endif
if (options.proto == SOCK_DGRAM)
return 0;
client_addr_size = sizeof(struct sockaddr_in);
rc.client_socket = accept(rc.server_socket, (struct sockaddr *) &rc.client_addr, &client_addr_size);
if (rc.client_socket < 0) {
if (errno != EINTR)
perror("wait_for_clients: accept()");
return 1;
if (options.proto == SOCK_DGRAM) {
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) {
if (errno != EINTR)
perror("wait_connection: accept()");
return 1;
}
}
if (options.client_address && (strcmp(inet_ntoa(rc.client_addr.sin_addr), options.client_address) != 0)) {
......@@ -396,11 +404,13 @@ void serve(void) {
#else
if (options.fork) {
if (fork() == 0) {
if (options.log)
printf("forking ...\n");
close(rc.server_socket);
run();
exit(0);
}
close(rc.client_socket);
//close(rc.client_socket);
}
else {
run();
......@@ -558,10 +568,10 @@ void check_options() {
}
/* Consistency checkss */
if (options.proto == SOCK_DGRAM && options.fork) {
printf("%s: %s\n", name, "option --fork is not supported with --proto=udp, ignored");
options.fork = 0;
}
// if (options.proto == SOCK_DGRAM && options.fork) {
// printf("%s: %s\n", name, "option --fork is not supported with --proto=udp, ignored");
// options.fork = 0;
// }
if (options.mode == MODE_SERVER && !options.stay_alive) {
printf("%s: %s\n", name, "option --stay-alive is switched on with --mode=server");
options.stay_alive = 0;
......@@ -638,6 +648,7 @@ int main(int argc, char *argv[]) {
printf(" remote: %s:%d\n", options.remote_host, options.remote_port);
printf(" mode: %s\n", options.mode == MODE_SERVER ? "server" : "client");
printf(" encrypt: %s\n", options.encrypt ? "yes" : "no");
printf(" fork: %s\n", options.fork ? "yes" : "no");
}
do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment