Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Joshua
wendelin.core
Commits
323ba50c
Commit
323ba50c
authored
Mar 10, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
97befba7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
49 deletions
+54
-49
wcfs/client/wcfs_watchlink.cpp
wcfs/client/wcfs_watchlink.cpp
+54
-49
No files found.
wcfs/client/wcfs_watchlink.cpp
View file @
323ba50c
...
...
@@ -211,6 +211,60 @@ error _WatchLink::_serveRX(context::Context ctx) {
}
}
// recvReq receives client <- server request.
//
// it returns EOF when server closes the link.
static
error
_parsePinReq
(
PinReq
*
pin
,
const
rxPkt
*
pkt
);
error
_WatchLink
::
recvReq
(
context
::
Context
ctx
,
PinReq
*
prx
)
{
_WatchLink
&
wlink
=
*
this
;
xerr
::
Contextf
E
(
"%s: recvReq"
,
v
(
wlink
));
rxPkt
pkt
;
bool
ok
;
int
_
=
select
({
ctx
->
done
().
recvs
(),
// 0
wlink
.
_acceptq
.
recvs
(
&
pkt
,
&
ok
),
// 1
});
if
(
_
==
0
)
return
E
(
ctx
->
err
());
if
(
!
ok
)
return
io
::
EOF_
;
// NOTE EOF goes without E
return
E
(
_parsePinReq
(
prx
,
&
pkt
));
}
// replyReq sends reply to client <- server request received by recvReq.
error
_WatchLink
::
replyReq
(
context
::
Context
ctx
,
const
PinReq
*
req
,
const
string
&
answer
)
{
_WatchLink
&
wlink
=
*
this
;
xerr
::
Contextf
E
(
"%s: replyReq .%d"
,
v
(
wlink
),
req
->
stream
);
//print('C: reply %s <- %r ...' % (req, answer))
wlink
.
_rxmu
.
lock
();
bool
ok
=
wlink
.
_accepted
.
has
(
req
->
stream
);
wlink
.
_rxmu
.
unlock
();
if
(
!
ok
)
panic
(
"reply to not accepted stream"
);
error
err
=
wlink
.
_send
(
req
->
stream
,
answer
);
wlink
.
_rxmu
.
lock
();
ok
=
wlink
.
_accepted
.
has
(
req
->
stream
);
if
(
ok
)
wlink
.
_accepted
.
erase
(
req
->
stream
);
wlink
.
_rxmu
.
unlock
();
if
(
!
ok
)
panic
(
"BUG: stream vanished from wlink._accepted while reply was in progress"
);
// TODO also track as answered? (and don't accept with the same ID ?)
return
E
(
err
);
}
// _send sends raw message via specified stream.
//
// multiple _send can be called in parallel - _send serializes writes.
...
...
@@ -322,55 +376,6 @@ tuple</*rxq*/chan<rxPkt>, error> _WatchLink::_sendReq(context::Context ctx, cons
return
make_tuple
(
rxq
,
err
);
}
// replyReq sends reply to client <- server request received by recvReq.
error
_WatchLink
::
replyReq
(
context
::
Context
ctx
,
const
PinReq
*
req
,
const
string
&
answer
)
{
_WatchLink
&
wlink
=
*
this
;
xerr
::
Contextf
E
(
"%s: replyReq .%d"
,
v
(
wlink
),
req
->
stream
);
//print('C: reply %s <- %r ...' % (req, answer))
wlink
.
_rxmu
.
lock
();
bool
ok
=
wlink
.
_accepted
.
has
(
req
->
stream
);
wlink
.
_rxmu
.
unlock
();
if
(
!
ok
)
panic
(
"reply to not accepted stream"
);
error
err
=
wlink
.
_send
(
req
->
stream
,
answer
);
wlink
.
_rxmu
.
lock
();
ok
=
wlink
.
_accepted
.
has
(
req
->
stream
);
if
(
ok
)
wlink
.
_accepted
.
erase
(
req
->
stream
);
wlink
.
_rxmu
.
unlock
();
if
(
!
ok
)
panic
(
"BUG: stream vanished from wlink._accepted while reply was in progress"
);
// TODO also track as answered? (and don't accept with the same ID ?)
return
E
(
err
);
}
// recvReq receives client <- server request.
//
// it returns EOF when server closes the link.
static
error
_parsePinReq
(
PinReq
*
pin
,
const
rxPkt
*
pkt
);
error
_WatchLink
::
recvReq
(
context
::
Context
ctx
,
PinReq
*
prx
)
{
_WatchLink
&
wlink
=
*
this
;
xerr
::
Contextf
E
(
"%s: recvReq"
,
v
(
wlink
));
rxPkt
pkt
;
bool
ok
;
int
_
=
select
({
ctx
->
done
().
recvs
(),
// 0
wlink
.
_acceptq
.
recvs
(
&
pkt
,
&
ok
),
// 1
});
if
(
_
==
0
)
return
E
(
ctx
->
err
());
if
(
!
ok
)
return
io
::
EOF_
;
// NOTE EOF goes without E
return
E
(
_parsePinReq
(
prx
,
&
pkt
));
}
// _parsePinReq parses message into PinReq according to wcfs isolation protocol.
static
error
_parsePinReq
(
PinReq
*
pin
,
const
rxPkt
*
pkt
)
{
...
...
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