-
Notifications
You must be signed in to change notification settings - Fork 4
Client Socket Pool Repository
A set of functions to manage connections in a connection pool. It is a repository of connection pools,
{ (repos_name, pool_repos) }
where pool_repos is a collection of connections and associated functions to manage the collection
{ (name, [ss_ptr]) }
One of the special features of a pool in the repository is that it is possible to share the same connection by multiple threads.
local ffi = require('ffi');
local repos_loader = package.loadlib("libevpoolrepos.so","luaopen_libevpoolrepos");
local repos_lib = repos_loader();
ffi.cdef[[
void * pin_loaded_so(const char *);
]]
local lib = ffi.C.pin_loaded_so("libevpoolrepos.so");
The repository is maintained per instance of evlua/evluaserver and will not get reinitialized if already initialized once (ffi is the foreign function interface to lua) The function pin_loaded_so ensures that the loaded dll remains in the process and will not get removed once the dlclose function is called, this is necessary to retain some of the static variables initialized in libevpoolrepos.so.
local connection_pool = repos_lib.new(poolname);
Adds a given connection handle (ss_ptr) to the connection pool of name "name".
Parameters:
connection_pool: handle to connection pool repository
name: Name of the connection pool
ss_ptr : streamsocket
Return:
none
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Removes the connection from the pool and returns the handle, nil if there is no entry
Parameters:
connection_pool: handle to connection pool repository
name: Name of the connection pool
Return:
ss_ptr: streamsocket or nil
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall
Fetches a connection from the pool if the pool is marked sharable
Parameters:
connection_pool: handle to connection pool repository
name: Name of the connection pool
Return:
ss_ptr: streamsocket or nil
ERROR:
Exceptions are thrown upon error, which can be caught via mechanism of pcall/xpcall