aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c18
1 files changed, 12 insertions, 6 deletions
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);
}