Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Tornax O7
relibc
Commits
43f1b582
Commit
43f1b582
authored
5 years ago
by
lmiskiew
Committed by
jD91mZM2
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use cbitset crate instead of custom bitset implementation in select
parent
e84ea94d
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/header/sys_select/mod.rs
+27
-48
27 additions, 48 deletions
src/header/sys_select/mod.rs
with
27 additions
and
48 deletions
src/header/sys_select/mod.rs
+
27
−
48
View file @
43f1b582
...
...
@@ -2,6 +2,8 @@
use
core
::
mem
;
use
cbitset
::
BitSet
;
use
fs
::
File
;
use
header
::
errno
;
use
header
::
sys_epoll
::{
epoll_create1
,
epoll_ctl
,
epoll_data
,
epoll_event
,
epoll_wait
,
EPOLLERR
,
...
...
@@ -13,45 +15,18 @@ use platform::types::*;
// fd_set is also defined in C because cbindgen is incompatible with mem::size_of booo
pub
const
FD_SETSIZE
:
usize
=
1024
;
type
bitset
=
BitSet
<
[
c_ulong
;
FD_SETSIZE
/
(
8
*
mem
::
size_of
::
<
c_ulong
>
())]
>
;
#[repr(C)]
pub
struct
fd_set
{
pub
fds_bits
:
[
c_ulong
;
FD_SETSIZE
/
(
8
*
mem
::
size_of
::
<
c_ulong
>
())],
}
impl
fd_set
{
fn
index
(
fd
:
c_int
)
->
usize
{
(
fd
as
usize
)
/
(
8
*
mem
::
size_of
::
<
c_ulong
>
())
}
fn
bitmask
(
fd
:
c_int
)
->
c_ulong
{
1
<<
((
fd
as
usize
)
&
(
8
*
mem
::
size_of
::
<
c_ulong
>
()
-
1
))
as
c_ulong
}
fn
zero
(
&
mut
self
)
{
for
i
in
0
..
self
.fds_bits
.len
()
{
self
.fds_bits
[
i
]
=
0
;
}
}
fn
set
(
&
mut
self
,
fd
:
c_int
)
{
self
.fds_bits
[
Self
::
index
(
fd
)]
|
=
Self
::
bitmask
(
fd
);
}
fn
clr
(
&
mut
self
,
fd
:
c_int
)
{
self
.fds_bits
[
Self
::
index
(
fd
)]
&=
!
Self
::
bitmask
(
fd
);
}
fn
isset
(
&
self
,
fd
:
c_int
)
->
bool
{
self
.fds_bits
[
Self
::
index
(
fd
)]
&
Self
::
bitmask
(
fd
)
>
0
}
pub
fds_bits
:
bitset
,
}
pub
fn
select_epoll
(
nfds
:
c_int
,
mut
readfds
:
Option
<&
mut
fd_set
>
,
mut
writefds
:
Option
<&
mut
fd_set
>
,
mut
exceptfds
:
Option
<&
mut
fd_set
>
,
readfds
:
Option
<&
mut
fd_set
>
,
writefds
:
Option
<&
mut
fd_set
>
,
exceptfds
:
Option
<&
mut
fd_set
>
,
timeout
:
Option
<&
mut
timeval
>
,
)
->
c_int
{
if
nfds
<
0
||
nfds
>
FD_SETSIZE
as
i32
{
...
...
@@ -67,11 +42,15 @@ pub fn select_epoll(
File
::
new
(
epfd
)
};
let
mut
read_bitset
:
Option
<&
mut
bitset
>
=
readfds
.map
(|
fd_set
|
&
mut
fd_set
.fds_bits
);
let
mut
write_bitset
:
Option
<&
mut
bitset
>
=
writefds
.map
(|
fd_set
|
&
mut
fd_set
.fds_bits
);
let
mut
except_bitset
:
Option
<&
mut
bitset
>
=
exceptfds
.map
(|
fd_set
|
&
mut
fd_set
.fds_bits
);
// Keep track of the number of file descriptors that do not support epoll
let
mut
not_epoll
=
0
;
for
fd
in
0
..
nfds
{
if
let
Some
(
ref
mut
fd_set
)
=
read
fds
{
if
fd_set
.
isset
(
fd
)
{
if
let
Some
(
ref
mut
fd_set
)
=
read
_bitset
{
if
fd_set
.
contains
(
fd
as
usize
)
{
let
mut
event
=
epoll_event
{
events
:
EPOLLIN
,
data
:
epoll_data
{
fd
},
...
...
@@ -84,12 +63,12 @@ pub fn select_epoll(
return
-
1
;
}
}
else
{
fd_set
.
clr
(
fd
);
fd_set
.
remove
(
fd
as
usize
);
}
}
}
if
let
Some
(
ref
mut
fd_set
)
=
write
fds
{
if
fd_set
.
isset
(
fd
)
{
if
let
Some
(
ref
mut
fd_set
)
=
write
_bitset
{
if
fd_set
.
contains
(
fd
as
usize
)
{
let
mut
event
=
epoll_event
{
events
:
EPOLLOUT
,
data
:
epoll_data
{
fd
},
...
...
@@ -102,12 +81,12 @@ pub fn select_epoll(
return
-
1
;
}
}
else
{
fd_set
.
clr
(
fd
);
fd_set
.
remove
(
fd
as
usize
);
}
}
}
if
let
Some
(
ref
mut
fd_set
)
=
except
fds
{
if
fd_set
.
isset
(
fd
)
{
if
let
Some
(
ref
mut
fd_set
)
=
except
_bitset
{
if
fd_set
.
contains
(
fd
as
usize
)
{
let
mut
event
=
epoll_event
{
events
:
EPOLLERR
,
data
:
epoll_data
{
fd
},
...
...
@@ -120,7 +99,7 @@ pub fn select_epoll(
return
-
1
;
}
}
else
{
fd_set
.
clr
(
fd
);
fd_set
.
remove
(
fd
as
usize
);
}
}
}
...
...
@@ -154,22 +133,22 @@ pub fn select_epoll(
let
event
=
&
events
[
i
];
let
fd
=
unsafe
{
event
.data.fd
};
// TODO: Error status when fd does not match?
if
fd
>=
0
&&
fd
<
=
FD_SETSIZE
as
c_int
{
if
fd
>=
0
&&
fd
<
FD_SETSIZE
as
c_int
{
if
event
.events
&
EPOLLIN
>
0
{
if
let
Some
(
ref
mut
fd_set
)
=
read
fds
{
fd_set
.set
(
fd
);
if
let
Some
(
ref
mut
fd_set
)
=
read
_bitset
{
fd_set
.
in
se
r
t
(
fd
as
usize
);
count
+=
1
;
}
}
if
event
.events
&
EPOLLOUT
>
0
{
if
let
Some
(
ref
mut
fd_set
)
=
write
fds
{
fd_set
.set
(
fd
);
if
let
Some
(
ref
mut
fd_set
)
=
write
_bitset
{
fd_set
.
in
se
r
t
(
fd
as
usize
);
count
+=
1
;
}
}
if
event
.events
&
EPOLLERR
>
0
{
if
let
Some
(
ref
mut
fd_set
)
=
except
fds
{
fd_set
.set
(
fd
);
if
let
Some
(
ref
mut
fd_set
)
=
except
_bitset
{
fd_set
.
in
se
r
t
(
fd
as
usize
);
count
+=
1
;
}
}
...
...
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