private void OnSPEvent(uint poolId, tagSocketPoolEvent spe, IntPtr h) { THandler handler = MapToHandler(h); switch (spe) { case tagSocketPoolEvent.speTimer: if (CScopeUQueue.MemoryConsumed / 1024 > CScopeUQueue.SHARED_BUFFER_CLEAN_SIZE) { CScopeUQueue.DestroyUQueuePool(); } break; case tagSocketPoolEvent.speStarted: lock (m_cs) { m_nPoolId = poolId; } break; case tagSocketPoolEvent.speShutdown: lock (m_cs) { m_dicSocketHandler.Clear(); } break; case tagSocketPoolEvent.speUSocketCreated: { CClientSocket cs = new CClientSocket(); cs.Set(h); ClientCoreLoader.SetRecvTimeout(h, m_recvTimeout); ClientCoreLoader.SetConnTimeout(h, m_connTimeout); ClientCoreLoader.SetAutoConn(h, (byte)(m_autoConn ? 1 : 0)); handler = new THandler(); if (handler.SvsID == 0) { handler.m_nServiceId = m_ServiceId; } if (handler.SvsID <= SocketProAdapter.BaseServiceID.sidStartup) { throw new InvalidOperationException("Service id must be larger than SocketProAdapter.BaseServiceID.sidStartup"); } handler.Attach(cs); lock (m_cs) { m_dicSocketHandler[cs] = handler; } } break; case tagSocketPoolEvent.speUSocketKilled: if (handler != null) { lock (m_cs) { m_dicSocketHandler.Remove(handler.AttachedClientSocket); } } break; case tagSocketPoolEvent.speConnecting: break; case tagSocketPoolEvent.speConnected: if (ClientCoreLoader.IsOpened(h) != 0) { CClientSocket cs = handler.AttachedClientSocket; if (DoSslServerAuthentication != null && cs.EncryptionMethod == tagEncryptionMethod.TLSv1 && !DoSslServerAuthentication.Invoke(this, cs)) { return; //don't set password or call SwitchTo in case failure of ssl server authentication on certificate from server } ClientCoreLoader.SetSockOpt(h, tagSocketOption.soRcvBuf, 116800, tagSocketLevel.slSocket); ClientCoreLoader.SetSockOpt(h, tagSocketOption.soSndBuf, 116800, tagSocketLevel.slSocket); ClientCoreLoader.SetSockOpt(h, tagSocketOption.soTcpNoDelay, 1, tagSocketLevel.slTcp); ClientCoreLoader.SetPassword(h, cs.ConnectionContext.GetPassword()); bool ok = ClientCoreLoader.StartBatching(h) != 0; ok = ClientCoreLoader.SwitchTo(h, handler.SvsID) != 0; ok = ClientCoreLoader.TurnOnZipAtSvr(h, (byte)(cs.ConnectionContext.Zip ? 1 : 0)) != 0; ok = ClientCoreLoader.SetSockOptAtSvr(h, tagSocketOption.soRcvBuf, 116800, tagSocketLevel.slSocket) != 0; ok = ClientCoreLoader.SetSockOptAtSvr(h, tagSocketOption.soSndBuf, 116800, tagSocketLevel.slSocket) != 0; ok = ClientCoreLoader.SetSockOptAtSvr(h, tagSocketOption.soTcpNoDelay, 1, tagSocketLevel.slTcp) != 0; ok = (ClientCoreLoader.CommitBatching(h, (byte)0) != 0); } break; case tagSocketPoolEvent.speQueueMergedFrom: m_pHFrom = MapToHandler(h); #if DEBUG IClientQueue cq = m_pHFrom.AttachedClientSocket.ClientQueue; uint remaining = (uint)m_pHFrom.RequestsQueued; if (cq.MessageCount != remaining) { Console.WriteLine("From: Messages = {0}, remaining requests = {1}", cq.MessageCount, remaining); } #endif break; case tagSocketPoolEvent.speQueueMergedTo: { THandler to = MapToHandler(h); m_pHFrom.AppendTo(to); m_pHFrom = null; } break; default: break; } if (SocketPoolEvent != null) { SocketPoolEvent.Invoke(this, spe, handler); } OnSocketPoolEvent(spe, handler); if (spe == tagSocketPoolEvent.speConnected && ClientCoreLoader.IsOpened(h) != 0) { SetQueue(handler.AttachedClientSocket); } }
private void OnSPEvent(uint poolId, tagSocketPoolEvent spe, IntPtr h) { THandler handler = MapToHandler(h); switch (spe) { case tagSocketPoolEvent.speTimer: //Console.WriteLine("Timer running = " + poolId + ", thread id = " + System.Threading.Thread.CurrentThread.ManagedThreadId); break; case tagSocketPoolEvent.speStarted: lock (m_cs) { m_nPoolId = poolId; } break; case tagSocketPoolEvent.speShutdown: lock (m_cs) { m_dicSocketHandler.Clear(); } break; case tagSocketPoolEvent.speUSocketCreated: { CClientSocket cs = new CClientSocket(); cs.Set(h); ClientCoreLoader.SetRecvTimeout(h, m_recvTimeout); ClientCoreLoader.SetConnTimeout(h, m_connTimeout); ClientCoreLoader.SetAutoConn(h, (byte)(m_autoConn ? 1 : 0)); handler = new THandler(); if (handler.SvsID == 0) { handler.m_nServiceId = m_ServiceId; } if (handler.SvsID <= SocketProAdapter.BaseServiceID.sidStartup) { throw new InvalidOperationException("Service id must be larger than SocketProAdapter.BaseServiceID.sidStartup"); } handler.Attach(cs); lock (m_cs) { m_dicSocketHandler[cs] = handler; } } break; case tagSocketPoolEvent.speUSocketKilled: if (handler != null) { lock (m_cs) { m_dicSocketHandler.Remove(handler.AttachedClientSocket); } } break; case tagSocketPoolEvent.speConnecting: break; case tagSocketPoolEvent.speConnected: if (ClientCoreLoader.IsOpened(h) != 0) { CClientSocket cs = handler.AttachedClientSocket; if (DoSslServerAuthentication != null && cs.EncryptionMethod == tagEncryptionMethod.TLSv1 && !DoSslServerAuthentication.Invoke(this, cs)) { return; //don't set password or call SwitchTo in case failure of ssl server authentication on certificate from server } ClientCoreLoader.SetSockOpt(h, tagSocketOption.soRcvBuf, 116800, tagSocketLevel.slSocket); ClientCoreLoader.SetSockOpt(h, tagSocketOption.soSndBuf, 116800, tagSocketLevel.slSocket); ClientCoreLoader.SetSockOpt(h, tagSocketOption.soTcpNoDelay, 1, tagSocketLevel.slTcp); ClientCoreLoader.SetPassword(h, cs.ConnectionContext.GetPassword()); bool ok = ClientCoreLoader.StartBatching(h) != 0; ok = ClientCoreLoader.SwitchTo(h, handler.SvsID) != 0; if (ok) { ok = ClientCoreLoader.TurnOnZipAtSvr(h, (byte)(cs.ConnectionContext.Zip ? 1 : 0)) != 0; ok = ClientCoreLoader.SetSockOptAtSvr(h, tagSocketOption.soRcvBuf, 116800, tagSocketLevel.slSocket) != 0; ok = ClientCoreLoader.SetSockOptAtSvr(h, tagSocketOption.soSndBuf, 116800, tagSocketLevel.slSocket) != 0; ok = ClientCoreLoader.SetSockOptAtSvr(h, tagSocketOption.soTcpNoDelay, 1, tagSocketLevel.slTcp) != 0; } ok = ClientCoreLoader.CommitBatching(h, (byte)0) != 0; } break; case tagSocketPoolEvent.speQueueMergedFrom: m_pHFrom = MapToHandler(h); break; case tagSocketPoolEvent.speQueueMergedTo: { THandler to = MapToHandler(h); m_pHFrom.AppendTo(to); m_pHFrom = null; } break; default: break; } lock (m_cs) { if (SocketPoolEvent != null) { SocketPoolEvent.Invoke(this, spe, handler); } } OnSocketPoolEvent(spe, handler); }