public Disquuun( string host, int port, long bufferSize, int defaultConnectionCount, Action <string> ConnectionOpenedAct = null, Action <string, Exception> ConnectionFailedAct = null, Action <int, Action <bool, int> > OnSocketShortage = null ) { this.connectionId = Guid.NewGuid().ToString(); this.endPoint = new IPEndPoint(IPAddress.Parse(host), port); this.bufferSize = bufferSize; 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) => { }; } defaultConnectionIndexies = new Hashtable(); for (var i = 0; i < defaultConnectionCount; i++) { defaultConnectionIndexies.Add(i, false); } this.socketPool = new DisquuunSocketPool( defaultConnectionCount, this.OnSocketOpened, this.OnSocketConnectionFailed, OnSocketShortage, endPoint, bufferSize ); this.socketPool.Connect(); }
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.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; this.socketPool = new DisquuunSocketPool(minConnectionCount, this.OnSocketOpened, this.OnSocketConnectionFailed); this.socketPool.Connect(endPoint, bufferSize); }
public DisquuunInput(DisqueCommand command, byte[] data, DisquuunSocketPool socketPool) { this.command = command; this.data = data; this.socketPool = socketPool; }