mirror of https://github.com/fafhrd91/actix-net
remove Accept::new
This commit is contained in:
parent
501488f86e
commit
ee519aa345
|
@ -195,23 +195,12 @@ impl Accept {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let accept = Accept::new(poll, waker, handles, srv);
|
|
||||||
|
|
||||||
(accept, sockets)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new(
|
|
||||||
poll: Poll,
|
|
||||||
waker: WakerQueue,
|
|
||||||
handles: Vec<WorkerHandleAccept>,
|
|
||||||
srv: Server,
|
|
||||||
) -> Self {
|
|
||||||
let mut avail = Availability::default();
|
let mut avail = Availability::default();
|
||||||
|
|
||||||
// Assume all handles are avail at construct time.
|
// Assume all handles are avail at construct time.
|
||||||
avail.set_available_all(&handles);
|
avail.set_available_all(&handles);
|
||||||
|
|
||||||
Self {
|
let accept = Accept {
|
||||||
poll,
|
poll,
|
||||||
waker,
|
waker,
|
||||||
handles,
|
handles,
|
||||||
|
@ -219,7 +208,9 @@ impl Accept {
|
||||||
next: 0,
|
next: 0,
|
||||||
avail,
|
avail,
|
||||||
backpressure: false,
|
backpressure: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
(accept, sockets)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn poll_with(&mut self, mut sockets: Slab<ServerSocketInfo>) {
|
fn poll_with(&mut self, mut sockets: Slab<ServerSocketInfo>) {
|
||||||
|
@ -228,12 +219,8 @@ impl Accept {
|
||||||
loop {
|
loop {
|
||||||
if let Err(e) = self.poll.poll(&mut events, None) {
|
if let Err(e) = self.poll.poll(&mut events, None) {
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
std::io::ErrorKind::Interrupted => {
|
std::io::ErrorKind::Interrupted => continue,
|
||||||
continue;
|
_ => panic!("Poll error: {}", e),
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
panic!("Poll error: {}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,9 +399,9 @@ impl Accept {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while self.avail.available() {
|
while self.avail.available() {
|
||||||
let next = self.next;
|
let next = self.next();
|
||||||
let idx = self.handles[next].idx;
|
let idx = next.idx;
|
||||||
if self.handles[next].available() {
|
if next.available() {
|
||||||
self.avail.set_available(idx, true);
|
self.avail.set_available(idx, true);
|
||||||
match self.send_connection(sockets, conn) {
|
match self.send_connection(sockets, conn) {
|
||||||
Ok(_) => return,
|
Ok(_) => return,
|
||||||
|
@ -439,7 +426,7 @@ impl Accept {
|
||||||
sockets: &mut Slab<ServerSocketInfo>,
|
sockets: &mut Slab<ServerSocketInfo>,
|
||||||
conn: Conn,
|
conn: Conn,
|
||||||
) -> Result<(), Conn> {
|
) -> Result<(), Conn> {
|
||||||
match self.handles[self.next].send(conn) {
|
match self.next().send(conn) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.set_next();
|
self.set_next();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -504,6 +491,10 @@ impl Accept {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn next(&self) -> &WorkerHandleAccept {
|
||||||
|
&self.handles[self.next]
|
||||||
|
}
|
||||||
|
|
||||||
/// Set next worker handle that would accept connection.
|
/// Set next worker handle that would accept connection.
|
||||||
fn set_next(&mut self) {
|
fn set_next(&mut self) {
|
||||||
self.next = (self.next + 1) % self.handles.len();
|
self.next = (self.next + 1) % self.handles.len();
|
||||||
|
|
Loading…
Reference in New Issue