本文整理汇总了C++中poco::SharedPtr类的典型用法代码示例。如果您正苦于以下问题:C++ SharedPtr类的具体用法?C++ SharedPtr怎么用?C++ SharedPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SharedPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: forward
void LocalPortForwarder::forward(Poco::Net::StreamSocket& socket)
{
if (_logger.debug())
{
_logger.debug(Poco::format("Local connection accepted, creating forwarding connection to %s, remote port %hu", _remoteURI.toString(), _remotePort));
}
try
{
std::string path(_remoteURI.getPathEtc());
if (path.empty()) path = "/";
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPRequest::HTTP_1_1);
request.set(SEC_WEBSOCKET_PROTOCOL, WEBTUNNEL_PROTOCOL);
request.set(X_WEBTUNNEL_REMOTEPORT, Poco::NumberFormatter::format(_remotePort));
Poco::Net::HTTPResponse response;
Poco::SharedPtr<Poco::Net::WebSocket> pWebSocket = _pWebSocketFactory->createWebSocket(_remoteURI, request, response);
if (response.get(SEC_WEBSOCKET_PROTOCOL, "") != WEBTUNNEL_PROTOCOL)
{
_logger.error("The remote host does not support the WebTunnel protocol.");
pWebSocket->shutdown(Poco::Net::WebSocket::WS_PROTOCOL_ERROR);
pWebSocket->close();
socket.close();
return;
}
_pDispatcher->addSocket(socket, new StreamSocketToWebSocketForwarder(_pDispatcher, pWebSocket), _localTimeout);
_pDispatcher->addSocket(*pWebSocket, new WebSocketToStreamSocketForwarder(_pDispatcher, socket), _remoteTimeout);
}
catch (Poco::Exception& exc)
{
_logger.error(Poco::format("Failed to open forwarding connection: %s", exc.displayText()));
socket.close();
}
}
示例2: testCursorRequest
void MongoDBTest::testCursorRequest()
{
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
for(int i = 0; i < 10000; ++i)
{
Document::Ptr doc = new Document();
doc->add("number", i);
insertRequest->documents().push_back(doc);
}
_mongo->sendRequest(*insertRequest);
Poco::Int64 count = db.count(*_mongo, "numbers");
assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers");
int n = 0;
Poco::MongoDB::ResponseMessage& response = cursor.next(*_mongo);
while(1)
{
n += response.documents().size();
if ( response.cursorID() == 0 )
break;
response = cursor.next(*_mongo);
}
assert(n == 10000);
Poco::MongoDB::QueryRequest drop("team.$cmd");
drop.setNumberToReturn(1);
drop.selector().add("drop", std::string("numbers"));
Poco::MongoDB::ResponseMessage responseDrop;
_mongo->sendRequest(drop, responseDrop);
}
示例3: shutdownImpl
void WebEventServiceImpl::shutdownImpl(Poco::SharedPtr<Poco::Net::WebSocket> pWS, Poco::UInt16 statusCode, const std::string& statusMessage, bool passive)
{
//_pContext->logger().notice("Shutting down WebSocket.");
try
{
pWS->shutdown(statusCode, statusMessage);
}
catch (Poco::Exception& exc)
{
_pContext->logger().notice("Error while shutting down WebSocket: " + exc.displayText());
passive = true; // don't wait for client confirmation
}
if (!passive)
{
if (pWS->poll(Poco::Timespan(WEBEVENT_SHUTDOWN_TIMEOUT, 0), Poco::Net::Socket::SELECT_READ))
{
Poco::Buffer<char> buffer(4096);
int flags;
pWS->receiveFrame(buffer.begin(), buffer.size(), flags);
if (flags & Poco::Net::WebSocket::FRAME_OP_CLOSE)
{
pWS->close();
return;
}
}
_pContext->logger().notice("Client failed to confirm shutdown.");
}
pWS->close();
}
示例4: createQueryRequest
Poco::SharedPtr<Poco::MongoDB::QueryRequest> Database::createCountRequest(const std::string& collectionName) const
{
Poco::SharedPtr<Poco::MongoDB::QueryRequest> request = createQueryRequest("$cmd");
request->setNumberToReturn(1);
request->selector().add("count", collectionName);
return request;
}
示例5: sample10
// SELECT DISTINCT birthyear FROM players WHERE birthyear > 1980
void sample10(Poco::MongoDB::Connection& connection)
{
std::cout << "*** SAMPLE 10 ***" << std::endl;
Poco::MongoDB::Database db("sample");
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = db.createCommand();
command->selector()
.add("distinct", "players")
.add("key", "birthyear")
.addNewDocument("query")
.addNewDocument("birthyear")
.add("$gt", 1980);
Poco::MongoDB::ResponseMessage response;
connection.sendRequest(*command, response);
if ( response.hasDocuments() )
{
Poco::MongoDB::Array::Ptr values = response.documents()[0]->get<Poco::MongoDB::Array::Ptr>("values");
for(int i = 0; i < values->size(); ++i )
{
std::cout << values->get<int>(i) << std::endl;
}
}
}
示例6: listener
void WebController::listener()
{
Poco::SharedPtr<MultiView> multiView = new MultiView("base.tpl");
multiView->add("head", new TemplateView("listener/head.tpl"));
multiView->add("main", new TemplateView("listener/index.tpl"));
setView(multiView);
}
示例7: handleRequest
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
Application& app = Application::instance();
try
{
std::string proto = request.get("Sec-WebSocket-Protocol", "");
Poco::SharedPtr<Poco::Net::WebSocket> pWebSocket;
if (proto == "com.appinf.webtunnel.server/1.0")
{
response.set("Sec-WebSocket-Protocol", proto);
pWebSocket = new Poco::Net::WebSocket(request, response);
_portReflector.addServerSocket(pWebSocket, "ac9667bb-6032-4267-af61-9a7aafd40479");
}
else if (proto == "com.appinf.webtunnel.client/1.0")
{
response.set("Sec-WebSocket-Protocol", proto);
std::string portStr = request.get("X-WebTunnel-RemotePort", "");
unsigned port;
if (!portStr.empty() && Poco::NumberParser::tryParseUnsigned(portStr, port) && port > 0 && port < 65536)
{
pWebSocket = new Poco::Net::WebSocket(request, response);
try
{
_portReflector.addClientSocket(pWebSocket, "ac9667bb-6032-4267-af61-9a7aafd40479", static_cast<Poco::UInt16>(port));
}
catch (Poco::NotFoundException&)
{
pWebSocket->shutdown(Poco::Net::WebSocket::WS_UNEXPECTED_CONDITION, "No connection to target available");
}
}
else
{
pWebSocket = new Poco::Net::WebSocket(request, response);
pWebSocket->shutdown(Poco::Net::WebSocket::WS_UNEXPECTED_CONDITION, "Missing or invalid X-WebTunnel-RemotePort header");
}
}
else
{
pWebSocket = new Poco::Net::WebSocket(request, response);
pWebSocket->shutdown(Poco::Net::WebSocket::WS_PROTOCOL_ERROR);
}
}
catch (WebSocketException& exc)
{
app.logger().log(exc);
switch (exc.code())
{
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
response.set("Sec-WebSocket-Version", WebSocket::WEBSOCKET_VERSION);
// fallthrough
case Poco::Net::WebSocket::WS_ERR_NO_HANDSHAKE:
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
case Poco::Net::WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
response.setContentLength(0);
response.send();
break;
}
}
}
示例8: consume
void MessageConsumer::consume(MQHCONN conn, MQMD* md, MQGMO* gmo, MQBYTE* buffer, MQCBC* context)
{
Poco::SharedPtr<Message> msg = new Message(buffer, context->DataLength);
memcpy(msg->md(), md, sizeof(MQMD));
MessageConsumer* consumer = reinterpret_cast<MessageConsumer*>(context->CallbackArea);
consumer->message.notify(consumer, msg);
}
示例9: addSubscriberImpl
void WebEventServiceImpl::addSubscriberImpl(Poco::SharedPtr<Poco::Net::WebSocket> pWS)
{
Subscriber::Ptr pSubscriber = new Subscriber;
pSubscriber->pWebSocket = pWS;
_socketMap[*pWS] = pSubscriber;
watchSocketImpl(*pWS);
pWS->setSendTimeout(Poco::Timespan(WEBEVENT_SEND_TIMEOUT, 0));
pWS->setReceiveTimeout(Poco::Timespan(WEBEVENT_RECEIVE_TIMEOUT, 0));
}
示例10: creds
Poco::Net::WebSocket* DefaultWebSocketFactory::createWebSocket(const Poco::URI& uri, Poco::Net::HTTPRequest& request, Poco::Net::HTTPResponse& response)
{
Poco::SharedPtr<Poco::Net::HTTPClientSession> pSession = Poco::Net::HTTPSessionFactory::defaultFactory().createClientSession(uri);
pSession->setTimeout(_timeout);
if (!_username.empty())
{
Poco::Net::HTTPBasicCredentials creds(_username, _password);
creds.authenticate(request);
}
return new Poco::Net::WebSocket(*pSession, request, response);
}
示例11: sample13
//DELETE players WHERE firstname = 'Victor'
void sample13(Poco::MongoDB::Connection& connection)
{
std::cout << "*** SAMPLE 13 ***" << std::endl;
Poco::MongoDB::Database db("sample");
Poco::SharedPtr<Poco::MongoDB::DeleteRequest> request = db.createDeleteRequest("players");
request->selector().add("firstname", "Victor");
connection.sendRequest(*request);
Poco::MongoDB::Document::Ptr lastError = db.getLastErrorDoc(connection);
std::cout << "LastError: " << lastError->toString(2) << std::endl;
}
示例12: authenticateMongoCR
bool MongoAuthentication::authenticateMongoCR(const std::string &user, const std::string &pwd)
{
bool ret = false;
_user = user;
_pwd = pwd;
try {
std::string nonce;
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
command->selector().add<Poco::Int32>("getnonce", 1);
command->setNumberToReturn(1);
Poco::MongoDB::ResponseMessage response;
_conn.sendRequest(*command, response);
if (response.documents().size() > 0) {
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
nonce = doc->get<std::string>("nonce", "");
std::string password = _user + ":mongo:" + _pwd;
Poco::MD5Engine md5;
md5.update(password);
std::string hashedPassword(Poco::DigestEngine::digestToHex(md5.digest()));
std::string key = nonce + _user + hashedPassword;
md5.reset();
md5.update(key);
std::string hashedKey(Poco::DigestEngine::digestToHex(md5.digest()));
Poco::SharedPtr<Poco::MongoDB::QueryRequest> command = _db.createCommand();
command->selector()
.add<Poco::Int32>("authenticate", 1)
.add<std::string>("user", _user)
.add<std::string>("nonce", nonce)
.add<std::string>("key", hashedKey); // hex_md5( n.nonce + username + hex_md5( username + ":mongo:" + password ) )
_conn.sendRequest(*command, response);
if (response.documents().size() > 0 && response.documents()[0]->get<double>("ok")) {
ret = true;
}
}
} catch (Poco::Exception &) {
throw Poco::ApplicationException("auth failed.");
}
return ret;
}
示例13: UpdateUISetting
void CLogAnalyzerView::UpdateUISetting()
{
if (!m_logger->GetActiveUISetting().isNull())
{
tstring strSettingName = m_logger->GetActiveUISetting()->getName();
CLogAnalyzerApp* app = (CLogAnalyzerApp*)AfxGetApp();
if (app != NULL)
{
Poco::SharedPtr<CUISetting> currentSelSetting = app->GetUISetting(strSettingName);
if (!currentSelSetting.isNull())
m_logger->SetActiveUISetting(currentSelSetting);
}
}
}
示例14: ShowTraces
void CLogAnalyzerView::ShowTraces(const CString& strComponent, BOOL bShowAll)
{
tstring strItemText = strComponent;
const std::map<tstring, Poco::SharedPtr<CComponent>>& components = m_logger->GetComponents();
std::map<tstring, Poco::SharedPtr<CComponent>>::const_iterator ite = components.find(strItemText);
if (ite != components.end())
{
const std::vector<Poco::SharedPtr<CTraceLog>>& traceLogs = ite->second->GetTraceLogs();
if (bShowAll)
{
//Only show the traces you want in list control
m_traceList.DeleteAllTraceLog();
for (int i = 0; i < traceLogs.size(); ++i)
m_traceList.InsertTraceLog(traceLogs.at(i));
}
//Show all traces and go to the first trace log that fits to you want
else
{
Poco::SharedPtr<CUISetting> uiSetting = m_logger->GetActiveUISetting();
int nColumn = 0;
int nCurSel = m_comboColumns.GetCurSel();
if (nCurSel == 0)
nColumn = -1; //All
else
{
CString strItem;
m_comboColumns.GetLBText(nCurSel, strItem);
tstring strItemValue = strItem.GetBuffer(strItem.GetLength());
if (!uiSetting.isNull())
{
for (int i = 0; i < uiSetting->GetAllColumns().size(); ++i)
{
if (strItemValue == uiSetting->GetAllColumns().at(i)->m_strRealColumnName)
{
nColumn = i;
break;
}
}
}
}
m_traceList.SearchText(nColumn, m_strFindContent.GetBuffer(m_strFindContent.GetLength()), m_bMatchCase);
}
m_strCurrentPage.Format("%d", m_traceList.GetCurrentPage());
m_strTraceCount.Format("Total : %d", m_traceList.GetCount());
UpdateData(FALSE);
}
}
示例15: testCursorRequest
void MongoDBTest::testCursorRequest()
{
if (!_connected)
{
std::cout << "Not connected, test skipped." << std::endl;
return;
}
Poco::MongoDB::Database db("team");
Poco::SharedPtr<Poco::MongoDB::InsertRequest> insertRequest = db.createInsertRequest("numbers");
for(int i = 0; i < 10000; ++i)
{
Document::Ptr doc = new Document();
doc->add("number", i);
insertRequest->documents().push_back(doc);
}
_mongo.sendRequest(*insertRequest);
double count = db.count(_mongo, "numbers");
assert(count == 10000);
Poco::MongoDB::Cursor cursor("team", "numbers");
int n = 0;
Poco::MongoDB::ResponseMessage& response = cursor.next(_mongo);
while(1)
{
n += response.documents().size();
if ( response.cursorID() == 0 )
break;
response = cursor.next(_mongo);
}
std::cout << "n= " << n << std::endl;
assert(n == 10000);
Poco::MongoDB::QueryRequest drop("team.$cmd");
drop.setNumberToReturn(1);
drop.selector().add("drop", std::string("numbers"));
Poco::MongoDB::ResponseMessage responseDrop;
_mongo.sendRequest(drop, responseDrop);
if ( responseDrop.documents().size() > 0 )
{
std::cout << responseDrop.documents()[0]->toString(2) << std::endl;
}
}