style(http): Rustfmt State.update
This commit is contained in:
333
src/http/conn.rs
333
src/http/conn.rs
@@ -669,172 +669,195 @@ impl<H: MessageHandler<T>, T: Transport> fmt::Debug for State<H, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<H: MessageHandler<T>, T: Transport> State<H, T> {
|
impl<H: MessageHandler<T>, T: Transport> State<H, T> {
|
||||||
fn update<F, K>(&mut self, next: Next, factory: &F) where F: MessageHandlerFactory<K, T>, K: Key {
|
fn update<F, K>(&mut self, next: Next, factory: &F)
|
||||||
let timeout = next.timeout;
|
where F: MessageHandlerFactory<K, T>,
|
||||||
let state = mem::replace(self, State::Closed);
|
K: Key
|
||||||
match (state, next.interest) {
|
{
|
||||||
(_, Next_::Remove) | (State::Closed, _) => return, // Keep State::Closed.
|
let timeout = next.timeout;
|
||||||
(State::Init { .. }, e) =>
|
let state = mem::replace(self, State::Closed);
|
||||||
{ mem::replace(self, State::Init { interest: e, timeout: timeout} ); },
|
match (state, next.interest) {
|
||||||
(State::Http1(mut http1), next_) => {
|
(_, Next_::Remove) |
|
||||||
match next_ {
|
(State::Closed, _) => return, // Keep State::Closed.
|
||||||
Next_::Remove => unreachable!(), // Covered in (_, Next_::Remove) case above.
|
(State::Init { .. }, e) => {
|
||||||
Next_::End => {
|
mem::replace(self,
|
||||||
let reading = match http1.reading {
|
State::Init {
|
||||||
Reading::Body(ref decoder) |
|
interest: e,
|
||||||
Reading::Wait(ref decoder) if decoder.is_eof() => {
|
timeout: timeout,
|
||||||
if http1.keep_alive {
|
});
|
||||||
Reading::KeepAlive
|
}
|
||||||
} else {
|
(State::Http1(mut http1), next_) => {
|
||||||
Reading::Closed
|
match next_ {
|
||||||
|
Next_::Remove => unreachable!(), // Covered in (_, Next_::Remove) case above.
|
||||||
|
Next_::End => {
|
||||||
|
let reading = match http1.reading {
|
||||||
|
Reading::Body(ref decoder) |
|
||||||
|
Reading::Wait(ref decoder) if decoder.is_eof() => {
|
||||||
|
if http1.keep_alive {
|
||||||
|
Reading::KeepAlive
|
||||||
|
} else {
|
||||||
|
Reading::Closed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
Reading::KeepAlive => http1.reading,
|
||||||
Reading::KeepAlive => http1.reading,
|
_ => Reading::Closed,
|
||||||
_ => Reading::Closed,
|
};
|
||||||
};
|
let mut writing = Writing::Closed;
|
||||||
let mut writing = Writing::Closed;
|
let encoder = match http1.writing {
|
||||||
let encoder = match http1.writing {
|
Writing::Wait(enc) |
|
||||||
Writing::Wait(enc) | Writing::Ready(enc) => Some(enc),
|
Writing::Ready(enc) => Some(enc),
|
||||||
Writing::Chunk(mut chunk) => {
|
Writing::Chunk(mut chunk) => {
|
||||||
if chunk.is_written() {
|
if chunk.is_written() {
|
||||||
Some(chunk.next.0)
|
Some(chunk.next.0)
|
||||||
} else {
|
} else {
|
||||||
chunk.next.1 = next;
|
chunk.next.1 = next;
|
||||||
writing = Writing::Chunk(chunk);
|
writing = Writing::Chunk(chunk);
|
||||||
None
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
_ => return, // Keep State::Closed.
|
||||||
_ => return // Keep State::Closed.
|
};
|
||||||
};
|
if let Some(encoder) = encoder {
|
||||||
if let Some(encoder) = encoder {
|
if encoder.is_eof() {
|
||||||
if encoder.is_eof() {
|
if http1.keep_alive {
|
||||||
if http1.keep_alive { writing = Writing::KeepAlive }
|
writing = Writing::KeepAlive
|
||||||
} else if let Some(buf) = encoder.finish() {
|
}
|
||||||
writing = Writing::Chunk(Chunk {
|
} else if let Some(buf) = encoder.finish() {
|
||||||
buf: buf.bytes,
|
writing = Writing::Chunk(Chunk {
|
||||||
pos: buf.pos,
|
buf: buf.bytes,
|
||||||
next: (h1::Encoder::length(0), Next::end())
|
pos: buf.pos,
|
||||||
})
|
next: (h1::Encoder::length(0), Next::end()),
|
||||||
}
|
})
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match (reading, writing) {
|
match (reading, writing) {
|
||||||
(Reading::KeepAlive, Writing::KeepAlive) => {
|
(Reading::KeepAlive, Writing::KeepAlive) => {
|
||||||
let next = factory.keep_alive_interest();
|
let next = factory.keep_alive_interest();
|
||||||
mem::replace(self, State::Init {
|
mem::replace(self,
|
||||||
interest: next.interest,
|
State::Init {
|
||||||
timeout: next.timeout,
|
interest: next.interest,
|
||||||
});
|
timeout: next.timeout,
|
||||||
return;
|
});
|
||||||
},
|
return;
|
||||||
(reading, Writing::Chunk(chunk)) => {
|
}
|
||||||
http1.reading = reading;
|
(reading, Writing::Chunk(chunk)) => {
|
||||||
http1.writing = Writing::Chunk(chunk);
|
http1.reading = reading;
|
||||||
|
http1.writing = Writing::Chunk(chunk);
|
||||||
|
}
|
||||||
|
_ => return, // Keep State::Closed.
|
||||||
}
|
}
|
||||||
_ => return // Keep State::Closed.
|
|
||||||
}
|
}
|
||||||
},
|
Next_::Read => {
|
||||||
Next_::Read => {
|
http1.reading = match http1.reading {
|
||||||
http1.reading = match http1.reading {
|
Reading::Init => Reading::Parse,
|
||||||
Reading::Init => Reading::Parse,
|
Reading::Wait(decoder) => Reading::Body(decoder),
|
||||||
Reading::Wait(decoder) => Reading::Body(decoder),
|
same => same,
|
||||||
same => same
|
};
|
||||||
};
|
|
||||||
|
|
||||||
http1.writing = match http1.writing {
|
http1.writing = match http1.writing {
|
||||||
Writing::Ready(encoder) => {
|
Writing::Ready(encoder) => {
|
||||||
if encoder.is_eof() {
|
if encoder.is_eof() {
|
||||||
if http1.keep_alive {
|
if http1.keep_alive {
|
||||||
Writing::KeepAlive
|
Writing::KeepAlive
|
||||||
} else {
|
} else {
|
||||||
Writing::Closed
|
Writing::Closed
|
||||||
}
|
}
|
||||||
} else if encoder.is_closed() {
|
} else if encoder.is_closed() {
|
||||||
if let Some(buf) = encoder.finish() {
|
if let Some(buf) = encoder.finish() {
|
||||||
Writing::Chunk(Chunk {
|
Writing::Chunk(Chunk {
|
||||||
buf: buf.bytes,
|
buf: buf.bytes,
|
||||||
pos: buf.pos,
|
pos: buf.pos,
|
||||||
next: (h1::Encoder::length(0), Next::wait())
|
next: (h1::Encoder::length(0), Next::wait()),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Writing::Closed
|
Writing::Closed
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Writing::Wait(encoder)
|
Writing::Wait(encoder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Writing::Chunk(chunk) => {
|
||||||
|
if chunk.is_written() {
|
||||||
|
Writing::Wait(chunk.next.0)
|
||||||
|
} else {
|
||||||
|
Writing::Chunk(chunk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
same => same,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
Next_::Write => {
|
||||||
Writing::Chunk(chunk) => if chunk.is_written() {
|
http1.writing = match http1.writing {
|
||||||
Writing::Wait(chunk.next.0)
|
Writing::Wait(encoder) => Writing::Ready(encoder),
|
||||||
} else {
|
Writing::Init => Writing::Head,
|
||||||
Writing::Chunk(chunk)
|
Writing::Chunk(chunk) => {
|
||||||
},
|
if chunk.is_written() {
|
||||||
same => same
|
Writing::Ready(chunk.next.0)
|
||||||
};
|
} else {
|
||||||
},
|
Writing::Chunk(chunk)
|
||||||
Next_::Write => {
|
}
|
||||||
http1.writing = match http1.writing {
|
}
|
||||||
Writing::Wait(encoder) => Writing::Ready(encoder),
|
same => same,
|
||||||
Writing::Init => Writing::Head,
|
};
|
||||||
Writing::Chunk(chunk) => if chunk.is_written() {
|
|
||||||
Writing::Ready(chunk.next.0)
|
|
||||||
} else {
|
|
||||||
Writing::Chunk(chunk)
|
|
||||||
},
|
|
||||||
same => same
|
|
||||||
};
|
|
||||||
|
|
||||||
http1.reading = match http1.reading {
|
http1.reading = match http1.reading {
|
||||||
Reading::Body(decoder) => if decoder.is_eof() {
|
Reading::Body(decoder) => {
|
||||||
if http1.keep_alive {
|
if decoder.is_eof() {
|
||||||
Reading::KeepAlive
|
if http1.keep_alive {
|
||||||
} else {
|
Reading::KeepAlive
|
||||||
Reading::Closed
|
} else {
|
||||||
|
Reading::Closed
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Reading::Wait(decoder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
same => same,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else {
|
Next_::ReadWrite => {
|
||||||
Reading::Wait(decoder)
|
http1.reading = match http1.reading {
|
||||||
},
|
Reading::Init => Reading::Parse,
|
||||||
same => same
|
Reading::Wait(decoder) => Reading::Body(decoder),
|
||||||
};
|
same => same,
|
||||||
},
|
};
|
||||||
Next_::ReadWrite => {
|
http1.writing = match http1.writing {
|
||||||
http1.reading = match http1.reading {
|
Writing::Wait(encoder) => Writing::Ready(encoder),
|
||||||
Reading::Init => Reading::Parse,
|
Writing::Init => Writing::Head,
|
||||||
Reading::Wait(decoder) => Reading::Body(decoder),
|
Writing::Chunk(chunk) => {
|
||||||
same => same
|
if chunk.is_written() {
|
||||||
};
|
Writing::Ready(chunk.next.0)
|
||||||
http1.writing = match http1.writing {
|
} else {
|
||||||
Writing::Wait(encoder) => Writing::Ready(encoder),
|
Writing::Chunk(chunk)
|
||||||
Writing::Init => Writing::Head,
|
}
|
||||||
Writing::Chunk(chunk) => if chunk.is_written() {
|
}
|
||||||
Writing::Ready(chunk.next.0)
|
same => same,
|
||||||
} else {
|
};
|
||||||
Writing::Chunk(chunk)
|
}
|
||||||
},
|
Next_::Wait => {
|
||||||
same => same
|
http1.reading = match http1.reading {
|
||||||
};
|
Reading::Body(decoder) => Reading::Wait(decoder),
|
||||||
},
|
same => same,
|
||||||
Next_::Wait => {
|
};
|
||||||
http1.reading = match http1.reading {
|
|
||||||
Reading::Body(decoder) => Reading::Wait(decoder),
|
|
||||||
same => same
|
|
||||||
};
|
|
||||||
|
|
||||||
http1.writing = match http1.writing {
|
http1.writing = match http1.writing {
|
||||||
Writing::Ready(encoder) => Writing::Wait(encoder),
|
Writing::Ready(encoder) => Writing::Wait(encoder),
|
||||||
Writing::Chunk(chunk) => if chunk.is_written() {
|
Writing::Chunk(chunk) => {
|
||||||
Writing::Wait(chunk.next.0)
|
if chunk.is_written() {
|
||||||
} else {
|
Writing::Wait(chunk.next.0)
|
||||||
Writing::Chunk(chunk)
|
} else {
|
||||||
},
|
Writing::Chunk(chunk)
|
||||||
same => same
|
}
|
||||||
};
|
}
|
||||||
}
|
same => same,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http1.timeout = timeout;
|
||||||
|
mem::replace(self, State::Http1(http1));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
http1.timeout = timeout;
|
|
||||||
mem::replace(self, State::Http1(http1));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// These Reading and Writing stuff should probably get moved into h1/message.rs
|
// These Reading and Writing stuff should probably get moved into h1/message.rs
|
||||||
|
|||||||
Reference in New Issue
Block a user