VNC: Enable receive timeouts during negotiation phase
This commit is contained in:
parent
1ae24ddf77
commit
fdc6dd9516
@ -45,6 +45,10 @@
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_NET_SOCKOPTS
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
#include <nuttx/video/rfb.h>
|
||||
|
||||
@ -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);
|
||||
|
@ -43,6 +43,10 @@
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_NET_SOCKOPTS
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/video/rfb.h>
|
||||
|
||||
@ -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 (; ; )
|
||||
|
Loading…
Reference in New Issue
Block a user