public void UsageGiveBack(NanoConnection connection) { lock (_inUseLock) { _clients.Enqueue(connection); } }
public void OpenConnections() { if (ConnectionPoolSize <= 0) { throw new Exception("connection pool size must be greater than 0"); } _clients = new Queue <NanoConnection>(); for (int i = 0; i < ConnectionPoolSize; ++i) { string address = "tcp://" + Host + ":" + Port; var c = new NanoConnection(-1, this, address); CreateAndConnectSocket(c); _clients.Enqueue(c); } }
private void CreateAndConnectSocket(NanoConnection c) { c.Socket = NN.Socket(Domain.SP, Protocol.REQ); if (c.Socket < 0) { Dispose(); throw new Exception("failed to create SP/REQ socket."); } int ret = NN.Connect(c.Socket, c.Address); if (ret < 0) { Dispose(); throw new Exception("failed to open connection to: " + c.Address); } }
public void CloseOpenConnection(NanoConnection c) { NN.Close(c.Socket); // could return -1 (error). todo: handle better. CreateAndConnectSocket(c); }