From 3ca5a945151f9fa59773978a8fac404ea008e2f1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 17 Apr 2016 09:17:37 -0600 Subject: [PATCH] VNC: Add basic message receipt logic --- graphics/vnc/server/Kconfig | 1 + graphics/vnc/server/vnc_negotiate.c | 2 +- graphics/vnc/server/vnc_receiver.c | 63 +++++++++++++++++++++++++++++ net/socket/recvfrom.c | 2 +- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/graphics/vnc/server/Kconfig b/graphics/vnc/server/Kconfig index f688da3ab1..74319591ef 100644 --- a/graphics/vnc/server/Kconfig +++ b/graphics/vnc/server/Kconfig @@ -7,6 +7,7 @@ menuconfig VNCSERVER bool "VNC server" default n depends on NET_TCP && !NX_LCDDRIVER && EXPERIMENTAL + select NET_TCP_READAHEAD ---help--- Enable support for a VNC Remote Frame Buffer (RFB) server. diff --git a/graphics/vnc/server/vnc_negotiate.c b/graphics/vnc/server/vnc_negotiate.c index 44f1d8c312..39b9681e69 100644 --- a/graphics/vnc/server/vnc_negotiate.c +++ b/graphics/vnc/server/vnc_negotiate.c @@ -109,7 +109,7 @@ int vnc_negotiate(FAR struct vnc_session_s *session) /* Receive the echo of the protocol string */ nrecvd = psock_recv(&session->connect, session->inbuf, len, 0); - if (nrecvd <= 0) + if (nrecvd < 0) { errcode = get_errno(); gdbg("ERROR: Receive protocol confirmation failed: %d\n", errcode); diff --git a/graphics/vnc/server/vnc_receiver.c b/graphics/vnc/server/vnc_receiver.c index f8c9e47e1e..d84f05ba03 100644 --- a/graphics/vnc/server/vnc_receiver.c +++ b/graphics/vnc/server/vnc_receiver.c @@ -39,7 +39,12 @@ #include +#include #include +#include + +#include +#include #include "vnc_server.h" @@ -67,6 +72,64 @@ int vnc_receiver(FAR struct vnc_session_s *session) { + ssize_t nrecvd; + int errcode; + + /* Loop until the client disconnects or an unhandled error occurs */ + + for (; ; ) + { + /* Set up to read one byte which should be the message type of the + * next Client-to-Server message. We will block here until the message + * is received. + */ + + nrecvd = psock_recv(&session->connect, session->inbuf, 1, 0); + if (nrecvd < 0) + { + errcode = get_errno(); + gdbg("ERROR: Receive byte failed: %d\n", errcode); + DEBUGASSERT(errcode > 0); + return -errcode; + } + + DEBUGASSERT(nrecvd == 1); + + /* The single byte received should be the message type. Handle the + * message according to this message type. + */ + + switch (session->inbuf[0]) + { + case RFB_SETPIXELFMT_MSG: /* SetPixelFormat */ #warning Missing logic + break; + + case RFB_SETENCODINGS_MSG: /* SetEncodings */ +#warning Missing logic + break; + + case RFB_FBUPDATEREQ_MSG: /* FramebufferUpdateRequest */ +#warning Missing logic + break; + + case RFB_KEYEVENT_MSG: /* KeyEvent */ +#warning Missing logic + break; + + case RFB_POINTEREVENT_MSG: /* PointerEvent */ +#warning Missing logic + break; + + case RFB_CLIENTCUTTEXT_MSG: /* ClientCutText */ +#warning Missing logic + break; + + default: + gdbg("ERROR: Unsynchronized, msgtype=%d\n", session->inbuf[0]); + return -EPROTO; + } + } + return -ENOSYS; } diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index a6921315fd..0125975393 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -261,7 +261,7 @@ static inline void recvfrom_newtcpdata(FAR struct net_driver_s *dev, size_t recvlen = recvfrom_newdata(dev, pstate); - /* If there is more data left in the packet that we could not buffer, than + /* If there is more data left in the packet that we could not buffer, then * add it to the read-ahead buffers. */