diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-23 23:37:22 +0000 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-23 23:37:22 +0000 |
commit | 759b0550996b251d1bf4ae64a6a6f5c2059d2479 (patch) | |
tree | 03534b77f9cfc7e78b0c477e9b2e9f7de5bf99a3 | |
parent | 5e3925610f1e9a1351c2b22cfa10b08385015b31 (diff) | |
parent | c2348702491e5ea65e64b1ab7d2f51c5bad1562b (diff) |
try some stuff, no avail
-rw-r--r-- | .gitattributes | 4 | ||||
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | client.c | 41 | ||||
-rwxr-xr-x | snowcast_control | bin | 35693 -> 18552 bytes | |||
-rwxr-xr-x | snowcast_listener | bin | 34654 -> 13656 bytes | |||
-rwxr-xr-x | snowcast_server | bin | 56748 -> 28720 bytes | |||
-rwxr-xr-x | util/run_tests | 8 | ||||
-rwxr-xr-x | util/snowcast-dissector/install.sh | 4 | ||||
-rwxr-xr-x | util/tester/arm64/control_tester | bin | 6742776 -> 6742776 bytes | |||
-rwxr-xr-x | util/tester/arm64/server_tester | bin | 6808312 -> 6808312 bytes | |||
-rwxr-xr-x | util/tester/control_tester | bin | 7031352 -> 7029336 bytes | |||
-rwxr-xr-x | util/tester/server_tester | bin | 7055960 -> 7053912 bytes |
12 files changed, 51 insertions, 22 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c3e4d96 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Force unix newlines on all platforms +util/update_from_stencil text eol=lf +util/run_tests text eol=lf +*.sh text eol=lf @@ -1,21 +1,17 @@ CC = gcc # CFLAGS = -std=c99 -target x86_64-apple-darwin20 -g -CFLAGS = -g -I. -std=gnu99 -Wall -pthread +# CFLAGS = -g -I. -std=gnu99 -Wall -pthread +CFLAGS = -o all: server client server: - $(CC) $(CFLAGS) -o snowcast_server server.c + $(CC) $(CFLAGS) snowcast_server server.c client: - $(CC) $(CFLAGS) -o snowcast_control client.c - $(CC) $(CFLAGS) -o snowcast_listener listener.c - -# new: -# $(CC) $(CFLAGS) -o s snowcast_server_concurrent.c -# $(CC) $(CFLAGS) -o l listener.c -# $(CC) $(CFLAGS) -o c client.c - + $(CC) $(CFLAGS) snowcast_control client.c + $(CC) $(CFLAGS) snowcast_listener listener.c + clean: rm -fv snowcast_control snowcast_listener snowcast_server @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) char s[INET6_ADDRSTRLEN]; if (argc != 4) { - fprintf(stderr,"<server IP> <server port> <listener port>\n"); + fprintf(stderr, "usage: <server IP> <server port> <listener port>\n"); exit(1); } @@ -92,7 +92,14 @@ int main(int argc, char *argv[]) pthread_t reply_thread; pthread_create(&reply_thread, NULL, reply_thread_routine, (void*)sockfd); - usleep(1000); + usleep(100); + + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = TIMEOUT; + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { + perror("setsockopt"); + } struct Hello hello; hello.commandType = 0; @@ -123,6 +130,11 @@ int main(int argc, char *argv[]) // printf("Changing to station %d.\n", inputInt); // send the command to change the station + tv.tv_sec = 0; + tv.tv_usec = TIMEOUT; + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { + perror("setsockopt"); + } struct SetStation setStation; setStation.commandType = 1; setStation.stationNumber = htons(inputInt); @@ -148,6 +160,8 @@ void *reply_thread_routine(void* args) { perror("recv"); exit(1); } + + fprintf(stderr, "reply_type: %d\n", reply_type); if (reply_type == 2) { // we have a welcome message // recv the message, check for errors too @@ -158,10 +172,16 @@ void *reply_thread_routine(void* args) { exit(1); } uint16_t num_stations = ntohs(buf_num_stations); - fflush(stdout); - printf("Click q to end stream.\n"); - printf("Welcome to Snowcast! The server has %u stations.\n", num_stations); - fflush(stdout); + fprintf(stdout, "Welcome to Snowcast! The server has %u stations.\n", num_stations); + fprintf(stderr, "Welcome to Snowcast! The server has %u stations.\n", num_stations); + // printf("Click q to end stream.\n"); + + struct timeval no_tv; + no_tv.tv_sec = 0; + no_tv.tv_usec = 0; + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &no_tv, sizeof(no_tv)) < 0) { + perror("setsockopt"); + } continue; } @@ -192,13 +212,22 @@ void *reply_thread_routine(void* args) { exit(1); } + printf("string size: %d\n", string_size); + char *message = malloc(string_size); if(message == NULL) { perror("malloc in message"); } if (recv_all(sockfd, message, &string_size) == -1) { perror("recv_all"); exit(1); } + struct timeval no_tv; + no_tv.tv_sec = 0; + no_tv.tv_usec = 0; + if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &no_tv, sizeof(no_tv)) < 0) { + perror("setsockopt"); + } printf("Invalid protocol: %s. Exiting.\n", message); + fprintf(stderr, "Invalid protocol: %s. Exiting.\n", message); free(message); close(sockfd); exit(1); diff --git a/snowcast_control b/snowcast_control Binary files differindex 8496be5..21e448c 100755 --- a/snowcast_control +++ b/snowcast_control diff --git a/snowcast_listener b/snowcast_listener Binary files differindex d399eb6..f27a5c1 100755 --- a/snowcast_listener +++ b/snowcast_listener diff --git a/snowcast_server b/snowcast_server Binary files differindex 104d93f..7516d88 100755 --- a/snowcast_server +++ b/snowcast_server diff --git a/util/run_tests b/util/run_tests index 4dbdf4b..64bbb1e 100755 --- a/util/run_tests +++ b/util/run_tests @@ -94,18 +94,18 @@ do_server() { } do_control() { - check_exists "${bin_dir}/snowcast_server" - run_tester server_tester $@ + check_exists "${bin_dir}/snowcast_control" + run_tester control_tester $@ } do_milestone() { - do_control -test.run="Test.+?/Test(ConnectsToServer|AcceptsClientConnection|CompletesHandshake)" + do_control -test.v -test.run="Test.+?/Test(ConnectsToServer|AcceptsClientConnection|CompletesHandshake)" || true do_server -test.v -test.run="Test.+?/Test(ConnectsToServer|AcceptsClientConnection|CompletesHandshake)" } do_all() { - do_server $@ + do_server $@ || true do_control $@ } diff --git a/util/snowcast-dissector/install.sh b/util/snowcast-dissector/install.sh index efd2341..caba8b6 100755 --- a/util/snowcast-dissector/install.sh +++ b/util/snowcast-dissector/install.sh @@ -7,8 +7,8 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) TARGET=~/.config/wireshark/plugins main() { - mkdir -pv ${TARGET} - install -v -m644 ${SCRIPT_DIR}/cs168_snowcast.lua ${TARGET} + mkdir -pv "${TARGET}" + install -v -m644 "${SCRIPT_DIR}/cs168_snowcast.lua" "${TARGET}" } main $@ diff --git a/util/tester/arm64/control_tester b/util/tester/arm64/control_tester Binary files differindex 5eebce7..ef56521 100755 --- a/util/tester/arm64/control_tester +++ b/util/tester/arm64/control_tester diff --git a/util/tester/arm64/server_tester b/util/tester/arm64/server_tester Binary files differindex 6694cfe..d900a1f 100755 --- a/util/tester/arm64/server_tester +++ b/util/tester/arm64/server_tester diff --git a/util/tester/control_tester b/util/tester/control_tester Binary files differindex 942e960..854d3c6 100755 --- a/util/tester/control_tester +++ b/util/tester/control_tester diff --git a/util/tester/server_tester b/util/tester/server_tester Binary files differindex 13063ec..7ea880c 100755 --- a/util/tester/server_tester +++ b/util/tester/server_tester |