Skip to content

Commit c06e76c

Browse files
author
Volodymyr Samokhatko
committed
libvncserver/sockets: skip
1 parent 0e2a0d2 commit c06e76c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/libvncserver/sockets.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,34 @@ int rfbReadExact(rfbClientPtr cl,char* buf,int len)
794794
return(rfbReadExactTimeout(cl,buf,len,rfbMaxClientWait));
795795
}
796796

797+
inline static unsigned min(unsigned a, unsigned b)
798+
{
799+
return a > b ? b : a;
800+
}
801+
802+
/*
803+
* SkipExact reads an exact number of bytes on a TCP socket into a temporary
804+
* buffer and then discards them. Returns 1 on success, 0 if the other end has
805+
* closed, or -1 if an error occurred (errno is set to ETIMEDOUT if it timed
806+
* out).
807+
*/
808+
809+
int rfbSkipExact(rfbClientPtr cl, int len)
810+
{
811+
char *tmpbuf = NULL;
812+
int bufLen = min(len, 65536), i, retval = 1;
813+
814+
tmpbuf = (char *)malloc(bufLen);
815+
816+
for (i = 0; i < len; i += bufLen) {
817+
retval = rfbReadExact(cl, tmpbuf, min(bufLen, len - i));
818+
if (retval <= 0) break;
819+
}
820+
821+
free(tmpbuf);
822+
return retval;
823+
}
824+
797825
/*
798826
* PeekExact peeks at an exact number of bytes from a client. Returns 1 if
799827
* those bytes have been read, 0 if the other end has closed, or -1 if an

0 commit comments

Comments
 (0)