Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libfibre
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Zhaocheng Che
libfibre
Commits
ccf6937a
Commit
ccf6937a
authored
2 years ago
by
chezhaocheng ubuntu server
Browse files
Options
Downloads
Patches
Plain Diff
in debug
parent
830c5396
No related branches found
No related tags found
No related merge requests found
Pipeline
#63283
failed with stage
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
apps/echotest.cpp
+14
-4
14 additions, 4 deletions
apps/echotest.cpp
src/libfibre/EventScope.h
+11
-1
11 additions, 1 deletion
src/libfibre/EventScope.h
with
28 additions
and
5 deletions
.gitignore
+
3
−
0
View file @
ccf6937a
# Untracked Files
/tags
src/runtime/testoptions.h
src/runtime-glue/testoptions.h
# Untracked Directories
doc/html
This diff is collapsed.
Click to expand it.
apps/echotest.cpp
+
14
−
4
View file @
ccf6937a
...
...
@@ -47,7 +47,7 @@
* for a good description.
-----------------------------------------------------------------------------*/
static
const
int
numaccept
=
2
;
static
const
int
numaccept
=
1
;
static
bool
server
=
false
;
static
int
numconn
=
std
::
max
(
2
,
numaccept
);
...
...
@@ -73,6 +73,7 @@ static void opts(int argc, char** argv, sockaddr_in& addr) {
break
;
case
'c'
:
numconn
=
atoi
(
optarg
);
std
::
cout
<<
"numconn "
<<
numconn
<<
std
::
endl
;
break
;
case
'p'
:
addr
.
sin_port
=
htons
(
atoi
(
optarg
));
...
...
@@ -120,17 +121,21 @@ static void servconn(void* arg) {
}
finish
:
std
::
cout
<<
fd
<<
" finish recv 1"
<<
std
::
endl
;
// std::cout << ntohs(client.sin_port) << " done receiving" << std::endl;
// send response
SYSCALL_EQ
(
lfSend
(
fd
,
(
const
void
*
)
&
code
,
sizeof
(
code
),
0
),
sizeof
(
code
));
// std::cout << ntohs(client.sin_port) << " done sending" << std::endl;
std
::
cout
<<
fd
<<
" finish recv 2"
<<
std
::
endl
;
// wait for client closing the socket
SYSCALL_EQ
(
lfRecv
(
fd
,
(
void
*
)
&
code
,
sizeof
(
code
),
0
),
0
);
// std::cout << ntohs(client.sin_port) << " client closed" << std::endl;
std
::
cout
<<
fd
<<
" finish recv 3"
<<
std
::
endl
;
// close socket and terminate fibre
SYSCALL
(
lfClose
(
fd
));
std
::
cout
<<
fd
<<
" finish recv 4"
<<
std
::
endl
;
}
static
int
servFD
=
-
1
;
...
...
@@ -139,7 +144,9 @@ void servaccept() {
// create up to N connection handlers
Fibre
**
f
=
new
Fibre
*
[
numconn
/
numaccept
];
for
(
int
n
=
0
;
n
<
numconn
/
numaccept
;
n
+=
1
)
{
std
::
cout
<<
"tryAccept "
<<
std
::
endl
;
intptr_t
fd
=
SYSCALLIO
(
lfAccept
(
servFD
,
nullptr
,
nullptr
));
std
::
cout
<<
"lfAccept "
<<
fd
<<
std
::
endl
;
__atomic_add_fetch
(
&
acceptcount
,
1
,
__ATOMIC_RELAXED
);
if
(
acceptcount
==
pausecount
)
{
Context
::
CurrCluster
().
pause
();
...
...
@@ -173,6 +180,7 @@ void servaccept2(void*) {
void
servmain
(
sockaddr_in
&
addr
)
{
// create server socket
servFD
=
SYSCALLIO
(
lfSocket
(
AF_INET
,
SOCK_STREAM
,
0
));
std
::
cout
<<
"servFD created "
<<
servFD
<<
std
::
endl
;
int
on
=
1
;
SYSCALL
(
setsockopt
(
servFD
,
SOL_SOCKET
,
SO_REUSEADDR
,
(
const
void
*
)
&
on
,
sizeof
(
int
)));
...
...
@@ -184,7 +192,7 @@ void servmain(sockaddr_in& addr) {
SYSCALL
(
getsockname
(
servFD
,
(
sockaddr
*
)
&
addr
,
&
addrlen
));
std
::
cout
<<
"listening on "
<<
inet_ntoa
(
addr
.
sin_addr
)
<<
':'
<<
ntohs
(
addr
.
sin_port
)
<<
std
::
endl
;
SYSCALL
(
lfListen
(
servFD
,
numconn
));
std
::
cout
<<
"HERE"
<<
std
::
endl
;
{
Context
::
CurrCluster
().
addWorkers
(
2
);
Fibre
a1
(
Context
::
CurrCluster
(),
true
);
...
...
@@ -206,13 +214,14 @@ void servmain(sockaddr_in& addr) {
void
clientconn
(
sockaddr_in
*
server
)
{
// create client socket and connect to server
int
fd
=
SYSCALLIO
(
lfSocket
(
AF_INET
,
SOCK_STREAM
,
0
));
//
std::cout << "connecting to " << inet_ntoa(server->sin_addr) << ':' << ntohs(server->sin_port) << std::endl;
std
::
cout
<<
"connecting to "
<<
inet_ntoa
(
server
->
sin_addr
)
<<
':'
<<
ntohs
(
server
->
sin_port
)
<<
std
::
endl
;
SYSCALL
(
lfConnect
(
fd
,
(
sockaddr
*
)
server
,
sizeof
(
sockaddr_in
)));
std
::
cout
<<
"connected at "
<<
fd
<<
std
::
endl
;
struct
sockaddr_in
local
;
socklen_t
addrlen
=
sizeof
(
local
);
SYSCALL
(
getsockname
(
fd
,
(
sockaddr
*
)
&
local
,
&
addrlen
));
//
std::cout << "connected from " << inet_ntoa(local.sin_addr) << ':' << ntohs(local.sin_port) << std::endl;
std
::
cout
<<
"connected from "
<<
inet_ntoa
(
local
.
sin_addr
)
<<
':'
<<
ntohs
(
local
.
sin_port
)
<<
std
::
endl
;
char
code
=
0
;
int32_t
bcount
;
...
...
@@ -260,5 +269,6 @@ int main(int argc, char** argv) {
FibreInit
();
if
(
server
)
servmain
(
addr
);
else
clientmain
(
addr
);
std
::
cerr
<<
"FINISH"
<<
std
::
endl
;
return
0
;
}
This diff is collapsed.
Click to expand it.
src/libfibre/EventScope.h
+
11
−
1
View file @
ccf6937a
...
...
@@ -170,15 +170,18 @@ class EventScope {
#else
static
const
Poller
::
Variant
variant
=
Input
?
Poller
::
Edge
:
Poller
::
Oneshot
;
#endif
//std::cout << "First try start " << fd << std::endl;
#if TESTING_IO_TRYFIRST
if
(
Yield
)
Fibre
::
yield
();
if
(
tryIO
<
Input
>
(
ret
,
iofunc
,
fd
,
a
...))
return
ret
;
#else
if
(
!
Input
&&
tryIO
<
Input
>
(
ret
,
iofunc
,
fd
,
a
...))
return
ret
;
#endif
std
::
cout
<<
"First try fail "
<<
fd
<<
std
::
endl
;
BasePoller
*&
poller
=
fdSyncVector
[
fd
].
poller
[
Input
];
#if TESTING_EVENTPOLL_MEMO
if
(
Input
&&
!
poller
)
{
std
::
cout
<<
"syncIO getPoller "
<<
fd
<<
std
::
endl
;
poller
=
&
getPoller
<
Input
,
Cluster
>
(
fd
);
poller
->
setupFD
(
fd
,
static_cast
<
Poller
::
Operation
>
(
static_cast
<
int
>
(
Poller
::
Create
)
|
static_cast
<
int
>
(
Poller
::
Memo
)
...
...
@@ -193,8 +196,12 @@ class EventScope {
}
Poller
::
SyncSem
&
sync
=
fdSyncVector
[
fd
].
sync
[
Input
];
for
(;;)
{
std
::
cout
<<
"syncIO Wait "
<<
fd
<<
std
::
endl
;
if
(
variant
==
Poller
::
Level
)
sync
.
wait
();
else
sync
.
P
();
if
(
tryIO
<
Input
>
(
ret
,
iofunc
,
fd
,
a
...))
return
ret
;
std
::
cout
<<
"syncIO Wake "
<<
fd
<<
std
::
endl
;
if
(
tryIO
<
Input
>
(
ret
,
iofunc
,
fd
,
a
...))
// return ret;
{
// printf("Finish tryIO %d\n", fd);
return
ret
;}
#if TESTING_EVENTPOLL_MEMO
if
(
Input
)
{}
else
#endif
...
...
@@ -209,6 +216,7 @@ class EventScope {
fdsync
.
poller
[
false
]
=
&
getPoller
<
false
,
false
>
(
fd
);
fdsync
.
poller
[
false
]
->
setupFD
(
fd
,
Poller
::
Create
,
Poller
::
Output
,
Poller
::
Oneshot
);
// register immediately
fdsync
.
sync
[
false
].
P
();
// wait for completion
std
::
cout
<<
"checkAsyncCompletion Wake "
<<
std
::
endl
;
int
err
;
socklen_t
sz
=
sizeof
(
err
);
SYSCALL
(
getsockopt
(
fd
,
SOL_SOCKET
,
SO_ERROR
,
&
err
,
&
sz
));
...
...
@@ -440,6 +448,8 @@ public:
:
::
accept4
(
fd
,
addr
,
addrlen
,
flags
);
}
else
#endif
std
::
cout
<<
"lfAccept Invoked"
<<
std
::
endl
;
std
::
cout
<<
"accept4 is blocking ?"
<<
fdSyncVector
[
fd
].
blocking
<<
std
::
endl
;
ret
=
fdSyncVector
[
fd
].
blocking
?
syncIO
<
true
,
false
,
true
>
(
::
accept4
,
fd
,
addr
,
addrlen
,
flags
|
SOCK_NONBLOCK
)
:
::
accept4
(
fd
,
addr
,
addrlen
,
flags
|
SOCK_NONBLOCK
);
...
...
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