VNC: Need to handle connection closed events

This commit is contained in:
Gregory Nutt 2016-04-23 10:57:28 -06:00
parent 47a33cbb64
commit 0d57612d13
4 changed files with 38 additions and 4 deletions

View File

@ -162,6 +162,11 @@ int vnc_negotiate(FAR struct vnc_session_s *session)
DEBUGASSERT(errcode > 0);
return -errcode;
}
else if (nrecvd == 0)
{
gdbg("Connection closed\n");
return -ECONNABORTED;
}
DEBUGASSERT(nrecvd == len);
@ -229,6 +234,11 @@ int vnc_negotiate(FAR struct vnc_session_s *session)
DEBUGASSERT(errcode > 0);
return -errcode;
}
else if (nrecvd == 0)
{
gdbg("Connection closed\n");
return -ECONNABORTED;
}
DEBUGASSERT(nrecvd == sizeof(struct rfb_selected_sectype_s));
@ -313,6 +323,11 @@ int vnc_negotiate(FAR struct vnc_session_s *session)
DEBUGASSERT(errcode > 0);
return -errcode;
}
else if (nrecvd == 0)
{
gdbg("Connection closed\n");
return -ECONNABORTED;
}
DEBUGASSERT(nrecvd == sizeof(struct rfb_clientinit_s));
@ -383,6 +398,11 @@ int vnc_negotiate(FAR struct vnc_session_s *session)
DEBUGASSERT(errcode > 0);
return -errcode;
}
else if (nrecvd == 0)
{
gdbg("Connection closed\n");
return -ECONNABORTED;
}
else if (nrecvd != sizeof(struct rfb_setpixelformat_s))
{
/* Must not be a SetPixelFormat message? */
@ -425,8 +445,13 @@ int vnc_negotiate(FAR struct vnc_session_s *session)
DEBUGASSERT(errcode > 0);
return -errcode;
}
else if (nrecvd == 0)
{
gdbg("Connection closed\n");
return -ECONNABORTED;
}
if (nrecvd > 0 && encodings->msgtype == RFB_SETENCODINGS_MSG)
if (encodings->msgtype == RFB_SETENCODINGS_MSG)
{
DEBUGASSERT(nrecvd >= SIZEOF_RFB_SETENCODINGS_S(0));

View File

@ -176,10 +176,16 @@ int vnc_receiver(FAR struct vnc_session_s *session)
return -errcode;
}
/* REVISIT: This assertion sometimes fires when there is a client
* disconnection.
/* A return value of zero means that the connection was gracefully
* closed by the VNC client.
*/
else if (nrecvd == 0)
{
gdbg("Connection closed\n", errcode);
return OK;
}
DEBUGASSERT(nrecvd == 1);
/* The single byte received should be the message type. Handle the

View File

@ -129,9 +129,11 @@ static void vnc_reset_session(FAR struct vnc_session_s *session,
sem_reset(&session->freesem, CONFIG_VNCSERVER_NUPDATES);
sem_reset(&session->queuesem, 0);
session->fb = fb;
session->display = display;
session->state = VNCSERVER_INITIALIZED;
session->change = true;
}
/****************************************************************************
@ -344,6 +346,7 @@ int vnc_server(int argc, FAR char *argv[])
ret = vnc_receiver(session);
gvdbg("Session terminated with %d\n", ret);
UNUSED(ret);
/* Stop the VNC updater thread. */

View File

@ -371,7 +371,7 @@ struct rfb_setencodings_s
{
uint8_t msgtype; /* U8 Message type */
uint8_t padding;
uint8_t nencodings[2]; /* U32 Number of encodings */
uint8_t nencodings[2]; /* U16 Number of encodings */
uint8_t encodings[4]; /* S32 Encoding type, size = 4*nencodings */
};