diff options
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | c | bin | 34446 -> 35150 bytes | |||
-rw-r--r-- | c.dSYM/Contents/Info.plist | 20 | ||||
-rw-r--r-- | c.dSYM/Contents/Resources/DWARF/c | bin | 0 -> 13761 bytes | |||
-rw-r--r-- | client.c | 42 | ||||
-rwxr-xr-x | l | bin | 34254 -> 34654 bytes | |||
-rw-r--r-- | l.dSYM/Contents/Info.plist | 20 | ||||
-rw-r--r-- | l.dSYM/Contents/Resources/DWARF/l | bin | 0 -> 11745 bytes | |||
-rwxr-xr-x | s | bin | 52974 -> 54558 bytes | |||
-rw-r--r-- | s.dSYM/Contents/Info.plist | 20 | ||||
-rw-r--r-- | s.dSYM/Contents/Resources/DWARF/s | bin | 0 -> 21520 bytes | |||
-rwxr-xr-x | snowcast_control | bin | 34461 -> 20992 bytes | |||
-rwxr-xr-x | snowcast_server | bin | 34636 -> 25336 bytes | |||
-rw-r--r-- | snowcast_server_concurrent.c | 42 |
14 files changed, 138 insertions, 8 deletions
@@ -1,6 +1,6 @@ CC = gcc # CFLAGS = -std=c99 -target x86_64-apple-darwin20 -g -# CFLAGS = -std=c99 -Wall -g +CFLAGS = -g -I. -std=gnu99 -Wall -pthread default: all diff --git a/c.dSYM/Contents/Info.plist b/c.dSYM/Contents/Info.plist new file mode 100644 index 0000000..ceced96 --- /dev/null +++ b/c.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleIdentifier</key> + <string>com.apple.xcode.dsym.c</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>dSYM</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + </dict> +</plist> diff --git a/c.dSYM/Contents/Resources/DWARF/c b/c.dSYM/Contents/Resources/DWARF/c Binary files differnew file mode 100644 index 0000000..c325e9f --- /dev/null +++ b/c.dSYM/Contents/Resources/DWARF/c @@ -12,6 +12,7 @@ #include <netinet/in.h> #include <sys/socket.h> #include <ctype.h> +#include <pthread.h> #include <arpa/inet.h> @@ -22,6 +23,7 @@ #define MAX_READ_SIZE 1024 #define LINE_MAX 1024 +void *reply_thread_routine(void *args); // get sockaddr, IPv4 or IPv6: void *get_in_addr(struct sockaddr *sa) @@ -105,6 +107,9 @@ int main(int argc, char *argv[]) exit(1); } + pthread_t reply_thread; + pthread_create(&reply_thread, NULL, reply_thread_routine, (void*)sockfd); + char input[LINE_MAX]; printf("Enter a number to change to it's station. Click q to end stream.\n"); while (1) { @@ -133,4 +138,41 @@ int main(int argc, char *argv[]) } return 0; +} + +void *reply_thread_routine(void* args) { + int sockfd = (int)args; + int recvbytes; + char buf[MAX_READ_SIZE]; + while (1) { + // recv the message, check for errors too + if ((recvbytes = recv(sockfd, &buf, MAX_READ_SIZE, 0)) == -1) { + perror("recv"); + exit(1); + } + buf[recvbytes] = '\0'; + printf("client: received %d bytes on a reply call \n", recvbytes); + // print the two first field of the call + printf("client: replyType: %d, stringSize: %d\n", buf[0], buf[1]); + // print the while buffer by char + for (int i = 0; i < recvbytes; i++) { + printf("%d", buf[i]); + } + + struct Reply reply; + memcpy(&reply, buf, sizeof(struct Reply)); + + if (reply.replyType == 3) { + printf("client: received an announce message\n"); + + continue; + } else if (reply.replyType == 4) { + printf("client: received an invalid command message\n"); + + continue; + } + printf("client: received an unknown message\n"); + + memset(buf, 0, MAX_READ_SIZE); + } }
\ No newline at end of file Binary files differdiff --git a/l.dSYM/Contents/Info.plist b/l.dSYM/Contents/Info.plist new file mode 100644 index 0000000..7025c85 --- /dev/null +++ b/l.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleIdentifier</key> + <string>com.apple.xcode.dsym.l</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>dSYM</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + </dict> +</plist> diff --git a/l.dSYM/Contents/Resources/DWARF/l b/l.dSYM/Contents/Resources/DWARF/l Binary files differBinary files differnew file mode 100644 index 0000000..9843052 --- /dev/null +++ b/l.dSYM/Contents/Resources/DWARF/l diff --git a/s.dSYM/Contents/Info.plist b/s.dSYM/Contents/Info.plist new file mode 100644 index 0000000..9ce500c --- /dev/null +++ b/s.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> + <dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleIdentifier</key> + <string>com.apple.xcode.dsym.s</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundlePackageType</key> + <string>dSYM</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleVersion</key> + <string>1</string> + </dict> +</plist> diff --git a/s.dSYM/Contents/Resources/DWARF/s b/s.dSYM/Contents/Resources/DWARF/s Binary files differnew file mode 100644 index 0000000..09cab17 --- /dev/null +++ b/s.dSYM/Contents/Resources/DWARF/s diff --git a/snowcast_control b/snowcast_control Binary files differindex 1b879ff..24fe551 100755 --- a/snowcast_control +++ b/snowcast_control diff --git a/snowcast_server b/snowcast_server Binary files differindex bf1801b..8a4c1cc 100755 --- a/snowcast_server +++ b/snowcast_server diff --git a/snowcast_server_concurrent.c b/snowcast_server_concurrent.c index e09e398..4387407 100644 --- a/snowcast_server_concurrent.c +++ b/snowcast_server_concurrent.c @@ -62,7 +62,7 @@ void destroy_user(int sockfd); // void *load_file(void* arg); -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { // threads to control reading files at chunks while the other threads sleep // station_data = malloc(sizeof(station_t) * NUM_STATIONS); @@ -165,7 +165,7 @@ void *send_udp_packet_routine(void *arg) { if (error_code = getaddrinfo(NULL, port, &thread_hints, &thread_servinfo) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error_code)); - return 1; + return (NULL); } free(port); @@ -203,7 +203,7 @@ void *send_udp_packet_routine(void *arg) { if (!did_work) { // sendto a random string of data to the user - int station_num = user_data[user_index].stationNum - 1; + int station_num = user_data[user_index].stationNum; char *data = station_data[station_num].filePath; printf("load data: thread %d \n", user_index); int numbytes; @@ -374,10 +374,38 @@ void *select_thread(void *arg) { update_user_udpPort(i, ntohs(command.number)); } else if (command.commandType == 1) { - // setStation command for the user - printf("TODO: set station to %d\n", ntohs(command.number)); + int station_num = ntohs(command.number); + printf("setting station to %d\n", ntohs(command.number)); // update station of user update_user_station(i, ntohs(command.number)); + + const char* song_name = station_data[station_num].filePath; + size_t song_name_size = strlen(song_name); // don't add 1, don't want to include the null terminator + struct Announce *announce = malloc(sizeof *announce + song_name_size); + + printf("song_name: %s\n", song_name); + + announce->replyType = 3; + announce->songnameSize = song_name_size; + + announce->songname = malloc(song_name_size); + memcpy(announce->songname, song_name, song_name_size); + + // print out all fields on announce on one line + printf("announce: %d %d %s\n", announce->replyType, announce->songnameSize, announce->songname); + + char* send_buffer[sizeof(struct Announce) + song_name_size]; + memcpy(send_buffer, announce, sizeof(struct Announce)); + memcpy(send_buffer+sizeof(struct Announce), song_name, song_name_size); + + int bytessent; + if ((bytessent = send(newfd, send_buffer, sizeof(struct Announce) + song_name_size, 0)) == -1) + perror("send"); + // print the number of bytes sent + printf("sent %d bytes\n", bytessent); + + free(announce->songname); + free(announce); } else { // send back in invalid command @@ -410,9 +438,9 @@ void *init_user(int sockfd) { // this is to save memory space. // in general, the displacement of 4 is where a user "used to be" int user_index = max_active_users++; - if(user_data[sockfd-4].sockfd == -1) { + if(user_data[(sockfd-4)/2].sockfd == -1) { printf("reusing memory\n"); - user_index = sockfd - 4; + user_index = (sockfd - 4)/2; } else { printf("making new memory\n"); // have to make more memory |