void TCPServerDispatcher::run() { AutoPtr<TCPServerDispatcher> guard(this, true); // ensure object stays alive int idleTime = (int) _pParams->getThreadIdleTime().totalMilliseconds(); for (;;) { AutoPtr<Notification> pNf = _queue.waitDequeueNotification(idleTime); if (pNf) { TCPConnectionNotification* pCNf = dynamic_cast<TCPConnectionNotification*>(pNf.get()); if (pCNf) { std::unique_ptr<TCPServerConnection> pConnection(_pConnectionFactory->createConnection(pCNf->socket())); poco_check_ptr(pConnection.get()); beginConnection(); pConnection->start(); endConnection(); } } FastMutex::ScopedLock lock(_mutex); if (_stopped || (_currentThreads > 1 && _queue.empty())) { --_currentThreads; break; } } }
void CNHSQLServerDBO::SynchronizeDBTime() { _ConnectionPtr pConnection(NULL); if (0x00 == CNHSQLServerDBO::OpenDB(pConnection)) { wchar_t wchSql[1024] = {L'\0'}; ZeroMemory(wchSql, sizeof(wchSql)); _snwprintf_s(wchSql,_countof(wchSql) ,_TRUNCATE, L"select GETDATE() as DateTime;"); _RecordsetPtr pRecordset(NULL); if (0x00 == CNHSQLServerDBO::OpenQuery(pConnection, pRecordset, wchSql)) { if (!pRecordset->adoEOF) { _variant_t v; v.ChangeType(VT_NULL); CNHSQLServerDBO::GetFieldValue(pRecordset, v, L"DateTime"); if (v.vt == VT_DATE) { HANDLE token; //提升权限 if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&token)) { } TOKEN_PRIVILEGES tkp; tkp.PrivilegeCount = 1; ::LookupPrivilegeValue(NULL,SE_SYSTEMTIME_NAME,&tkp.Privileges[0].Luid); tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if(!AdjustTokenPrivileges(token,FALSE,&tkp,sizeof(tkp),NULL,NULL)) { } CloseHandle(token); DATE dt = static_cast<DATE>(v); SYSTEMTIME st; VariantTimeToSystemTime(dt, &st); SetLocalTime(&st); } } } CNHSQLServerDBO::CloseQuery(pRecordset); CNHSQLServerDBO::CloseDB(pConnection); } }
Protocol::Protocol( char* tag ) { LOG(Log::logDEBUG4) << "NEW PROTOCOL STARTED" << tag; connections[tag] = ( pConnection( (aosnet::IConnection*) new Connection() ) ); fPS onDisconnectCallback = boost::bind( &IConnection::onDisconnect , connections[tag], _1 ); fPS onRecvCallback = boost::bind( &IConnection::onRecv , connections[tag], _1); transports[tag] = ( pTransport( (aosnet::Transport::ITransport*)new aosnet::Transport::Dummy::Transport( onDisconnectCallback , onRecvCallback ) ) ); transports[tag]->connect(connections[tag]); }
//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~ void HyperTextTransportProtocolService::createConnection() { boost::shared_ptr<HTTP::Connection> pConnection(new HTTP::Connection(m_ioService, *this)); m_pNewConnection.swap(pConnection); }