Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
07750492
Commit
07750492
authored
3 years ago
by
David Bühler
Browse files
Options
Downloads
Patches
Plain Diff
[server] Improves the stopping condition of functions [send_bytes].
parent
357fb3b1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/plugins/server/server_socket.ml
+31
-33
31 additions, 33 deletions
src/plugins/server/server_socket.ml
with
31 additions
and
33 deletions
src/plugins/server/server_socket.ml
+
31
−
33
View file @
07750492
...
...
@@ -67,43 +67,41 @@ type channel = {
}
let
read_bytes
{
sock
;
rcv
;
brcv
}
=
begin
(* rcv buffer is only used locally *)
let
s
=
Bytes
.
length
rcv
in
let
rec
scan
p
=
(* try to fill RCV buffer *)
if
p
<
s
then
let
n
=
try
Unix
.
read
sock
rcv
p
(
s
-
p
)
with
Unix
.
Unix_error
((
EAGAIN
|
EWOULDBLOCK
)
,_,_
)
->
0
in
if
n
>
0
then
scan
(
p
+
n
)
else
p
else
p
(* rcv buffer is only used locally *)
let
s
=
Bytes
.
length
rcv
in
let
rec
scan
p
=
(* try to fill RCV buffer *)
let
n
=
try
Unix
.
read
sock
rcv
p
(
s
-
p
)
with
Unix
.
Unix_error
((
EAGAIN
|
EWOULDBLOCK
)
,_,_
)
->
0
in
let
n
=
scan
0
in
if
n
>
0
then
Buffer
.
add_subbytes
brcv
rcv
0
n
end
let
p
=
p
+
n
in
if
n
>
0
&&
p
<
s
then
scan
p
else
p
in
let
n
=
scan
0
in
if
n
>
0
then
Buffer
.
add_subbytes
brcv
rcv
0
n
let
send_bytes
{
sock
;
snd
;
bsnd
}
=
begin
(* snd buffer is only used locally *)
let
n
=
Buffer
.
length
bsnd
in
if
n
>
0
then
let
s
=
Bytes
.
length
snd
in
let
rec
send
p
=
(* try to flush BSND buffer *)
let
w
=
min
(
n
-
p
)
s
in
Buffer
.
blit
bsnd
p
snd
0
w
;
let
r
=
try
Unix
.
single_write
sock
snd
0
w
with
Unix
.
Unix_error
((
EAGAIN
|
EWOULDBLOCK
)
,_,_
)
->
0
in
if
r
>
0
then
send
(
p
+
r
)
else
p
(* snd buffer is only used locally *)
let
n
=
Buffer
.
length
bsnd
in
if
n
>
0
then
let
s
=
Bytes
.
length
snd
in
let
rec
send
p
=
(* try to flush BSND buffer *)
let
w
=
min
(
n
-
p
)
s
in
Buffer
.
blit
bsnd
p
snd
0
w
;
let
r
=
try
Unix
.
single_write
sock
snd
0
w
with
Unix
.
Unix_error
((
EAGAIN
|
EWOULDBLOCK
)
,_,_
)
->
0
in
let
p
=
send
0
in
if
p
>
0
then
let
tail
=
Buffer
.
sub
bsnd
p
(
n
-
p
)
in
Buffer
.
reset
bsnd
;
Buffer
.
add_string
bsnd
tail
end
let
p
=
p
+
r
in
if
r
>
0
&&
p
<
n
then
send
p
else
p
in
let
p
=
send
0
in
if
p
>
0
then
let
tail
=
Buffer
.
sub
bsnd
p
(
n
-
p
)
in
Buffer
.
reset
bsnd
;
Buffer
.
add_string
bsnd
tail
(* -------------------------------------------------------------------------- *)
(* --- Data Chunks Encoding --- *)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment