Skip to content

Commit

Permalink
libvncserver/sockets: skip
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr Samokhatko committed Mar 16, 2023
1 parent 0e2a0d2 commit c06e76c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/libvncserver/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,34 @@ int rfbReadExact(rfbClientPtr cl,char* buf,int len)
return(rfbReadExactTimeout(cl,buf,len,rfbMaxClientWait));
}

inline static unsigned min(unsigned a, unsigned b)
{
return a > b ? b : a;
}

/*
* SkipExact reads an exact number of bytes on a TCP socket into a temporary
* buffer and then discards them. Returns 1 on success, 0 if the other end has
* closed, or -1 if an error occurred (errno is set to ETIMEDOUT if it timed
* out).
*/

int rfbSkipExact(rfbClientPtr cl, int len)
{
char *tmpbuf = NULL;
int bufLen = min(len, 65536), i, retval = 1;

tmpbuf = (char *)malloc(bufLen);

for (i = 0; i < len; i += bufLen) {
retval = rfbReadExact(cl, tmpbuf, min(bufLen, len - i));
if (retval <= 0) break;
}

free(tmpbuf);
return retval;
}

/*
* PeekExact peeks at an exact number of bytes from a client. Returns 1 if
* those bytes have been read, 0 if the other end has closed, or -1 if an
Expand Down

0 comments on commit c06e76c

Please sign in to comment.