예제 #1
0
 public DisquuunSocketPool(int connectionCount, Action <DisquuunSocket, string> OnSocketOpened, Action <DisquuunSocket, string, Exception> OnSocketConnectionFailed)
 {
     this.stackSocket = new StackSocket();
     this.sockets     = new DisquuunSocket[connectionCount];
     for (var i = 0; i < sockets.Length; i++)
     {
         this.sockets[i] = new DisquuunSocket(OnSocketOpened, this.OnReloaded, OnSocketConnectionFailed);
     }
 }
예제 #2
0
        public Disquuun(
            string host,
            int port,
            long bufferSize,
            int minConnectionCount,
            Action <string> ConnectionOpenedAct            = null,
            Action <string, Exception> ConnectionFailedAct = null
            )
        {
            this.connectionId = Guid.NewGuid().ToString();

            this.bufferSize = bufferSize;
            this.endPoint   = new IPEndPoint(IPAddress.Parse(host), port);

            this.stackSocket = new StackSocket();

            this.connectionState = ConnectionState.OPENING;

            /*
             *      ConnectionOpened handler treats all connections are opened.
             */
            if (ConnectionOpenedAct != null)
            {
                this.ConnectionOpened = ConnectionOpenedAct;
            }
            else
            {
                this.ConnectionOpened = conId => {}
            };

            /*
             *      ConnectionFailed handler only treats connection error.
             *
             *      other runtime errors will emit in API handler.
             */
            if (ConnectionFailedAct != null)
            {
                this.ConnectionFailed = ConnectionFailedAct;
            }
            else
            {
                this.ConnectionFailed = (info, e) => {}
            };

            this.minConnectionCount = minConnectionCount;

            socketPool = new DisquuunSocket[minConnectionCount];
            for (var i = 0; i < minConnectionCount; i++)
            {
                socketPool[i] = new DisquuunSocket(endPoint, bufferSize, OnSocketOpened, OnReloaded, OnSocketConnectionFailed);
            }
        }
예제 #3
0
 public DisquuunInput(DisqueCommand command, byte[] data, StackSocket socket)
 {
     this.command = command;
     this.data    = data;
     this.socket  = socket;
 }