+static void dsi_tcp_timeout(DSI *dsi)
+{
+ struct timeval tv;
+ /* 2 seconds delay, most of the time it translates to 4 seconds:
+ * send/write returns first with whatever it has written and the
+ * second time it returns EAGAIN
+ */
+ tv.tv_sec = 2;
+ tv.tv_usec = 0;
+
+ /* Note: write isn't a restartable syscall if there's a timeout on the socket
+ * we have to test for EINTR
+ */
+ if (setsockopt(dsi->socket, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) < 0) {
+ LOG(log_error, logtype_default, "dsi_tcp_open: unable to set timeout %s", strerror(errno));
+ exit(EXITERR_CLNT);
+ }
+}
+