Esempio n. 1
0
 def _spe_(self, poolId, spe, h): #h -- usocket handle
     #print "Pool id = " + str(poolId) + ", spe = " + str(spe) + ", usocket handle = " + str(h)
     handler = self._MapToHandler_(h)
     if spe == tagSocketPoolEvent.speTimer:
         if CScopeUQueue.MemoryConsumed() / 1024 > CScopeUQueue.SHARED_BUFFER_CLEAN_SIZE:
             CScopeUQueue.DestroyUQueuePool()
     elif spe == tagSocketPoolEvent.speStarted:
         with self._lock_:
             self._PoolId_ = poolId
     elif spe == tagSocketPoolEvent.speShutdown:
         with self._lock_:
             self._PoolId_ = 0
     elif spe == tagSocketPoolEvent.speUSocketKilled:
         with self._lock_:
             del self._m_dicSocketHandler_[handler.Socket]
     elif spe == tagSocketPoolEvent.speUSocketCreated:
         cs = CClientSocket(h)
         ash = self._m_cls_()
         ccl.SetRecvTimeout(h, self._recvTimeout_)
         ccl.SetConnTimeout(h, self._connTimeout_)
         ccl.SetAutoConn(h, self._autoConn_)
         if ash.SvsID == 0:
             ash._m_nServiceId_ = self._serviceId_
         if ash.SvsID <= BaseServiceID.sidStartup:
             raise ValueError('Service id must be larger than SocketProAdapter.BaseServiceID.sidReserved (268435456)')
         ash._Attach_(cs)
         handler = ash
         with self._lock_:
             self._m_dicSocketHandler_[cs] = ash
     elif spe == tagSocketPoolEvent.speConnected:
         if ccl.IsOpened(h):
             cs = handler.Socket
             if self.DoSslServerAuthentication is not None and cs.EncryptionMethod == tagEncryptionMethod.TLSv1 and (not self.DoSslServerAuthentication(self, cs)):
                 return #don't set password or call SwitchTo in case failure of ssl server authentication on certificate from server
             ccl.SetSockOpt(h, tagSocketOption.soRcvBuf, 116800, tagSocketLevel.slSocket)
             ccl.SetSockOpt(h, tagSocketOption.soSndBuf, 116800, tagSocketLevel.slSocket)
             ccl.SetSockOpt(h, tagSocketOption.soTcpNoDelay, 1, tagSocketLevel.slTcp)
             ccl.SetPassword(h, cs.ConnectionContext._Password_)
             ok = ccl.StartBatching(h)
             ok = ccl.SwitchTo(h, handler.SvsID)
             ok = ccl.TurnOnZipAtSvr(h, cs.ConnectionContext.Zip)
             ok = ccl.SetSockOptAtSvr(h, tagSocketOption.soRcvBuf, 116800, tagSocketLevel.slSocket)
             ok = ccl.SetSockOptAtSvr(h, tagSocketOption.soSndBuf, 116800, tagSocketLevel.slSocket)
             ok = ccl.SetSockOptAtSvr(h, tagSocketOption.soTcpNoDelay, 1, tagSocketLevel.slTcp)
             ok = ccl.CommitBatching(h, False)
     elif spe == tagSocketPoolEvent.speQueueMergedFrom:
         self._hFrom = handler
     elif spe == tagSocketPoolEvent.speQueueMergedTo:
         self._hFrom._AppendTo_(handler)
         self._hFrom = None
     else:
         pass
     if self.SocketPoolEvent:
         self.SocketPoolEvent(self, spe, handler)
     self.OnSocketPoolEvent(spe, handler)
     if spe == tagSocketPoolEvent.speConnected and ccl.IsOpened(h):
         self._SetQueue_(handler.Socket)
Esempio n. 2
0
 def OnIdle(self, milliseconds):
     if CScopeUQueue.MemoryConsumed(
     ) / 1024 > CScopeUQueue.SHARED_BUFFER_CLEAN_SIZE:
         CScopeUQueue.DestroyUQueuePool()