Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 09:02
    lganzzzo commented #448
  • 04:46
    bamkrs milestoned #448
  • 04:46
    bamkrs labeled #448
  • 04:44
    bamkrs commented #448
  • Jul 27 22:06
    LaurentBergeron edited #48
  • Jul 27 22:05
    LaurentBergeron edited #448
  • Jul 27 22:04
    LaurentBergeron commented #417
  • Jul 27 22:03
    LaurentBergeron commented #417
  • Jul 27 22:01
    LaurentBergeron opened #48
  • Jul 27 21:56
    LaurentBergeron opened #448
  • Jul 27 19:02
    lenikur commented #447
  • Jul 27 18:56
    bamkrs commented #447
  • Jul 27 18:53
    bamkrs commented #447
  • Jul 27 18:08
    lenikur opened #447
  • Jul 26 11:58
    lenikur closed #446
  • Jul 26 11:58
    lenikur commented #446
  • Jul 25 23:31
    lganzzzo labeled #47
  • Jul 25 23:29
    lganzzzo commented #190
  • Jul 25 23:26
    lganzzzo commented #190
  • Jul 25 23:24
    lganzzzo commented #190
oat++
@oatpp_io_twitter

Hey @acidtonic ,

Please post some code - I don't completely understand what happens and where is the race condition.
Also, please note - that all of the endpoints - are expected to run simultaneously in different threads (if multiple clients connect).
So you have to plan endpoints' resources accordingly.

Zach
@acidtonic

It's simple really, the destructors must run or the file isn't always synced to the disk in time if inside that handler, a disk scan to find the file is done. This is quite normal as you aren't using fdset or equiv to turn off write caching, I just needed to find a way to make sure it was flushed and normally I'd get the underlying descriptor, close it or flush it, then I'm good to go. I just couldn't figure out how to do that with your stream class as it lacks a close method and instead does that in it's destructor.

A second fix would have been to just call the filesystem sync system call but that would wait for all write-caching rather than a single-files descriptor which in some cases of heavy server use would take far too long to return than desired. I fixed it by making sure all oatpp multipart/stream classes were destructed in an extra scope block, that called close when I wanted and all is good.

so in your example for multipart, just throw the whole thing inside a spare {} block and that achieves closing the stream so it can be flushed.
Zach
@acidtonic

OATPP_LOGD seems non-linear with regards to ordering output. Not sure if it's in the design goals or not so I can't say it's a bug or not....

Unit test has a client calling server endpoints in a loop uploading chunks of a split file in order. Each chunk same size sequentially uploaded. Fewer chunks than cores so no thread blocking server-side. The OATPP_LOGD entries appear but sometimes out of order. Some logger designs require stdout to not have multiple threads stepping on each other, but other designs go farther and have a dedicated log printing thread with a strongly-ordered mutex locked queue such that timeline linearity is preserved. Not sure the design here...

Zach
@acidtonic
Are there any adapters or example of using ostream and istream with oatpp BufferInput/OutputStream?
Zach
@acidtonic
stuck getting binary data to multipart if read from my own stream classes. Constructor for StrBuffer createFromCString can't take size so isn't suitable for binary data....
oatpp::data::stream::transfer doesn't seem to accept non-oatpp stream classes if I try transfering to BufferOutputStream
I specifically want to avoid the filesystem and FileInputStream, not sure the best way to get it over from memory
write() method on the stream classes seem to require a 3rd argument AsyncAction and it's protected when I tried to manually write my buffer... Appreciate any advice there.
Zach
@acidtonic
Not sure if this is elegant but it works...
std::ifstream ifs( file_to_read );
std::unique_ptr<char[]> buffer(new char[chunk_size * num_reads_expected);
ifs.read(buffer.get(), chunk_size);
//... more ifs reads
part->setDataInfo( std::make_shared<oatpp::data::stream::BufferInputStream>( oatpp::String( buffer.get(), ifs.gcount() ) ) );
Zach
@acidtonic
(I would use FileInputStream, but I have to pass the inputstream to other apis that require std::istream before I get it back and the whole file is not read but rather seeked and skipped around)
oat++
@oatpp_io_twitter
Hey @acidtonic

The OATPP_LOGD entries appear but sometimes out of order. Some logger designs require stdout to not have multiple threads stepping on each other, but other designs go farther and have a dedicated log printing thread with a strongly-ordered mutex locked queue such that timeline linearity is preserved. Not sure the design here...

The default oatpp Logger (which you can override with your own) does all the printings under the mutex.
All of the OATPP_LOGX params should are processed in order.
If you see a different behavior - we have to understand why it's happening.
Sometimes (on some platforms) weird things can happen when the integer/float parameters size does not match the %d, %llu, etc. params.
For example when printing a variable of type char where %llu was expected

oat++
@oatpp_io_twitter
stuck getting binary data to multipart if read from my own stream classes. Constructor for StrBuffer createFromCString can't take size so isn't suitable for binary data....
auto buffer = coatpp::base::StrBuffer::reateShared(data, size, true);
oat++
@oatpp_io_twitter

oatpp::data::stream::transfer doesn't seem to accept non-oatpp stream classes if I try transfering to BufferOutputStream

oatpp::data::stream::transfer accepts ReadCallback and WriteCallback which are simple interfaces:

class MyWriteCallback : public oatpp::data::stream::WriteCallback {
public:

   v_io_size write(const void *data, v_buff_size count, async::Action& action) override {
     // ignore action if using Simple API
     // TODO - write(data, count);
   }

};

class MyReadCallback : public oatpp::data::stream::ReadCallback {
public:

   v_io_size read(void *buffer, v_buff_size count, async::Action& action) override {
     // ignore action if using Simple API
     // TODO - read(data, count);
   }

};
@acidtonic , please let me know if you have more questions
Claudio Barca
@clabnet
@oatpp_io_twitter
You say : The default oatpp Logger (which you can override with your own) does all the printings under the mutex.
I know this is a forum for oatpp, but I would add spdlog into my oatpp project, because I don't find mutch documentation on oatpp.logger.
How to add spdlog (or other logger platform) on oatpp proj ? Thank's
oat++
@oatpp_io_twitter

Hello @clabnet ,

All calls to OATPP_LOGX go through the logger that is set in oatpp::base::Environment.
Just init env with your custom logger.

class MyLogger : public oatpp::base::Logger {
public:
  void log(v_int32 priority, const std::string& tag, const std::string& message) override {
     std::cout << "MyCustomLog - " << message << std::endl;
    // TODO - change std::cout to whatever 
  }
};

...

oatpp::base::Environment::init(std::make_shared<MyLogger>());
Thus you can log to any output/file/logger/etc.
alex-wakizashi
@alex-wakizashi
Hello, all,
Could someone, please, advice - how to annotate with oatpp-swagger not just a DTO field (there is macro DTO_FIELD_INFO), but whole DTO (add OpenAPI schema description)?
oat++
@oatpp_io_twitter

Hello @alex-wakizashi ,

You can do it with the response/request description on the endpoint:

  ENDPOINT_INFO(createUser) {
    info->summary = "Create new User";

    info->addConsumes<Object<UserDto>>("application/json", "Consumes DTO-description");
    info->addResponse<Object<UserDto>>(Status::CODE_200, "application/json", "Response DTO description");

  }
  ENDPOINT("POST", "users", createUser,
           BODY_DTO(Object<UserDto>, userDto))
  {
    ...
  }
However no DTO specific descriptions like the annotation for the DTO itself is supported in oatpp currently
Zach
@acidtonic
Hey thanks for the help, @oatpp_io_twitter
alex-wakizashi
@alex-wakizashi
Thanks, @oatpp_io_twitter, for answer, but question was exactly about description of DTO itself, not response/request. Is there any plans to add such a thing? I'm new with oatpp, so not able to add it myself yet. Maybe later...
Zach
@acidtonic
@alex-wakizashi In my case annotating the DTO is not needed, swagger shows it at the bottom with the openapi definition of min/max and cardinality details. You can however annotate path/query params which in most cases are the import id fields or query-specific things that you would want to have annotations for....
Claudio Barca
@clabnet
@oatpp_io_twitter thanks
oat++
@oatpp_io_twitter
Hey @alex-wakizashi , please file an issue on Github for that issue. Also please put a link there to an open-api spec for that feature.
alex-wakizashi
@alex-wakizashi
@oatpp_io_twitter Hmmm... Examples both for Swagger and OpenAPI have that field for schema objects (Look for "4.8.24.3.6 Models with Polymorphism Support") - but looks like it's optional. In specs these are in the list below"The following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification." (Swagger). And in OpenAPI it's at "4.8.24.1 Properties"
alex-wakizashi
@alex-wakizashi
Hello, @oatpp_io_twitter, done: issue #47 for oatpp-swagger .
oat++
@oatpp_io_twitter
@alex-wakizashi , thanks!
arnobbhanja
@arnobbhanja
Hi, I just started learning oatpp and I was trying to add some tests for my poject but unable to register the controller to runner. I'm using visual studio 2019 and the exception is related to "unable to deference end list iterator". Has anybody faced this before?
the exception occurs while registering the endpoints
oat++
@oatpp_io_twitter

Hello @arnobbhanja ,

Are you able to run tests in this example project? - https://github.com/oatpp/example-crud

I'm trying to understand if it's your project which is misconfigured or if it's something else.
Zach
@acidtonic
while iterating a mixed multipart reader (some parts in memory, others in disk) is there a way to know which is which so I can determine which to use InMemoryData() on?
Zach
@acidtonic
safe to just use getKnownSize() > 0?
Sandro S. Andrade
@sandroandrade_gitlab
Hi there. I'm trying to create a wrapper DTO type containing a DTO field with type oatpp::Vector<oatpp::Object<X>>, where X is any oatpp::DTO descendant type. Apparently X cannot be a pointer or reference, therefore polymorphic types wouldn't work. I've tried the Any type with no success. Any hint?
junyama
@junyama

I'm trying to include WebSocket function to my custom code based on example-websocket/server. I want to modify WSListener.cpp as follows:

void WSListener::readMessage(const WebSocket& socket, v_uint8 opcode, p_char8 data, oatpp::v_io_size size) {

  if(size == 0) { // message transfer finished

        auto wholeMessage = m_messageBuffer.toString();
        m_messageBuffer.clear();

        OATPP_LOGD(TAG, "onMessage message='%s'", wholeMessage->c_str());

         myClassInstancePoniter->memberFunction();  //<--------- want to call a member function constructed by MyController

        /* Send message in reply */
        socket.sendOneFrameText( "Hello from oatpp!: " + wholeMessage);

I understand that I need to define myClassInstancePoniter as a member variable of WSListener class, but I do not know how to set a value of myClassInstancePoniter , because it is not visible where WSListener class is constructed.

Thank you for your help in advance.

oat++
@oatpp_io_twitter

Hey @acidtonic ,

safe to just use getKnownSize() > 0?

Yes

Hey @sandroandrade_gitlab ,

Hi there. I'm trying to create a wrapper DTO type containing a DTO field with type oatpp::Vector<oatpp::Object<X>>, where X is any oatpp::DTO descendant type. Apparently X cannot be a pointer or reference, therefore polymorphic types wouldn't work. I've tried the Any type with no success. Any hint?

This will work for Serialization but not for Deserialization.
At the moment there is no mechanism to deserialize such data

Hey @junyama ,
Just pass myClassInstancePoniter as a parameter to constructor of WSListener
mmjvox
@mmjvox
how to connect to websocket server on browsers or other libraries?
i tried to connect with qt websocket as a client to oat++ websocket server but didn't work.
oat++
@oatpp_io_twitter

Hello @mmjvox ,

Try the following:

alex-wakizashi
@alex-wakizashi

Hello,
Could somebody, please, advise - how to define constructor for DTO?
I need DTO object to be created with specific field as mandatory one.

Also, don't see any annotation/macro/etc. to mark DTO field as unique for ORM.
Is it specific for DB initialization only? (Sorry for stupid question, came from Hybernate, which is quite different, and uses annotations/reflections).

oat++
@oatpp_io_twitter

Hey @alex-wakizashi ,

Could somebody, please, advise - how to define constructor for DTO?

Same as for any other class:

class MyDto : public oatpp::DTO {
  ...
  OATPP_FIELD(String, name);

public:

  MyDto(const String& pname)
    : name(pname)
  {}

};

...

auto myDto = MyDto::createShared("oatpp");

Also, don't see any annotation/macro/etc. to mark DTO field as unique for ORM.
Is it specific for DB initialization only? (Sorry for stupid question, came from Hybernate, which is quite different, and uses annotations/reflections).

Oat++ ORM doesn't define the DB structure. It works with the already existing DB model.
Keep all the constraints in the DDL

Like in the example-crud: