|
@@ -13,6 +13,7 @@
|
|
|
#include <string.h>
|
|
|
#include <netinet/in.h>
|
|
|
#include <time.h>
|
|
|
+#include <sys/time.h>
|
|
|
#include <syslog.h>
|
|
|
|
|
|
#include "tcpserver.h"
|
|
@@ -134,6 +135,10 @@ int main(int argc, char **argv) {
|
|
|
if (conn == -1) {
|
|
|
continue;
|
|
|
}
|
|
|
+ struct timeval tv;
|
|
|
+ tv.tv_sec = 3;
|
|
|
+ tv.tv_usec = 0;
|
|
|
+ setsockopt(conn, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv);
|
|
|
recv(conn, &sync, sizeof(sync), 0);
|
|
|
if (sync.sample_rate < 8000 || sync.sample_rate > 48000) {
|
|
|
syslog(LOG_ERR, "Invalid sample rate received\n");
|
|
@@ -151,11 +156,12 @@ int main(int argc, char **argv) {
|
|
|
close(conn);
|
|
|
continue;
|
|
|
}
|
|
|
- while ((bytes_received = recv(conn, buffer, BUF_SIZE, 0)) != 0) {
|
|
|
+ while ((bytes_received = recv(conn, buffer, BUF_SIZE, 0)) != -1) {
|
|
|
wavfile_append_data(file, buffer, bytes_received);
|
|
|
}
|
|
|
syslog(LOG_INFO, "closing file: %s\n", filepath);
|
|
|
wavfile_close(file);
|
|
|
+ close(conn);
|
|
|
file_closed = 1;
|
|
|
}
|
|
|
return EXIT_SUCCESS;
|