API
#net/pool
Xu 0.8.8 API
import: #net/pool
counts: 1 fns, 4 methods, 2 types, 0 consts, 0 ifaces
The state channel serializes lifecycle changes, not network dialing/I/O.
struct State
pub struct State {
pub closed int
pub idle []int
pub borrowed []int
}
Purpose
The state channel serializes lifecycle changes, not network dialing/I/O.
Parameters
closed int- field (int)
idle []int- field ([]int)
borrowed []int- field ([]int)
struct SocketPool
pub struct SocketPool {
pub state chan State
pub max_idle int
}
Purpose
Public struct `SocketPool`.
Parameters
state chan State- field (channel; type chan State)
max_idle int- field (int)
new_state
pub fn new_state() chan State
Purpose
Construct state.
Parameters
none
Returns
chan State — a value of this type
(&SocketPool) take
pub fn (p &SocketPool) take() int
Purpose
1 means dial a new socket; -2 means the pool is closed.
Parameters
p &SocketPool- receiver &SocketPool (borrow)
Returns
int — a value of this type
(&SocketPool) adopt
pub fn (p &SocketPool) adopt(fd int) bool
Purpose
A close concurrent with an outstanding dial wins; the new fd is closed.
Parameters
p &SocketPool- receiver &SocketPool (borrow)
fd int- file descriptor (int)
Returns
bool — true or false
(&SocketPool) release
pub fn (p &SocketPool) release(fd int, reusable bool)
Purpose
max_idle limits retained sockets, not the total number of open sockets. Borrowers must return/discard each fd exactly once, before borrowing again.
Parameters
p &SocketPool- receiver &SocketPool (borrow)
fd int- file descriptor (int)
reusable bool- reusable (bool)
(&SocketPool) close
pub fn (p &SocketPool) close()
Purpose
Method on `&SocketPool`: close the resource.
Parameters
p &SocketPool- receiver &SocketPool (borrow)