Skip to content

Commit 4c9ba96

Browse files
committed
Cleanup: socket protocol: Set recive timeout in master
Otherwhise, master will hang forever if client doesn't send enough data
1 parent a5f8dd3 commit 4c9ba96

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/rtapi/uspace_rtapi_main.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,17 @@ static bool master_process_socket_command(int fd) {
556556
} else {
557557
int result;
558558
std::vector<std::string> args;
559+
560+
//Set timeout, so master doesn't hang forever
561+
struct timeval timeout;
562+
timeout.tv_sec = 10;
563+
timeout.tv_usec = 0;
564+
if (setsockopt(fd1, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0){
565+
rtapi_print_msg(RTAPI_MSG_ERR, "rtapi_app: setsockopt timeout failed: %s\n", strerror(errno));
566+
close(fd1);
567+
return true; //If there is a socket error, just continue
568+
}
569+
559570
if (!recv_args(fd1, args)) {
560571
rtapi_print_msg(RTAPI_MSG_ERR, "rtapi_app: failed to read from slave\n");
561572
close(fd1);

0 commit comments

Comments
 (0)