src/anonimongo/core/pool

Source   Edit  

Types

Connection[TheSocket] {..} = object
  socket*: TheSocket         ## Socket which used for sending/receiving Bson.
  id*: int                   ## Identifier which used in pool for socket availability.
  
Connection is an object representation of a single asyncsocket and its identifier. Source   Edit  
Pool[TheSocket] {..} = ref object
  ## Actual pool for keeping connections.
  available*: Deque[int]     ## The deque mechanism to indicate which\
                             ## connection available.
  
A single ref object that will live as long Mongo ref-object lives. Source   Edit  

Procs

proc `[]`[T: MultiSock](p: Pool[T]; i: int): lent Connection[T]
Retrieve the i-th connection object in a pool. Source   Edit  
proc `[]=`[T: MultiSock](p: Pool; i: int; c: Connection[T])
Set the i-th connection object with c. Source   Edit  
proc authenticate(p: Pool[AsyncSocket]; user, pass: string;
                  T: typedesc = Sha256Digest; dbname = "admin.$cmd"): Future[
    bool] {....stackTrace: false.}
Authenticate all connections in a pool with supplied username, password, type which default to SHA256Digest, and database which default to "admin". Type receives SHA1Digest as other typedesc. Currently this taking too long for large pool connections. Source   Edit  
proc authenticate(p: Pool[Socket]; user, pass: string;
                  T: typedesc = Sha256Digest; dbname = "admin.$cmd"): bool
Authenticate all connections in a pool with supplied username, password, type which default to SHA256Digest, and database which default to "admin". Type receives SHA1Digest as other typedesc. Currently this taking too long for large pool connections. Source   Edit  
proc close[T: MultiSock](p: Pool[T])
Close all connections in a pool. Source   Edit  
proc connect(p: Pool[AsyncSocket]; address: string; port: int): Future[void] {.
    ...stackTrace: false, raises: [Exception], tags: [RootEffect], forbids: [].}
Connect all connection to specified address and port. Source   Edit  
proc connect(p: Pool[Socket]; address: string; port: int): void {.
    ...raises: [OSError, SslError], tags: [ReadIOEffect, RootEffect], forbids: [].}
Connect all connection to specified address and port. Source   Edit  
proc connections[T: MultiSock](p: Pool[T]): lent TableRef[int, Connection[T]]
Retrieve the connections table. Source   Edit  
proc contains[T: MultiSock](p: Pool; i: int): bool
Check whether the id available in connections. Source   Edit  
proc endConn(p: Pool; i: Positive)
End a connection and return back the id to available queues. Source   Edit  
proc getConn(p: Pool[AsyncSocket]): Future[(int, Connection[AsyncSocket])] {.
    ...stackTrace: false, raises: [Exception, ValueError],
    tags: [RootEffect, TimeEffect], forbids: [].}
Retrieve a random connection with its id in async. In case no available queues in the pool, it will poll whether any other connections will be available soon. Source   Edit  
proc getConn(p: Pool[Socket]): (int, Connection[Socket]) {....raises: [KeyError],
    tags: [], forbids: [].}
Source   Edit  
proc initConnection[T: MultiSock](id = 0): Connection[T]
Init for a connection. Source   Edit  
proc initPool[T: MultiSock](size = 16): Pool[T]
Init a pool. The size very likely higher than supplied pool size, because of deque need to be in size the power of 2. Source   Edit