public static TcpClient CreateSocket(IPEndPoint endpoint, DistCacheConfigBase config) { TcpClient Connection = new TcpClient(); if (Connection.ReceiveBufferSize != 1 << 15) { Connection.ReceiveBufferSize = 1 << 15; } if (Connection.SendBufferSize != 1 << 15) { Connection.SendBufferSize = 1 << 15; } if (Connection.ReceiveTimeout != config.SocketReadTimeout) { Connection.ReceiveTimeout = config.SocketReadTimeout; } if (Connection.SendTimeout != config.SocketWriteTimeout) { Connection.SendTimeout = config.SocketWriteTimeout; } if (Connection.Client.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive) as int? == 1) { Connection.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); } Connection.Connect(endpoint); return(Connection); }
protected SocketHandler(TcpClient tcp, DistCacheConfigBase config) { this.lockMe = new object(); this.Config = config; this._connection = tcp; this._messagesToSend = new ConcurrentQueue <MessageTriplete>(); this._memoryStream = new MemoryStream(); }
protected SocketHandler(SocketHandler other) { this.lockMe = other.lockMe; lock (this.lockMe) { this.Config = Config; this._connection = other._connection; other._connection = null; this._memoryStream = other._memoryStream; other._memoryStream = null; this.Config = other.Config; this._messagesToSend = other._messagesToSend; this._posistionReadUntil = other._posistionReadUntil; } }
public void HandShakeAcceptMoar() { var dic = new Dictionary <string, string>(); string pass = DistCacheConfigBase.GenerateRandomPassword(); var serverConfig = new DistCacheServerConfig() { Password = pass }; int toAdd = 16; int iters = 2; using (var srv = new CacheServer(serverConfig)) { var clientscon = new ConcurrentBag <DistCacheClient>(); for (int k = 0; k < iters; ++k) { List <Task <DistCacheClient> > clients = new List <Task <DistCacheClient> >(); var ls = new List <DistCacheClient>(); for (int i = 0; i < toAdd; ++i) { clients.Add(new Task <DistCacheClient>(() => { var o = DistCacheClient.Create(new DistCacheClientConfig() { Password = pass }); clientscon.Add(o); return(o); })); clients.Last().Start(); } Task.WaitAll(clients.ToArray()); } while (srv.PendingClientsCount > 0) { Thread.Sleep(500); } Assert.AreEqual(toAdd * iters, srv.ConnectedClientsCount); } }
public static void Main(string[] args) { var dic = new Dictionary <string, string>(); string pass = DistCacheConfigBase.GenerateRandomPassword(); var serverConfig = new DistCacheServerConfig() { Password = pass }; using (var srv = new CacheServer(serverConfig)) { int clients = 1; int msgs = 50000; var ls = new ConcurrentBag <DistCacheClient>(); for (int k = 0; k < clients; ++k) { var client = DistCacheClient.Create(new DistCacheClientConfig() { Password = pass }); ls.Add(client); } Stopwatch sw = Stopwatch.StartNew(); long cnt = 0; for (int i = 0; i < msgs; ++i) { foreach (var cl in ls) { string s = cl.GetMessage($"{Interlocked.Increment(ref cnt)}").Result; } } string ss = ""; while (ss != "q") { Console.WriteLine($"got {Interlocked.Read(ref cnt)} {sw.Elapsed}"); ss = Console.ReadLine(); } } }
public void HandShakeAccept() { var dic = new Dictionary <string, string>(); string pass = DistCacheConfigBase.GenerateRandomPassword(); var serverConfig = new DistCacheServerConfig() { Password = pass }; using (var srv = new CacheServer(serverConfig)) { var ls = new List <DistCacheClient>(); var client = DistCacheClient.Create(new DistCacheClientConfig() { Password = pass }); Thread.Sleep(1000); Assert.IsTrue(srv.ConnectedClientsCount == 1); } }
public ClientHandShakeHandler(TcpClient tcp, DistCacheConfigBase config, Guid clientUID) : base(tcp, config) { this.clientUID = clientUID; }