// as this is pretty impossible, a panic is warranted if it ever occurs
Err(TryRecvError::Disconnected)=>panic!("Receiving channel was disconnected. A a sender is owned by the current struct, this should never happen(!!!)")
}
}
}
structRecycledConn(
Option<Connection>,// To allow moving out of the struct when `Drop` is called.
ChannelSender<Connection>,
);
implDerefforRecycledConn{
typeTarget=Connection;
fnderef(&self)-> &Self::Target{
self.0
.as_ref()
.expect("RecycledConn does not have a connection in Option<>")
}
}
implDropforRecycledConn{
fndrop(&mutself){
ifletSome(conn)=self.0.take(){
log::debug!("Recycled connection");
ifletErr(e)=self.1.send(conn){
log::warn!("Recycling a connection led to the following error: {:?}",e)
}
}
}
}
}
}
}
@ -76,6 +113,7 @@ impl Pool {
Ok(Self{
Ok(Self{
writer,
writer,
readers,
readers,
spills: ConnectionRecycler::new(),
spill_tracker: Arc::new(()),
spill_tracker: Arc::new(()),
path: path.as_ref().to_path_buf(),
path: path.as_ref().to_path_buf(),
})
})
@ -104,24 +142,38 @@ impl Pool {
}
}
fnread_lock(&self)-> HoldingConn<'_>{
fnread_lock(&self)-> HoldingConn<'_>{
// First try to get a connection from the permanent pool
forrin&self.readers{
forrin&self.readers{
ifletSome(reader)=r.try_lock(){
ifletSome(reader)=r.try_lock(){
returnHoldingConn::FromGuard(reader);
returnHoldingConn::FromGuard(reader);
}
}
}
}
letspill_arc=self.spill_tracker.clone();
// We didn't get a connection from the permanent pool, so we'll dumpster-dive for recycled connections.
// Either we have a connection or we dont, if we don't, we make a new one.