diff --git a/graphics/vnc/server/vnc_negotiate.c b/graphics/vnc/server/vnc_negotiate.c index 7c229814cbc..fd294f451ae 100644 --- a/graphics/vnc/server/vnc_negotiate.c +++ b/graphics/vnc/server/vnc_negotiate.c @@ -45,6 +45,10 @@ #include #include +#ifdef CONFIG_NET_SOCKOPTS +# include +#endif + #include #include @@ -92,6 +96,27 @@ int vnc_negotiate(FAR struct vnc_session_s *session) size_t len; int errcode; +#ifdef CONFIG_NET_SOCKOPTS + struct timeval tv; + int ret; + + /* Set a receive timeout so that we don't hang if the client does not + * respond according to RFB 3.3 protocol. + */ + + tv.tv_sec = 5; + tv.tv_usec = 0; + ret = psock_setsockopt(&session->connect, SOL_SOCKET, SO_RCVTIMEO, + &tv, sizeof(struct timeval)); + if (ret < 0) + { + errcode = get_errno(); + gdbg("ERROR: Failed to set receive timeout: %d\n", errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } +#endif + /* Inform the client of the VNC protocol version */ gvdbg("Send protocol version: %s\n", g_vncproto); @@ -302,6 +327,27 @@ int vnc_negotiate(FAR struct vnc_session_s *session) ssize_t nrecvd; size_t len; +#ifdef CONFIG_NET_SOCKOPTS + struct timeval tv; + int ret; + + /* Set a receive timeout so that we don't hang if the client does not + * respond according to RFB 3.3 protocol. + */ + + tv.tv_sec = 5; + tv.tv_usec = 0; + ret = psock_setsockopt(&session->connect, SOL_SOCKET, SO_RCVTIMEO, + &tv, sizeof(struct timeval)); + if (ret < 0) + { + errcode = get_errno(); + gdbg("ERROR: Failed to set receive timeout: %d\n", errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } +#endif + /* Inform the client of the VNC protocol version */ len = strlen(g_vncproto); diff --git a/graphics/vnc/server/vnc_receiver.c b/graphics/vnc/server/vnc_receiver.c index a74fc1a68d6..9bb2c34a906 100644 --- a/graphics/vnc/server/vnc_receiver.c +++ b/graphics/vnc/server/vnc_receiver.c @@ -43,6 +43,10 @@ #include #include +#ifdef CONFIG_NET_SOCKOPTS +# include +#endif + #include #include @@ -115,6 +119,9 @@ int vnc_read_remainder(FAR struct vnc_session_s *session, size_t msglen, int vnc_receiver(FAR struct vnc_session_s *session) { +#ifdef CONFIG_NET_SOCKOPTS + struct timeval tv; +#endif ssize_t nrecvd; int errcode; int ret; @@ -122,6 +129,24 @@ int vnc_receiver(FAR struct vnc_session_s *session) DEBUGASSERT(session); gvdbg("Receiver running for Display %d\n", session->display); +#ifdef CONFIG_NET_SOCKOPTS + /* Disable the receive timeout so that we will wait indefinitely for the + * next Client-to-Server message. + */ + + tv.tv_sec = 0; + tv.tv_usec = 0; + ret = psock_setsockopt(&session->connect, SOL_SOCKET, SO_RCVTIMEO, + &tv, sizeof(struct timeval)); + if (ret < 0) + { + errcode = get_errno(); + gdbg("ERROR: Failed to disable receive timeout: %d\n", errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } +#endif + /* Loop until the client disconnects or an unhandled error occurs */ for (; ; )