aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'server.c')
-rw-r--r--server.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/server.c b/server.c
index e6b4867..dd08599 100644
--- a/server.c
+++ b/server.c
@@ -807,8 +807,10 @@ void *send_stationsinfo_reply(void * arg) {
if (l) printf("sending STATIONSINFO reply to socket %d\n", fd);
uint8_t reply_size = 0;
- for (int i = 0; i < num_stations; i++)
- reply_size += snprintf(NULL, 0, "%d,%s\n", i, stations[i].filePath);
+ 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);
+ }
reply_size--; // don't want final \n
// send type
@@ -821,8 +823,10 @@ void *send_stationsinfo_reply(void * arg) {
char send_buffer[reply_size];
int ptr = 0;
- for (int i = 0; i < num_stations; i++)
+ 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);
+ }
int bytes_to_send = reply_size; // don't want final \n
if (send_all(fd, &send_buffer, &bytes_to_send) == -1)