trantor::InetAddress inetInfo("127.0.0.1", 1102);
auto socketClient =
trantor::TcpClient(trantor::EventLoop::getEventLoopOfCurrentThread(), inetInfo, "kick-ass-gamer");
try {
socketClient.setConnectionCallback([](const trantor::TcpConnectionPtr &conn) {
if (conn->connected()) {
LOG_INFO << "connected to db";
} else {
LOG_ERROR << "connect to db failed";
}
});
socketClient.setConnectionErrorCallback([]() { LOG_DEBUG << "connect to db error"; });
socketClient.connect();
const auto connPtr = socketClient.connection();
if (!connPtr) {
throw std::runtime_error("Connect to db failed #" + std::to_string(server.getValueOfId()));
}
// connPtr->send(reinterpret_cast<const char *>(&packets[0]), packets.size());
socketClient.disconnect();
} catch (const std::exception &e) {
LOG_ERROR << e.what();
}
socketClient.stop();
Hello, all !
I'm trying to send a request to a Keycloak thanks to an HttpRequest, created with newHttpFormPostRequest() (as Keycloak only accept content type: application/x-www-form-urlencoded).
I'm getting an error /home/user/drogon/lib/src/HttpRequestImpl.cc:313: void drogon::HttpRequestImpl::appendToBuffer(trantor::MsgBuffer*) const: Assertion !(!content.empty() && !content_.empty()) failed.
What should I do ?
Also, for this type of request, should I fill my form entries thanks to the setParameter() method or thanks to the setBody() ? It seems that x-www-form-urlencoded requests puts everything in the Body.
Thanks a lot for your answers !
lib/inc/drogon/plugins
MoviesPlugin
and I would use this plugin as a service that would interact with ORM.Movie
, MoviesPlugin
and MoviesController
Hi, i have a problem with dbClient creation. When i try to use different host than 127.0. 0.1 on run time says "Socket fd < 0, Usually this is because the number of files opened by the program exceeds the system limit. Please use the ulimit command to check. - PgConnection.cc:71"
"db_clients": [
{
//name:Name of the client,'default' by default
//"name":"",
//rdbms:server type, "postgreSQL" by default
"rdbms": "postgresql",
//host:server address,localhost by default
"host": "drogondb.do",
//port:server port, 5432 by default
"port": 5432,
//dbname:Database name
"dbname": "hello_world",
//user:'postgres' by default
"user": "benchmarkdbuser",
//passwd:'' by default
"passwd": "benchmarkdbpass",
//is_fast: false by default, if it is true, the client is faster but user can't call
//any synchronous interface of it.
"is_fast": true,
//connection_number:1 by default
"connection_number": 1,
"auto_batch": false
}
i'am using this config, what i'm missing?
Hello, I've followed the windows installation instructions. I setup a project using dragon_ctl. I'm using VS2019 with C++ 20
I'm getting a linker error when calling into certain functions like drogon::getVersion()
or HttpResponse::getBody()
Error LNK2019 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl drogon::getVersion(void)" (?getVersion@drogon@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function main
I've also tried using C++14 and boost and got the same linker error.
I have added the following to the path environment variables: vcpkg\installed\x64-windows\bin
, lib
and include
I noticed a similar issue is open currently: drogonframework/drogon#1202
Does anyone have any ideas about how to fix this?
Hello, I need to introduce some classes in my project as utility classes to be invoked later in my controllers in Drogon.
I guess I can implement them as plugins (although there's a base class (DivisionsQueryBuilder at a specific namespace) which only has pure virtual functions), even if their initAndStart() function won't actually do anything yet.
What is the best practice in this case ?
In fact, I need to instantiate a class that builds me a query according to the parameters it's being given (dynamic query building).
For a specific type (hotel), it instantiates HotelDivisionsQueryBuilder (which extends DivisionsQueryBuilder and implements pure virtual function virtual std::string_view buildQuery(...))
Is there any suggested best practice on where to put the files (certainly not in the controllers, views, or the filters folders) and if it's clean and legit to create them as plugins ?
Note that this supposedly created "plugin" will be doing nothing, until buildQuery is invoked.
If the suggested solution is to use HotelDivisionsQueryBuilder as plugin, is it also mandatory that its parent class DivisionsQueryBuilder also be a plugin ?
Hello, I need to introduce some classes in my project as utility classes to be invoked later in my controllers in Drogon.
I guess I can implement them as plugins (although there's a base class (DivisionsQueryBuilder at a specific namespace) which only has pure virtual functions), even if their initAndStart() function won't actually do anything yet.
What is the best practice in this case ?
In fact, I need to instantiate a class that builds me a query according to the parameters it's being given (dynamic query building).
For a specific type (hotel), it instantiates HotelDivisionsQueryBuilder (which extends DivisionsQueryBuilder and implements pure virtual function virtual std::string_view buildQuery(...))Is there any suggested best practice on where to put the files (certainly not in the controllers, views, or the filters folders) and if it's clean and legit to create them as plugins ?
Note that this supposedly created "plugin" will be doing nothing, until buildQuery is invoked.If the suggested solution is to use HotelDivisionsQueryBuilder as plugin, is it also mandatory that its parent class DivisionsQueryBuilder also be a plugin ?
You can think of drogon's plugin as a singleton implementation that can be configured and loaded at runtime.
preRouting advice
to drogon