Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
libvncserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
libvncserver
Commits
7d1c1033
Commit
7d1c1033
authored
Aug 30, 2011
by
Gernot Tenchio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rfbssl_gnutls: Merge rfbssl_peek/rfbssl_read into one function
parent
b1671e6d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
53 deletions
+35
-53
rfbssl_gnutls.c
libvncserver/rfbssl_gnutls.c
+35
-53
No files found.
libvncserver/rfbssl_gnutls.c
View file @
7d1c1033
...
@@ -190,11 +190,8 @@ int rfbssl_write(rfbClientPtr cl, const char *buf, int bufsize)
...
@@ -190,11 +190,8 @@ int rfbssl_write(rfbClientPtr cl, const char *buf, int bufsize)
return
ret
;
return
ret
;
}
}
int
rfbssl_peek
(
rfbClientPtr
cl
,
char
*
buf
,
int
bufsize
)
static
void
rfbssl_gc_peekbuf
(
struct
rfbssl_ctx
*
ctx
,
int
bufsize
)
{
{
int
ret
=
-
1
;
struct
rfbssl_ctx
*
ctx
=
(
struct
rfbssl_ctx
*
)
cl
->
sslctx
;
if
(
ctx
->
peekstart
)
{
if
(
ctx
->
peekstart
)
{
int
spaceleft
=
sizeof
(
ctx
->
peekbuf
)
-
ctx
->
peeklen
-
ctx
->
peekstart
;
int
spaceleft
=
sizeof
(
ctx
->
peekbuf
)
-
ctx
->
peeklen
-
ctx
->
peekstart
;
if
(
spaceleft
<
bufsize
)
{
if
(
spaceleft
<
bufsize
)
{
...
@@ -202,70 +199,55 @@ int rfbssl_peek(rfbClientPtr cl, char *buf, int bufsize)
...
@@ -202,70 +199,55 @@ int rfbssl_peek(rfbClientPtr cl, char *buf, int bufsize)
ctx
->
peekstart
=
0
;
ctx
->
peekstart
=
0
;
}
}
}
}
/* If we have any peek data, simply return that. */
if
(
ctx
->
peeklen
)
{
if
(
bufsize
>
ctx
->
peeklen
)
{
/* more than we have, so we are trying to read the remaining
* bytes
**/
int
required
=
bufsize
-
ctx
->
peeklen
;
int
total
=
ctx
->
peekstart
+
ctx
->
peeklen
;
int
n
,
avail
=
sizeof
(
ctx
->
peekbuf
)
-
total
;
if
(
required
>
avail
)
required
=
avail
;
if
(
!
required
)
{
rfbErr
(
"%s: no space left
\n
"
,
__func__
);
}
else
if
((
n
=
rfbssl_do_read
(
cl
,
ctx
->
peekbuf
+
total
,
required
))
<
0
)
{
rfbErr
(
"%s: read error
\n
"
,
__func__
);
return
n
;
}
else
{
ctx
->
peeklen
+=
n
;
}
ret
=
ctx
->
peeklen
;
}
else
{
/* simply return what we have */
ret
=
bufsize
;
}
}
else
{
ret
=
bufsize
;
if
(
ret
>
sizeof
(
ctx
->
peekbuf
))
ret
=
sizeof
(
ctx
->
peekbuf
);
if
((
ret
=
rfbssl_do_read
(
cl
,
ctx
->
peekbuf
,
ret
))
>
0
)
ctx
->
peeklen
=
ret
;
}
if
(
ret
>=
0
)
{
memcpy
(
buf
,
ctx
->
peekbuf
+
ctx
->
peekstart
,
ret
);
}
return
ret
;
}
}
int
rfbssl_read
(
rfbClientPtr
cl
,
char
*
buf
,
int
bufsize
)
static
int
__rfbssl_read
(
rfbClientPtr
cl
,
char
*
buf
,
int
bufsize
,
int
peek
)
{
{
int
ret
;
int
ret
=
0
;
struct
rfbssl_ctx
*
ctx
=
(
struct
rfbssl_ctx
*
)
cl
->
sslctx
;
struct
rfbssl_ctx
*
ctx
=
(
struct
rfbssl_ctx
*
)
cl
->
sslctx
;
rfbssl_gc_peekbuf
(
ctx
,
bufsize
);
if
(
ctx
->
peeklen
)
{
if
(
ctx
->
peeklen
)
{
/* If we have any peek data, simply return that. */
/* If we have any peek data, simply return that. */
ret
=
bufsize
<
ctx
->
peeklen
?
bufsize
:
ctx
->
peeklen
;
ret
=
bufsize
<
ctx
->
peeklen
?
bufsize
:
ctx
->
peeklen
;
memcpy
(
buf
,
ctx
->
peekbuf
+
ctx
->
peekstart
,
ret
);
memcpy
(
buf
,
ctx
->
peekbuf
+
ctx
->
peekstart
,
ret
);
if
(
!
peek
)
{
ctx
->
peeklen
-=
ret
;
ctx
->
peeklen
-=
ret
;
if
(
ctx
->
peeklen
!=
0
)
if
(
ctx
->
peeklen
!=
0
)
ctx
->
peekstart
+=
ret
;
ctx
->
peekstart
+=
ret
;
else
else
ctx
->
peekstart
=
0
;
ctx
->
peekstart
=
0
;
}
else
{
}
ret
=
rfbssl_do_read
(
cl
,
buf
,
bufsize
);
}
if
(
ret
<
bufsize
)
{
int
n
;
/* read the remaining data */
if
((
n
=
rfbssl_do_read
(
cl
,
buf
+
ret
,
bufsize
-
ret
))
<=
0
)
{
rfbErr
(
"rfbssl_%s: %s error
\n
"
,
__func__
,
peek
?
"peek"
:
"read"
);
return
n
;
}
if
(
peek
)
{
memcpy
(
ctx
->
peekbuf
+
ctx
->
peekstart
+
ctx
->
peeklen
,
buf
+
ret
,
n
);
ctx
->
peeklen
+=
n
;
}
ret
+=
n
;
}
}
return
ret
;
return
ret
;
}
}
int
rfbssl_read
(
rfbClientPtr
cl
,
char
*
buf
,
int
bufsize
)
{
return
__rfbssl_read
(
cl
,
buf
,
bufsize
,
0
);
}
int
rfbssl_peek
(
rfbClientPtr
cl
,
char
*
buf
,
int
bufsize
)
{
return
__rfbssl_read
(
cl
,
buf
,
bufsize
,
1
);
}
int
rfbssl_pending
(
rfbClientPtr
cl
)
int
rfbssl_pending
(
rfbClientPtr
cl
)
{
{
struct
rfbssl_ctx
*
ctx
=
(
struct
rfbssl_ctx
*
)
cl
->
sslctx
;
struct
rfbssl_ctx
*
ctx
=
(
struct
rfbssl_ctx
*
)
cl
->
sslctx
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment