Esempio n. 1
0
 public void UsageGiveBack(NanoConnection connection)
 {
     lock (_inUseLock)
     {
         _clients.Enqueue(connection);
     }
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 public void CloseOpenConnection(NanoConnection c)
 {
     NN.Close(c.Socket); // could return -1 (error). todo: handle better.
     CreateAndConnectSocket(c);
 }