这两个代码示例是否相同?
Poco::ProcessHandle::PID ProcessRunner::processId() const
{
Poco::ProcessHandle::PID pid = 0;
mMutex.lock();
pid = mPID;
mMutex.unlock();
return pid;
}
Run Code Online (Sandbox Code Playgroud)
,
Poco::ProcessHandle::PID ProcessRunner::processId() const
{
Poco::ScopedLock<Poco::Mutex> lock(mMutex);
return mPID;
}
Run Code Online (Sandbox Code Playgroud)
在我的测试代码中看起来像线程安全.我可以Poco::Logger在多线程程序中使用吗?
static Poco::Logger *pLogger;
class MyRunnable : public Poco::Runnable {
private:
std::string _name;
Poco::Random _rnd;
public:
void setName(std::string name) {
_name = name;
}
void run() {
for (int i=0; i<200; i++) {
pLogger->information("info from: " + _name);
_rnd.seed(_rnd.next(65532) * _name.size());
Poco::Thread::sleep(_rnd.next(13) + 1);
}
}
};
Run Code Online (Sandbox Code Playgroud)
这里是测试主要:
int
main ( int argc, char *argv[] )
{
Poco::Thread thr1, thr2, thr3;
MyRunnable *pMyR1 = new MyRunnable(),
*pMyR2 = new MyRunnable(),
*pMyR3 = new MyRunnable();
pMyR1->setName("r1");
pMyR2->setName("ra2");
pMyR3->setName("runable3");
Poco::FormattingChannel …Run Code Online (Sandbox Code Playgroud) 使用Logging Framework时我遇到了一些问题.我有一个配置文件如下:
# core channel
logging.channels.c1.class = FileChannel
logging.channels.c1.path = <somePath>/core.log
logging.channels.c1.archive = timestamp
logging.channels.c1.times = utc
logging.channels.c1.rotation = daily
logging.channels.c1.formatter.class = PatternFormatter
logging.channels.c1.formatter.pattern = %Y-%m-%d %H:%M:%S %s: [%p] %t
# core logger
logging.loggers.l1.name = core
logging.loggers.l1.level = information
logging.loggers.l1.channel = c1
Run Code Online (Sandbox Code Playgroud)
我的程序使用Poco :: Util:ServerApplication框架,受益于子系统架构.我有多个子系统,每个子系统都存储一个Poco :: Logger对象的引用,该对象是使用Poco :: Logger :: get("logger name")方法获得的.我正在尝试使用日志层次结构,具有"核心"日志,如上面的配置文件中所示,作为我的日志记录层次结构的根.以下代码举例说明了我在每个susbsystem中所做的事情:
Subsystem1::Subsystem1() :
Poco::Util::Subsystem(),
logger_(Poco::Logger::get("core." + std::string(name()))),
...
Subsystem2::Subsystem2() :
Poco::Util::Subsystem(),
logger_(Poco::Logger::get("core." + std::string(name()))),
...
Run Code Online (Sandbox Code Playgroud)
这适用于日志记录.这很好,因为我从属性文件继承了配置,每个子系统都有一个不同的Poco :: Message源名称,这样就可以很容易地识别日志条目来自哪个子系统.
当我尝试更改记录器实例的属性时(例如,从Subsystem1的记录器),问题就出现了.例如,如果我更改了它的通道路径,则更改将传播到整个层次结构.以下代码演示了此问题:
Poco::Logger& subsystem1Logger = Poco::Logger::get("core.Subsystem1");
Poco::Logger& subsystem2Logger = Poco::Logger::get("core.Subsystem2");
subsystem1Logger.getChannel()->close(); //without …Run Code Online (Sandbox Code Playgroud) 我有一个嵌套的JSON对象.我正在尝试在函数中构建它并将内部对象添加到原始对象中,但我无法提取结果.
void build_object (Poco::JSON::Object * const result)
{
/* Construct some int/bool/string fields here */
Poco::JSON::Object inner;
inner.set("some_number", 5);
inner.set("some_string", "xyz");
/* This is where it breaks down */
std::string key = "new_object";
result->set("new_object", inner);
/* Then some debugging and testing */
// The new object is printed inside the first -> seems like it's working
result->stringify(std::cout);
printf("result has(key): %i\n", result->has(key)); // true
printf("isObject: %i\n", result->isObject(key)); // false - huh?
printf("isNull: %i\n", result->isNull(key)); // false
printf("isArray: %i\n", result->isArray(key)); // false …Run Code Online (Sandbox Code Playgroud) 我正在与第三方库(Poco C ++)链接,并从链接器中收到以下未解决的符号错误。它似乎找不到“ CryptAcquireContextW”,“ CryptReleaseContext”和“ CryptGenRandom”。
根据此处的Microsoft信息,可以使用“ Advapi32.lib”链接这些功能。我已将其添加到链接器输入中,但符号仍未解析。
1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptAcquireContextW@20 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)
1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptReleaseContext@8 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)
1>PocoFoundationCLR.lib(RandomStream.obj) : error LNK2019: unresolved external symbol __imp__CryptGenRandom@12 referenced in function "public: virtual int __thiscall Poco::RandomBuf::readFromDevice(char *,__int64)" (?readFromDevice@RandomBuf@Poco@@UAEHPAD_J@Z)
Run Code Online (Sandbox Code Playgroud)
我已经确认Advapi32.lib在搜索路径上,而Advapi32.dll在Windows目录中,所以我不确定该错误如何继续发生。
想法,有人吗?
谢谢!
我正在尝试链接到POCO C++库的静态版本,如下所示:
g++ BCCMain.o -L$_POCO_LIBS -Wl,-Bstatic $_POCO_LIBS/libPocoFoundation.a $_POCO_LIBS/libPocoUtil.a $_POCO_LIBS/libPocoXML.a $_POCO_LIBS/libPocoJSON.a -Wl,-Bdynamic -o BCMain
Run Code Online (Sandbox Code Playgroud)
不幸的是,这给出了一些对符号的未定义引用的错误,例如:
Poco::Logger::get(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
Run Code Online (Sandbox Code Playgroud)
即使Poco::Logger::get(std::string const&)实际上是IS定义的libPocoFoundation.a.
现在,如果我尝试链接到基础库的共享版本,它可以工作:
g++ BCCMain.o -L$_POCO_LIBS -Wl,-Bstatic $_POCO_LIBS/libPocoFoundation.a $_POCO_LIBS/libPocoUtil.a $_POCO_LIBS/libPocoXML.a $_POCO_LIBS/libPocoJSON.a -Wl,-Bdynamic -lPocoFoundation -o BCMain
Run Code Online (Sandbox Code Playgroud)
lib的静态和共享版本具有相同的符号,因此我发现很难弄清楚我做错了什么.
Ubuntu的/ Linaro的.g ++ 4.6.3
我正在尝试使用Poco C++ 库连接到Echo Test Websocket。为此,我的代码应设置 Websocket:
HTTPClientSession cs("echo.websocket.org");
HTTPRequest request(HTTPRequest::HTTP_GET, "/ws");
HTTPResponse response;
WebSocket* m_psock = new WebSocket(cs, request, response);
m_psock->close(); //close immidiately
Run Code Online (Sandbox Code Playgroud)
但是它不起作用:我收到如下错误消息:
Poco::Exception: WebSocket Exception: Cannot upgrade to WebSocket connection: Not Found
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我想知道如何用C++中的POCO对URL进行请求(例如下载图片并保存)?
到目前为止,我得到了这个小代码
#include <iostream>
#include <string>
#include "multiplication.h"
#include <vector>
#include <HTTPRequest.h>
using std::cout;
using std::cin;
using std::getline;
using namespace Poco;
using namespace Net;
int main() {
HTTPRequest *test = new HTTPRequest("HTTP_GET", "http://www.example.com", "HTTP/1.1");
}
Run Code Online (Sandbox Code Playgroud) 我一直在研究如何做到这一点,所有的例子都是text/html.我已经尝试使用带有POCO C++网络库的JSON实现服务器api休息,但我不确定这是否是正确的方法.
void MyHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setStatus(HTTPResponse::HTTP_OK);
response.setContentType("application/json");
std::ostream& ostr = response.send();
string send("true");
ostr << send;
response.setContentLength(send.size());
}
Run Code Online (Sandbox Code Playgroud)
最初它是为hmtl连接实现的:
void MyHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setStatus(HTTPResponse::HTTP_OK);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
ostr << "ConfigHandler";
ostr << "</p></body></html>";
}
Run Code Online (Sandbox Code Playgroud)
我是否正确地完成了更改或者我错过了什么?
如果有人知道如何使用带有POCO C++库的JSON构建API REST的教程,我们将非常感激.
提前致谢.
我正在开发一个 http 服务器,作为我的 C++ 应用程序的一部分,基于 Poco::Net HTTP。它非常简单,使用Poco::Net::HTTPServer,然后Poco::Net::HTTPRequestHandler使用子类,实现void handleRequest(Poco::Net::HTTPServerRequest &req, Poco::Net::HTTPServerResponse &resp). 在这种方法中,进程可能会变得耗时,甚至在某些情况下可能会无休止地运行。
浏览器通过 ajax 请求 ( ) 从 Web 应用程序内部使用这些服务器XMLHttpRequest,有时还abort()通过这些请求(这会关闭连接?!)。
如何检测内部的这种情况handleRequest(...)以便停止处理?
顺便说一句:我确实需要这种流程。关于不同的、可能是异步的方式(例如传递数据)的建议将不起作用。如果 Poco 做不到,我就必须更换它。
文档和一些实验都没有Poco::Net::HTTPServerRequest帮助Poco::Net::HTTPServerResponse我。
poco-libraries ×10
c++ ×9
http ×2
json ×2
advapi32 ×1
connection ×1
logging ×1
mutex ×1
request ×1
rest ×1
visual-c++ ×1
websocket ×1
winapi ×1