aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-09-24 04:17:57 -0400
committersotech117 <michael_foiani@brown.edu>2023-09-24 04:17:57 -0400
commit0e34f9ce017d0a9afc2b2354854a0e76019a86ec (patch)
tree284ad75e920e70798109f46545a3783e78396442
parent28d4aacf00d6b7389dd2440060541a623ec25f1d (diff)
fix for stations with lots of stations
-rw-r--r--client.c14
-rw-r--r--protocol.h2
-rw-r--r--server.c18
-rwxr-xr-xsnowcast_controlbin35245 -> 35277 bytes
-rwxr-xr-xsnowcast_serverbin71596 -> 71644 bytes
5 files changed, 22 insertions, 12 deletions
diff --git a/client.c b/client.c
index 4ab7457..7b9e036 100644
--- a/client.c
+++ b/client.c
@@ -174,16 +174,20 @@ int main(int argc, char *argv[])
}
else if (reply_type == 6) { // we are getting STATIONINFO
// get the string size
- uint8_t string_size = -1;
- if (recv(sockfd, &string_size, 1, 0) == -1) {
- perror("recv in stationinfo");
+ uint32_t buf_string_size = -1;
+ int bytes_to_read = sizeof(uint32_t);
+ if (recv_all(sockfd, &buf_string_size, &bytes_to_read) == -1) {
+ perror("recv_all 1 in stationinfo");
exit(1);
}
+
+ uint32_t string_size = ntohl(buf_string_size);
+ printf("string size: %d\n", string_size);
char *info = malloc(string_size);
if(info == NULL) { perror("malloc in info"); }
- int bytes_to_read = string_size;
+ bytes_to_read = string_size;
if (recv_all(sockfd, info, &bytes_to_read) == -1) {
- perror("recv_all in station info");
+ perror("recv_all 2 in stationinfo");
exit(1);
}
remove_timeout(sockfd);
diff --git a/protocol.h b/protocol.h
index 2b48ef4..d4f7b2a 100644
--- a/protocol.h
+++ b/protocol.h
@@ -35,7 +35,7 @@ struct InvalidCommand {
struct StationInfo {
uint8_t replyType; // 6
- uint8_t infoStringSize;
+ uint32_t infoStringSize;
char *infoString;
} __attribute__((packed));
diff --git a/server.c b/server.c
index dd08599..d5ca55f 100644
--- a/server.c
+++ b/server.c
@@ -806,7 +806,7 @@ void *send_stationsinfo_reply(void * arg) {
if (l) printf("sending STATIONSINFO reply to socket %d\n", fd);
- uint8_t reply_size = 0;
+ uint32_t reply_size = 0;
for (int i = 0; i < num_stations; i++) {
if (stations[i].readfd != -1)
reply_size += snprintf(NULL, 0, "%d,%s\n", i, stations[i].filePath);
@@ -817,20 +817,26 @@ void *send_stationsinfo_reply(void * arg) {
uint8_t reply_num = 6;
if (send(fd, &reply_num, 1, 0) == -1)
perror("send in send stations info");
+
// send payload size
- if (send(fd, &reply_size, 1, 0) == -1)
- perror("send in send stations info");
+ uint32_t reply_size_endian = htonl(reply_size);
+ int bytes = sizeof(uint32_t);
+ if (send_all(fd, &reply_size_endian, &bytes) == -1)
+ perror("send_all in send stations info");
+
+
+
+ printf("SENT reply size: %d\n", reply_size);
char send_buffer[reply_size];
int ptr = 0;
for (int i = 0; i < num_stations; i++) {
- if (stations[i].readfd != -1)
- ptr += sprintf(send_buffer + ptr, (i == num_stations - 1) ? "%d,%s" : "%d,%s\n", i, stations[i].filePath);
+ ptr += sprintf(send_buffer + ptr, "%d,%s\n", i, stations[i].filePath);
}
int bytes_to_send = reply_size; // don't want final \n
if (send_all(fd, &send_buffer, &bytes_to_send) == -1)
- perror("send_all");
+ perror("send_all buffer");
return (NULL);
}
diff --git a/snowcast_control b/snowcast_control
index 163b0f5..8a8a2ce 100755
--- a/snowcast_control
+++ b/snowcast_control
Binary files differ
diff --git a/snowcast_server b/snowcast_server
index 0f39e68..ab6cf33 100755
--- a/snowcast_server
+++ b/snowcast_server
Binary files differ