Struct tokio_fastcgi::Requests
source · pub struct Requests<R: AsyncRead + Unpin + Send, W: AsyncWrite + Unpin + Send> { /* private fields */ }
Expand description
Processes records form an input and output stream.
FastCGI allow multiple requests to be interleaved within one data-stream.
This struct reads the FastCGI-records from an input stream and assembles
them into a Request
.
Beware: Requests are built in memory. Having huge requests can eat up all of your systems memory.
Implementations§
source§impl<'w, R: AsyncRead + Unpin + Send, W: AsyncWrite + Unpin + Send> Requests<R, W>
impl<'w, R: AsyncRead + Unpin + Send, W: AsyncWrite + Unpin + Send> Requests<R, W>
sourcepub fn new(rd: R, wr: W, max_conns: u8, max_reqs: u8) -> Self
pub fn new(rd: R, wr: W, max_conns: u8, max_reqs: u8) -> Self
Creates a new Requests
instance.
As soon as a new connection is accepted the read and write parts of this
connection should be passed to this function. It will create a new
Requests
instance that will handle the communication between the
web-server and the FastCGI application.
In addition to the read and write side of the connection two more parameters must be passed:
- max_conns
Maximum number of concurrent connections. This value will be returned to the web-server to allow it to adjust its connection handling. - max_reqs
Maximum number of concurrent requests. Concurrent requests are handled by tokio-fastcgi but they consume memory. This value is used to tell the web-server how many concurrent requests he can use per connection.
sourcepub fn from_split_socket(
split_socket: (R, W),
max_conns: u8,
max_reqs: u8
) -> Self
pub fn from_split_socket( split_socket: (R, W), max_conns: u8, max_reqs: u8 ) -> Self
Same as new
but takes a tuple containing the read and write
side of the socket instead of two distinct variables
This is more convenient in combination with the split
function.
§Example
if let Ok(mut socket) = listener.accept().await {
tokio::spawn(async move {
// Directly use the result of the split() call to construct a Requests instance
let mut requests = Requests::from_split_socket(socket.0.split(), 10, 10);
// Process the requests
});
}
sourcepub async fn next(&mut self) -> Result<Option<Request<W>>, Error>
pub async fn next(&mut self) -> Result<Option<Request<W>>, Error>
Fetches the next request from this connection
This function asynchronously fetches FastCGI records and assembles them
into requests. It does the de-interlacing to allow multiple requests to
be processed in parallel. As soon as the information for a request is
complete, it returns a Request
instance for further processing.
This function will do the book keeping and process system requests like
FCGI_GET_VALUES
or FCGI_ABORT_REQUEST
.