os::io::Library class removed

This commit is contained in:
lganzzzo 2019-02-07 02:53:33 +02:00
parent 1db5dc2296
commit c4dfd04505
45 changed files with 342 additions and 333 deletions

View File

@ -46,6 +46,7 @@ add_library(oatpp
oatpp/core/concurrency/SpinLock.hpp
oatpp/core/concurrency/Thread.cpp
oatpp/core/concurrency/Thread.hpp
oatpp/core/data/IODefinitions.hpp
oatpp/core/data/buffer/FIFOBuffer.cpp
oatpp/core/data/buffer/FIFOBuffer.hpp
oatpp/core/data/buffer/IOBuffer.cpp
@ -75,8 +76,6 @@ add_library(oatpp
oatpp/core/macro/basic.hpp
oatpp/core/macro/codegen.hpp
oatpp/core/macro/component.hpp
oatpp/core/os/io/Library.cpp
oatpp/core/os/io/Library.hpp
oatpp/core/parser/ParsingCaret.cpp
oatpp/core/parser/ParsingCaret.hpp
oatpp/core/utils/ConversionUtils.cpp

View File

@ -22,26 +22,50 @@
*
***************************************************************************/
#ifndef oatpp_os_io_Library_hpp
#define oatpp_os_io_Library_hpp
#ifndef oatpp_data_IODefinitions_hpp
#define oatpp_data_IODefinitions_hpp
#include "oatpp/core/base/Environment.hpp"
#include "oatpp/core/Types.hpp"
namespace oatpp { namespace data {
typedef int v_io_handle;
/**
* All I/O buffer operations (like read/write(buffer, size)) should return
* v_io_size.
*
* Possible return values:
* On Success - [0..max_int64]
* On Error - IOError values.
*
* All other values are considered to be a fatal error.
* application should be terminated.
*/
typedef v_int64 v_io_size;
enum IOError : v_io_size {
/**
* I/O operation is not possible any more
* Client should give up trying and free all related resources
*/
BROKEN_PIPE = -1001,
/**
* I/O operation was interrupted because of some reason
* Client may retry immediately
*/
RETRY = -1002,
/**
* I/O operation is not currently available due to some reason
* Client should wait then retry
*/
WAIT_RETRY = -1003
namespace oatpp { namespace os { namespace io {
class Library{
public:
typedef v_int32 v_handle;
typedef ssize_t v_size;
public:
static v_int32 handle_close(v_handle handle);
static v_size handle_read(v_handle handle, void *buf, v_size count);
static v_size handle_write(v_handle handle, const void *buf, v_size count);
};
}}}
#endif /* oatpp_os_io_Library_hpp */
}}
#endif //oatpp_data_IODefinitions_hpp

View File

@ -26,7 +26,7 @@
namespace oatpp { namespace data{ namespace buffer {
os::io::Library::v_size FIFOBuffer::availableToRead() {
data::v_io_size FIFOBuffer::availableToRead() {
oatpp::concurrency::SpinLock lock(m_atom);
if(!m_canRead) {
return 0;
@ -37,7 +37,7 @@ os::io::Library::v_size FIFOBuffer::availableToRead() {
return (IOBuffer::BUFFER_SIZE - m_readPosition + m_writePosition);
}
os::io::Library::v_size FIFOBuffer::availableToWrite() {
data::v_io_size FIFOBuffer::availableToWrite() {
oatpp::concurrency::SpinLock lock(m_atom);
if(m_canRead && m_writePosition == m_readPosition) {
return 0;
@ -48,7 +48,7 @@ os::io::Library::v_size FIFOBuffer::availableToWrite() {
return (IOBuffer::BUFFER_SIZE - m_writePosition + m_readPosition);
}
os::io::Library::v_size FIFOBuffer::read(void *data, os::io::Library::v_size count) {
data::v_io_size FIFOBuffer::read(void *data, data::v_io_size count) {
oatpp::concurrency::SpinLock lock(m_atom);
@ -99,7 +99,7 @@ os::io::Library::v_size FIFOBuffer::read(void *data, os::io::Library::v_size cou
}
os::io::Library::v_size FIFOBuffer::write(const void *data, os::io::Library::v_size count) {
data::v_io_size FIFOBuffer::write(const void *data, data::v_io_size count) {
oatpp::concurrency::SpinLock lock(m_atom);

View File

@ -27,7 +27,7 @@
#include "./IOBuffer.hpp"
#include "oatpp/core/concurrency/SpinLock.hpp"
#include "oatpp/core/os/io/Library.hpp"
#include "oatpp/core/data/IODefinitions.hpp"
namespace oatpp { namespace data{ namespace buffer {
@ -37,8 +37,8 @@ public:
SHARED_OBJECT_POOL(Shared_FIFOBuffer_Pool, FIFOBuffer, 32)
private:
bool m_canRead;
os::io::Library::v_size m_readPosition;
os::io::Library::v_size m_writePosition;
data::v_io_size m_readPosition;
data::v_io_size m_writePosition;
IOBuffer m_buffer;
oatpp::concurrency::SpinLock::Atom m_atom;
public:
@ -54,13 +54,17 @@ public:
return Shared_FIFOBuffer_Pool::allocateShared();
}
os::io::Library::v_size availableToRead();
os::io::Library::v_size availableToWrite();
data::v_io_size availableToRead();
data::v_io_size availableToWrite();
os::io::Library::v_size read(void *data, os::io::Library::v_size count);
os::io::Library::v_size write(const void *data, os::io::Library::v_size count);
data::v_io_size read(void *data, data::v_io_size count);
data::v_io_size write(const void *data, data::v_io_size count);
};
class SynchronizedFIFOBuffer : public FIFOBuffer {
};
}}}

View File

@ -30,10 +30,10 @@ const char* ChunkedBuffer::ERROR_ASYNC_FAILED_TO_WRITE_ALL_DATA = "ERROR_ASYNC_F
const char* const ChunkedBuffer::CHUNK_POOL_NAME = "ChunkedBuffer_Chunk_Pool";
const os::io::Library::v_size ChunkedBuffer::CHUNK_ENTRY_SIZE_INDEX_SHIFT = 11;
const os::io::Library::v_size ChunkedBuffer::CHUNK_ENTRY_SIZE =
const data::v_io_size ChunkedBuffer::CHUNK_ENTRY_SIZE_INDEX_SHIFT = 11;
const data::v_io_size ChunkedBuffer::CHUNK_ENTRY_SIZE =
(1 << ChunkedBuffer::CHUNK_ENTRY_SIZE_INDEX_SHIFT);
const os::io::Library::v_size ChunkedBuffer::CHUNK_CHUNK_SIZE = 32;
const data::v_io_size ChunkedBuffer::CHUNK_CHUNK_SIZE = 32;
ChunkedBuffer::ChunkEntry* ChunkedBuffer::obtainNewEntry(){
auto result = new ChunkEntry(getSegemntPool().obtain(), nullptr);
@ -51,10 +51,10 @@ void ChunkedBuffer::freeEntry(ChunkEntry* entry){
delete entry;
}
os::io::Library::v_size ChunkedBuffer::writeToEntry(ChunkEntry* entry,
data::v_io_size ChunkedBuffer::writeToEntry(ChunkEntry* entry,
const void *data,
os::io::Library::v_size count,
os::io::Library::v_size& outChunkPos) {
data::v_io_size count,
data::v_io_size& outChunkPos) {
if(count >= CHUNK_ENTRY_SIZE){
std::memcpy(entry->chunk, data, CHUNK_ENTRY_SIZE);
outChunkPos = 0;
@ -66,12 +66,12 @@ os::io::Library::v_size ChunkedBuffer::writeToEntry(ChunkEntry* entry,
}
}
os::io::Library::v_size ChunkedBuffer::writeToEntryFrom(ChunkEntry* entry,
os::io::Library::v_size inChunkPos,
data::v_io_size ChunkedBuffer::writeToEntryFrom(ChunkEntry* entry,
data::v_io_size inChunkPos,
const void *data,
os::io::Library::v_size count,
os::io::Library::v_size& outChunkPos) {
os::io::Library::v_size spaceLeft = CHUNK_ENTRY_SIZE - inChunkPos;
data::v_io_size count,
data::v_io_size& outChunkPos) {
data::v_io_size spaceLeft = CHUNK_ENTRY_SIZE - inChunkPos;
if(count >= spaceLeft){
std::memcpy(&((p_char8) entry->chunk)[inChunkPos], data, spaceLeft);
outChunkPos = 0;
@ -84,15 +84,15 @@ os::io::Library::v_size ChunkedBuffer::writeToEntryFrom(ChunkEntry* entry,
}
ChunkedBuffer::ChunkEntry* ChunkedBuffer::getChunkForPosition(ChunkEntry* fromChunk,
os::io::Library::v_size pos,
os::io::Library::v_size& outChunkPos) {
data::v_io_size pos,
data::v_io_size& outChunkPos) {
os::io::Library::v_size segIndex = pos >> CHUNK_ENTRY_SIZE_INDEX_SHIFT;
data::v_io_size segIndex = pos >> CHUNK_ENTRY_SIZE_INDEX_SHIFT;
outChunkPos = pos - (segIndex << CHUNK_ENTRY_SIZE_INDEX_SHIFT);
auto curr = fromChunk;
for(os::io::Library::v_size i = 0; i < segIndex; i++){
for(data::v_io_size i = 0; i < segIndex; i++){
curr = curr->next;
}
@ -100,7 +100,7 @@ ChunkedBuffer::ChunkEntry* ChunkedBuffer::getChunkForPosition(ChunkEntry* fromCh
}
os::io::Library::v_size ChunkedBuffer::write(const void *data, os::io::Library::v_size count){
data::v_io_size ChunkedBuffer::write(const void *data, data::v_io_size count){
if(count <= 0){
return 0;
@ -111,7 +111,7 @@ os::io::Library::v_size ChunkedBuffer::write(const void *data, os::io::Library::
}
ChunkEntry* entry = m_lastEntry;
os::io::Library::v_size pos = 0;
data::v_io_size pos = 0;
pos += writeToEntryFrom(entry, m_chunkPos, data, count, m_chunkPos);
@ -133,32 +133,32 @@ os::io::Library::v_size ChunkedBuffer::write(const void *data, os::io::Library::
}
os::io::Library::v_size ChunkedBuffer::readSubstring(void *buffer,
os::io::Library::v_size pos,
os::io::Library::v_size count) {
data::v_io_size ChunkedBuffer::readSubstring(void *buffer,
data::v_io_size pos,
data::v_io_size count) {
if(pos < 0 || pos >= m_size){
return 0;
}
os::io::Library::v_size countToRead;
data::v_io_size countToRead;
if(pos + count > m_size){
countToRead = m_size - pos;
} else {
countToRead = count;
}
os::io::Library::v_size firstChunkPos;
data::v_io_size firstChunkPos;
auto firstChunk = getChunkForPosition(m_firstEntry, pos, firstChunkPos);
os::io::Library::v_size lastChunkPos;
data::v_io_size lastChunkPos;
auto lastChunk = getChunkForPosition(firstChunk, firstChunkPos + countToRead, lastChunkPos);
os::io::Library::v_size bufferPos = 0;
data::v_io_size bufferPos = 0;
if(firstChunk != lastChunk){
os::io::Library::v_size countToCopy = CHUNK_ENTRY_SIZE - firstChunkPos;
data::v_io_size countToCopy = CHUNK_ENTRY_SIZE - firstChunkPos;
std::memcpy(buffer, &((p_char8)firstChunk->chunk)[firstChunkPos], countToCopy);
bufferPos += countToCopy;
@ -173,7 +173,7 @@ os::io::Library::v_size ChunkedBuffer::readSubstring(void *buffer,
std::memcpy(&((p_char8)buffer)[bufferPos], lastChunk->chunk, lastChunkPos);
} else {
os::io::Library::v_size countToCopy = lastChunkPos - firstChunkPos;
data::v_io_size countToCopy = lastChunkPos - firstChunkPos;
std::memcpy(buffer, &((p_char8)firstChunk->chunk)[firstChunkPos], countToCopy);
}
@ -181,15 +181,15 @@ os::io::Library::v_size ChunkedBuffer::readSubstring(void *buffer,
}
oatpp::String ChunkedBuffer::getSubstring(os::io::Library::v_size pos,
os::io::Library::v_size count){
oatpp::String ChunkedBuffer::getSubstring(data::v_io_size pos,
data::v_io_size count){
auto str = oatpp::String((v_int32) count);
readSubstring(str->getData(), pos, count);
return str;
}
bool ChunkedBuffer::flushToStream(const std::shared_ptr<OutputStream>& stream){
os::io::Library::v_size pos = m_size;
data::v_io_size pos = m_size;
auto curr = m_firstEntry;
while (pos > 0) {
if(pos > CHUNK_ENTRY_SIZE) {
@ -219,9 +219,9 @@ oatpp::async::Action ChunkedBuffer::flushToStreamAsync(oatpp::async::AbstractCor
std::shared_ptr<ChunkedBuffer> m_chunkedBuffer;
std::shared_ptr<OutputStream> m_stream;
ChunkEntry* m_currEntry;
os::io::Library::v_size m_bytesLeft;
data::v_io_size m_bytesLeft;
const void* m_currData;
os::io::Library::v_size m_currDataSize;
data::v_io_size m_currDataSize;
Action m_nextAction;
public:
@ -288,7 +288,7 @@ std::shared_ptr<ChunkedBuffer::Chunks> ChunkedBuffer::getChunks() {
return chunks;
}
os::io::Library::v_size ChunkedBuffer::getSize(){
data::v_io_size ChunkedBuffer::getSize(){
return m_size;
}

View File

@ -42,9 +42,9 @@ public:
static const char* const CHUNK_POOL_NAME;
static const os::io::Library::v_size CHUNK_ENTRY_SIZE_INDEX_SHIFT;
static const os::io::Library::v_size CHUNK_ENTRY_SIZE;
static const os::io::Library::v_size CHUNK_CHUNK_SIZE;
static const data::v_io_size CHUNK_ENTRY_SIZE_INDEX_SHIFT;
static const data::v_io_size CHUNK_ENTRY_SIZE;
static const data::v_io_size CHUNK_CHUNK_SIZE;
static oatpp::base::memory::ThreadDistributedMemoryPool& getSegemntPool(){
static oatpp::base::memory::ThreadDistributedMemoryPool pool(CHUNK_POOL_NAME,
@ -81,17 +81,17 @@ public:
SHARED_OBJECT_POOL(Shared_ChunkedBuffer_Chunk_Pool, Chunk, 32)
public:
Chunk(void* pData, os::io::Library::v_size pSize)
Chunk(void* pData, data::v_io_size pSize)
: data(pData)
, size(pSize)
{}
static std::shared_ptr<Chunk> createShared(void* data, os::io::Library::v_size size){
static std::shared_ptr<Chunk> createShared(void* data, data::v_io_size size){
return Shared_ChunkedBuffer_Chunk_Pool::allocateShared(data, size);
}
const void* data;
const os::io::Library::v_size size;
const data::v_io_size size;
};
@ -99,8 +99,8 @@ public:
typedef oatpp::collection::LinkedList<std::shared_ptr<Chunk>> Chunks;
private:
os::io::Library::v_size m_size;
os::io::Library::v_size m_chunkPos;
data::v_io_size m_size;
data::v_io_size m_chunkPos;
ChunkEntry* m_firstEntry;
ChunkEntry* m_lastEntry;
@ -109,20 +109,20 @@ private:
ChunkEntry* obtainNewEntry();
void freeEntry(ChunkEntry* entry);
os::io::Library::v_size writeToEntry(ChunkEntry* entry,
data::v_io_size writeToEntry(ChunkEntry* entry,
const void *data,
os::io::Library::v_size count,
os::io::Library::v_size& outChunkPos);
data::v_io_size count,
data::v_io_size& outChunkPos);
os::io::Library::v_size writeToEntryFrom(ChunkEntry* entry,
os::io::Library::v_size inChunkPos,
data::v_io_size writeToEntryFrom(ChunkEntry* entry,
data::v_io_size inChunkPos,
const void *data,
os::io::Library::v_size count,
os::io::Library::v_size& outChunkPos);
data::v_io_size count,
data::v_io_size& outChunkPos);
ChunkEntry* getChunkForPosition(ChunkEntry* fromChunk,
os::io::Library::v_size pos,
os::io::Library::v_size& outChunkPos);
data::v_io_size pos,
data::v_io_size& outChunkPos);
public:
@ -143,16 +143,16 @@ public:
return Shared_ChunkedBuffer_Pool::allocateShared();
}
os::io::Library::v_size write(const void *data, os::io::Library::v_size count) override;
data::v_io_size write(const void *data, data::v_io_size count) override;
os::io::Library::v_size readSubstring(void *buffer,
os::io::Library::v_size pos,
os::io::Library::v_size count);
data::v_io_size readSubstring(void *buffer,
data::v_io_size pos,
data::v_io_size count);
/**
* return substring of the data written to stream; NOT NULL
*/
oatpp::String getSubstring(os::io::Library::v_size pos, os::io::Library::v_size count);
oatpp::String getSubstring(data::v_io_size pos, data::v_io_size count);
/**
* return data written to stream as oatpp::String; NOT NULL
@ -168,7 +168,7 @@ public:
std::shared_ptr<Chunks> getChunks();
os::io::Library::v_size getSize();
data::v_io_size getSize();
void clear();
};

View File

@ -31,12 +31,12 @@ namespace oatpp { namespace data{ namespace stream {
class WriterDelegate {
public:
virtual os::io::Library::v_size writeToStream(const std::shared_ptr<OutputStream>& stream) = 0;
virtual data::v_io_size writeToStream(const std::shared_ptr<OutputStream>& stream) = 0;
};
class ReaderDelegate {
public:
virtual os::io::Library::v_size readFromStream(const std::shared_ptr<InputStream>& stream) = 0;
virtual data::v_io_size readFromStream(const std::shared_ptr<InputStream>& stream) = 0;
};
}}}

View File

@ -30,7 +30,7 @@ namespace oatpp { namespace data{ namespace stream {
const char* const Errors::ERROR_ASYNC_FAILED_TO_WRITE_DATA = "ERROR_ASYNC_FAILED_TO_WRITE_DATA";
const char* const Errors::ERROR_ASYNC_FAILED_TO_READ_DATA = "ERROR_ASYNC_FAILED_TO_READ_DATA";
os::io::Library::v_size OutputStream::writeAsString(v_int32 value){
data::v_io_size OutputStream::writeAsString(v_int32 value){
v_char8 a[100];
v_int32 size = utils::conversion::int32ToCharSequence(value, &a[0]);
if(size > 0){
@ -39,7 +39,7 @@ os::io::Library::v_size OutputStream::writeAsString(v_int32 value){
return 0;
}
os::io::Library::v_size OutputStream::writeAsString(v_int64 value){
data::v_io_size OutputStream::writeAsString(v_int64 value){
v_char8 a[100];
v_int32 size = utils::conversion::int64ToCharSequence(value, &a[0]);
if(size > 0){
@ -48,7 +48,7 @@ os::io::Library::v_size OutputStream::writeAsString(v_int64 value){
return 0;
}
os::io::Library::v_size OutputStream::writeAsString(v_float32 value){
data::v_io_size OutputStream::writeAsString(v_float32 value){
v_char8 a[100];
v_int32 size = utils::conversion::float32ToCharSequence(value, &a[0]);
if(size > 0){
@ -57,7 +57,7 @@ os::io::Library::v_size OutputStream::writeAsString(v_float32 value){
return 0;
}
os::io::Library::v_size OutputStream::writeAsString(v_float64 value){
data::v_io_size OutputStream::writeAsString(v_float64 value){
v_char8 a[100];
v_int32 size = utils::conversion::float64ToCharSequence(value, &a[0]);
if(size > 0){
@ -66,7 +66,7 @@ os::io::Library::v_size OutputStream::writeAsString(v_float64 value){
return 0;
}
os::io::Library::v_size OutputStream::writeAsString(bool value) {
data::v_io_size OutputStream::writeAsString(bool value) {
if(value){
return write("true", 4);
} else {
@ -117,16 +117,16 @@ const std::shared_ptr<OutputStream>& operator << (const std::shared_ptr<OutputSt
return s;
}
oatpp::os::io::Library::v_size transfer(const std::shared_ptr<InputStream>& fromStream,
oatpp::data::v_io_size transfer(const std::shared_ptr<InputStream>& fromStream,
const std::shared_ptr<OutputStream>& toStream,
oatpp::os::io::Library::v_size transferSize,
oatpp::data::v_io_size transferSize,
void* buffer,
oatpp::os::io::Library::v_size bufferSize) {
oatpp::data::v_io_size bufferSize) {
oatpp::os::io::Library::v_size progress = 0;
oatpp::data::v_io_size progress = 0;
while (transferSize == 0 || progress < transferSize) {
oatpp::os::io::Library::v_size desiredReadCount = transferSize - progress;
oatpp::data::v_io_size desiredReadCount = transferSize - progress;
if(transferSize == 0 || desiredReadCount > bufferSize){
desiredReadCount = bufferSize;
}
@ -153,27 +153,27 @@ oatpp::async::Action transferAsync(oatpp::async::AbstractCoroutine* parentCorout
const oatpp::async::Action& actionOnReturn,
const std::shared_ptr<InputStream>& fromStream,
const std::shared_ptr<OutputStream>& toStream,
oatpp::os::io::Library::v_size transferSize,
oatpp::data::v_io_size transferSize,
const std::shared_ptr<oatpp::data::buffer::IOBuffer>& buffer) {
class TransferCoroutine : public oatpp::async::Coroutine<TransferCoroutine> {
private:
std::shared_ptr<InputStream> m_fromStream;
std::shared_ptr<OutputStream> m_toStream;
oatpp::os::io::Library::v_size m_transferSize;
oatpp::os::io::Library::v_size m_progress;
oatpp::data::v_io_size m_transferSize;
oatpp::data::v_io_size m_progress;
std::shared_ptr<oatpp::data::buffer::IOBuffer> m_buffer;
oatpp::os::io::Library::v_size m_desiredReadCount;
oatpp::data::v_io_size m_desiredReadCount;
void* m_readBufferPtr;
const void* m_writeBufferPtr;
oatpp::os::io::Library::v_size m_bytesLeft;
oatpp::data::v_io_size m_bytesLeft;
public:
TransferCoroutine(const std::shared_ptr<InputStream>& fromStream,
const std::shared_ptr<OutputStream>& toStream,
oatpp::os::io::Library::v_size transferSize,
oatpp::data::v_io_size transferSize,
const std::shared_ptr<oatpp::data::buffer::IOBuffer>& buffer)
: m_fromStream(fromStream)
, m_toStream(toStream)
@ -243,7 +243,7 @@ oatpp::async::Action transferAsync(oatpp::async::AbstractCoroutine* parentCorout
oatpp::async::Action writeSomeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
os::io::Library::v_size& size,
data::v_io_size& size,
const oatpp::async::Action& nextAction) {
auto res = stream->write(data, size);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
@ -265,7 +265,7 @@ oatpp::async::Action writeSomeDataAsyncInline(oatpp::data::stream::OutputStream*
oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
os::io::Library::v_size& size,
data::v_io_size& size,
const oatpp::async::Action& nextAction) {
auto res = stream->write(data, size);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
@ -289,7 +289,7 @@ oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputSt
oatpp::async::Action readSomeDataAsyncInline(oatpp::data::stream::InputStream* stream,
void*& data,
os::io::Library::v_size& bytesLeftToRead,
data::v_io_size& bytesLeftToRead,
const oatpp::async::Action& nextAction) {
auto res = stream->read(data, bytesLeftToRead);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
@ -307,7 +307,7 @@ oatpp::async::Action readSomeDataAsyncInline(oatpp::data::stream::InputStream* s
oatpp::async::Action readExactSizeDataAsyncInline(oatpp::data::stream::InputStream* stream,
void*& data,
os::io::Library::v_size& bytesLeftToRead,
data::v_io_size& bytesLeftToRead,
const oatpp::async::Action& nextAction) {
auto res = stream->read(data, bytesLeftToRead);
if(res == oatpp::data::stream::Errors::ERROR_IO_WAIT_RETRY) {
@ -329,10 +329,10 @@ oatpp::async::Action readExactSizeDataAsyncInline(oatpp::data::stream::InputStre
return nextAction;
}
oatpp::os::io::Library::v_size readExactSizeData(oatpp::data::stream::InputStream* stream, void* data, os::io::Library::v_size size) {
oatpp::data::v_io_size readExactSizeData(oatpp::data::stream::InputStream* stream, void* data, data::v_io_size size) {
char* buffer = (char*) data;
oatpp::os::io::Library::v_size progress = 0;
oatpp::data::v_io_size progress = 0;
while (progress < size) {
@ -353,10 +353,10 @@ oatpp::os::io::Library::v_size readExactSizeData(oatpp::data::stream::InputStrea
}
oatpp::os::io::Library::v_size writeExactSizeData(oatpp::data::stream::OutputStream* stream, const void* data, os::io::Library::v_size size) {
oatpp::data::v_io_size writeExactSizeData(oatpp::data::stream::OutputStream* stream, const void* data, data::v_io_size size) {
const char* buffer = (char*)data;
oatpp::os::io::Library::v_size progress = 0;
oatpp::data::v_io_size progress = 0;
while (progress < size) {

View File

@ -25,23 +25,19 @@
#ifndef oatpp_data_Stream
#define oatpp_data_Stream
#include "oatpp/core/async/Coroutine.hpp"
#include "oatpp/core/data/buffer/IOBuffer.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/core/async/Coroutine.hpp"
#include "oatpp/core/os/io/Library.hpp"
#include "oatpp/core/data/IODefinitions.hpp"
namespace oatpp { namespace data{ namespace stream {
class Errors {
public:
constexpr static os::io::Library::v_size ERROR_IO_NOTHING_TO_READ = -1001;
constexpr static os::io::Library::v_size ERROR_IO_WAIT_RETRY = -1002;
constexpr static os::io::Library::v_size ERROR_IO_RETRY = -1003;
constexpr static os::io::Library::v_size ERROR_IO_PIPE = -1004;
constexpr static data::v_io_size ERROR_IO_NOTHING_TO_READ = -1001;
constexpr static data::v_io_size ERROR_IO_WAIT_RETRY = -1002;
constexpr static data::v_io_size ERROR_IO_RETRY = -1003;
constexpr static data::v_io_size ERROR_IO_PIPE = -1004;
static const char* const ERROR_ASYNC_FAILED_TO_WRITE_DATA;
static const char* const ERROR_ASYNC_FAILED_TO_READ_DATA;
@ -54,25 +50,25 @@ public:
* Write data to stream up to count bytes, and return number of bytes actually written
* It is a legal case if return result < count. Caller should handle this!
*/
virtual os::io::Library::v_size write(const void *data, os::io::Library::v_size count) = 0;
virtual data::v_io_size write(const void *data, data::v_io_size count) = 0;
os::io::Library::v_size write(const char* data){
data::v_io_size write(const char* data){
return write((p_char8)data, std::strlen(data));
}
os::io::Library::v_size write(const oatpp::String& str){
data::v_io_size write(const oatpp::String& str){
return write(str->getData(), str->getSize());
}
os::io::Library::v_size writeChar(v_char8 c){
data::v_io_size writeChar(v_char8 c){
return write(&c, 1);
}
os::io::Library::v_size writeAsString(v_int32 value);
os::io::Library::v_size writeAsString(v_int64 value);
os::io::Library::v_size writeAsString(v_float32 value);
os::io::Library::v_size writeAsString(v_float64 value);
os::io::Library::v_size writeAsString(bool value);
data::v_io_size writeAsString(v_int32 value);
data::v_io_size writeAsString(v_int64 value);
data::v_io_size writeAsString(v_float32 value);
data::v_io_size writeAsString(v_float64 value);
data::v_io_size writeAsString(bool value);
};
@ -82,12 +78,12 @@ public:
* Read data from stream up to count bytes, and return number of bytes actually read
* It is a legal case if return result < count. Caller should handle this!
*/
virtual os::io::Library::v_size read(void *data, os::io::Library::v_size count) = 0;
virtual data::v_io_size read(void *data, data::v_io_size count) = 0;
};
class IOStream : public InputStream, public OutputStream {
public:
typedef os::io::Library::v_size v_size;
typedef data::v_io_size v_size;
};
class CompoundIOStream : public oatpp::base::Controllable, public IOStream {
@ -110,11 +106,11 @@ public:
return Shared_CompoundIOStream_Pool::allocateShared(outputStream, inputStream);
}
os::io::Library::v_size write(const void *data, os::io::Library::v_size count) override {
data::v_io_size write(const void *data, data::v_io_size count) override {
return m_outputStream->write(data, count);
}
os::io::Library::v_size read(void *data, os::io::Library::v_size count) override {
data::v_io_size read(void *data, data::v_io_size count) override {
return m_inputStream->read(data, count);
}
@ -141,11 +137,11 @@ const std::shared_ptr<OutputStream>& operator << (const std::shared_ptr<OutputSt
* transfer up to transferSize or until error if transferSize == 0
* throws in case readCount != writeCount
*/
oatpp::os::io::Library::v_size transfer(const std::shared_ptr<InputStream>& fromStream,
oatpp::data::v_io_size transfer(const std::shared_ptr<InputStream>& fromStream,
const std::shared_ptr<OutputStream>& toStream,
oatpp::os::io::Library::v_size transferSize,
oatpp::data::v_io_size transferSize,
void* buffer,
oatpp::os::io::Library::v_size bufferSize);
oatpp::data::v_io_size bufferSize);
/**
@ -155,7 +151,7 @@ oatpp::async::Action transferAsync(oatpp::async::AbstractCoroutine* parentCorout
const oatpp::async::Action& actionOnReturn,
const std::shared_ptr<InputStream>& fromStream,
const std::shared_ptr<OutputStream>& toStream,
oatpp::os::io::Library::v_size transferSize,
oatpp::data::v_io_size transferSize,
const std::shared_ptr<oatpp::data::buffer::IOBuffer>& buffer);
/**
@ -164,22 +160,22 @@ oatpp::async::Action transferAsync(oatpp::async::AbstractCoroutine* parentCorout
*/
oatpp::async::Action writeSomeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
os::io::Library::v_size& size,
data::v_io_size& size,
const oatpp::async::Action& nextAction);
oatpp::async::Action writeExactSizeDataAsyncInline(oatpp::data::stream::OutputStream* stream,
const void*& data,
os::io::Library::v_size& size,
data::v_io_size& size,
const oatpp::async::Action& nextAction);
oatpp::async::Action readSomeDataAsyncInline(oatpp::data::stream::InputStream* stream,
void*& data,
os::io::Library::v_size& bytesLeftToRead,
data::v_io_size& bytesLeftToRead,
const oatpp::async::Action& nextAction);
oatpp::async::Action readExactSizeDataAsyncInline(oatpp::data::stream::InputStream* stream,
void*& data,
os::io::Library::v_size& bytesLeftToRead,
data::v_io_size& bytesLeftToRead,
const oatpp::async::Action& nextAction);
/**
@ -187,14 +183,14 @@ oatpp::async::Action readExactSizeDataAsyncInline(oatpp::data::stream::InputStre
* returns exact amount of bytes was read.
* return result can be < size only in case of some disaster like connection reset by peer
*/
oatpp::os::io::Library::v_size readExactSizeData(oatpp::data::stream::InputStream* stream, void* data, os::io::Library::v_size size);
oatpp::data::v_io_size readExactSizeData(oatpp::data::stream::InputStream* stream, void* data, data::v_io_size size);
/**
* Write exact amount of bytes to stream.
* returns exact amount of bytes was written.
* return result can be < size only in case of some disaster like broken pipe
*/
oatpp::os::io::Library::v_size writeExactSizeData(oatpp::data::stream::OutputStream* stream, const void* data, os::io::Library::v_size size);
oatpp::data::v_io_size writeExactSizeData(oatpp::data::stream::OutputStream* stream, const void* data, data::v_io_size size);
}}}

View File

@ -26,7 +26,7 @@
namespace oatpp { namespace data{ namespace stream {
os::io::Library::v_size OutputStreamBufferedProxy::write(const void *data, os::io::Library::v_size count) {
data::v_io_size OutputStreamBufferedProxy::write(const void *data, data::v_io_size count) {
if(m_pos == 0){
v_bufferSize spaceLeft = m_bufferSize - m_posEnd;
@ -45,11 +45,11 @@ os::io::Library::v_size OutputStreamBufferedProxy::write(const void *data, os::i
m_posEnd = m_bufferSize;
}
os::io::Library::v_size writeResult = m_outputStream->write(m_buffer, m_bufferSize);
data::v_io_size writeResult = m_outputStream->write(m_buffer, m_bufferSize);
if(writeResult == m_bufferSize){
m_posEnd = 0;
os::io::Library::v_size bigResult = write(&((p_char8) data)[spaceLeft], count - spaceLeft);
data::v_io_size bigResult = write(&((p_char8) data)[spaceLeft], count - spaceLeft);
if(bigResult > 0) {
return bigResult + spaceLeft;
} else if(bigResult < 0) {
@ -70,7 +70,7 @@ os::io::Library::v_size OutputStreamBufferedProxy::write(const void *data, os::i
} else {
auto amount = m_posEnd - m_pos;
if(amount > 0){
os::io::Library::v_size result = m_outputStream->write(&m_buffer[m_pos], amount);
data::v_io_size result = m_outputStream->write(&m_buffer[m_pos], amount);
if(result == amount){
m_pos = 0;
m_posEnd = 0;
@ -87,10 +87,10 @@ os::io::Library::v_size OutputStreamBufferedProxy::write(const void *data, os::i
}
}
os::io::Library::v_size OutputStreamBufferedProxy::flush() {
data::v_io_size OutputStreamBufferedProxy::flush() {
auto amount = m_posEnd - m_pos;
if(amount > 0){
os::io::Library::v_size result = stream::writeExactSizeData(m_outputStream.get(), &m_buffer[m_pos], amount);
data::v_io_size result = stream::writeExactSizeData(m_outputStream.get(), &m_buffer[m_pos], amount);
if(result == amount){
m_pos = 0;
m_posEnd = 0;
@ -117,7 +117,7 @@ oatpp::async::Action OutputStreamBufferedProxy::flushAsync(oatpp::async::Abstrac
Action act() override {
auto amount = m_stream->m_posEnd - m_stream->m_pos;
if(amount > 0){
os::io::Library::v_size result = m_stream->m_outputStream->write(&m_stream->m_buffer[m_stream->m_pos], amount);
data::v_io_size result = m_stream->m_outputStream->write(&m_stream->m_buffer[m_stream->m_pos], amount);
if(result == amount) {
m_stream->m_pos = 0;
m_stream->m_posEnd = 0;
@ -144,7 +144,7 @@ oatpp::async::Action OutputStreamBufferedProxy::flushAsync(oatpp::async::Abstrac
}
os::io::Library::v_size InputStreamBufferedProxy::read(void *data, os::io::Library::v_size count) {
data::v_io_size InputStreamBufferedProxy::read(void *data, data::v_io_size count) {
if (m_pos == 0 && m_posEnd == 0) {
@ -185,7 +185,7 @@ os::io::Library::v_size InputStreamBufferedProxy::read(void *data, os::io::Libra
m_pos = 0;
m_posEnd = 0;
os::io::Library::v_size bigResult = read(&((p_char8) data) [result], count - result);
data::v_io_size bigResult = read(&((p_char8) data) [result], count - result);
if(bigResult > 0){
return bigResult + result;
} else if(bigResult < 0) {

View File

@ -77,8 +77,8 @@ public:
bufferSize);
}
os::io::Library::v_size write(const void *data, os::io::Library::v_size count) override;
os::io::Library::v_size flush();
data::v_io_size write(const void *data, data::v_io_size count) override;
data::v_io_size flush();
oatpp::async::Action flushAsync(oatpp::async::AbstractCoroutine* parentCoroutine,
const oatpp::async::Action& actionOnFinish);
@ -166,7 +166,7 @@ public:
positionEnd);
}
os::io::Library::v_size read(void *data, os::io::Library::v_size count) override;
data::v_io_size read(void *data, data::v_io_size count) override;
void setBufferPosition(v_bufferSize pos, v_bufferSize posEnd){
m_pos = pos;

View File

@ -1,49 +0,0 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi, <lganzzzo@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************************/
#include "Library.hpp"
#include <memory>
#include <unistd.h>
#include <sys/socket.h>
namespace oatpp { namespace os { namespace io {
v_int32 Library::handle_close(v_handle handle){
return close(handle);
}
Library::v_size Library::handle_read(v_handle handle, void *buf, v_size count){
return read(handle, buf, count);
}
Library::v_size Library::handle_write(v_handle handle, const void *buf, v_size count){
v_int32 flags = 0;
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
#endif
return send(handle, buf, count, flags);
}
}}}

View File

@ -24,13 +24,14 @@
#include "./Connection.hpp"
#include <unistd.h>
#include <sys/socket.h>
#include <thread>
#include <chrono>
namespace oatpp { namespace network {
Connection::Connection(Library::v_handle handle)
Connection::Connection(data::v_io_handle handle)
: m_handle(handle)
{
}
@ -39,9 +40,16 @@ Connection::~Connection(){
close();
}
Connection::Library::v_size Connection::write(const void *buff, Library::v_size count){
data::v_io_size Connection::write(const void *buff, data::v_io_size count){
errno = 0;
auto result = Library::handle_write(m_handle, buff, count);
v_int32 flags = 0;
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
#endif
auto result = ::send(m_handle, buff, count, flags);
if(result <= 0) {
auto e = errno;
if(e == EAGAIN || e == EWOULDBLOCK){
@ -57,9 +65,9 @@ Connection::Library::v_size Connection::write(const void *buff, Library::v_size
return result;
}
Connection::Library::v_size Connection::read(void *buff, Library::v_size count){
data::v_io_size Connection::read(void *buff, data::v_io_size count){
errno = 0;
auto result = Library::handle_read(m_handle, buff, count);
auto result = ::read(m_handle, buff, count);
if(result <= 0) {
auto e = errno;
if(e == EAGAIN || e == EWOULDBLOCK){
@ -76,7 +84,7 @@ Connection::Library::v_size Connection::read(void *buff, Library::v_size count){
}
void Connection::close(){
Library::handle_close(m_handle);
::close(m_handle);
}
}}

View File

@ -31,29 +31,27 @@
namespace oatpp { namespace network {
class Connection : public oatpp::base::Controllable, public oatpp::data::stream::IOStream {
public:
typedef oatpp::os::io::Library Library;
public:
OBJECT_POOL(Connection_Pool, Connection, 32);
SHARED_OBJECT_POOL(Shared_Connection_Pool, Connection, 32);
private:
Library::v_handle m_handle;
data::v_io_handle m_handle;
public:
Connection(Library::v_handle handle);
Connection(data::v_io_handle handle);
public:
static std::shared_ptr<Connection> createShared(Library::v_handle handle){
static std::shared_ptr<Connection> createShared(data::v_io_handle handle){
return Shared_Connection_Pool::allocateShared(handle);
}
~Connection();
Library::v_size write(const void *buff, Library::v_size count) override;
Library::v_size read(void *buff, Library::v_size count) override;
data::v_io_size write(const void *buff, data::v_io_size count) override;
data::v_io_size read(void *buff, data::v_io_size count) override;
void close();
Library::v_handle getHandle(){
data::v_io_handle getHandle(){
return m_handle;
}

View File

@ -32,6 +32,7 @@
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <unistd.h>
namespace oatpp { namespace network { namespace client {
@ -58,7 +59,7 @@ std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getC
client.sin_port = htons(m_port);
memcpy(&client.sin_addr, host->h_addr, host->h_length);
oatpp::os::io::Library::v_handle clientHandle = socket(AF_INET, SOCK_STREAM, 0);
oatpp::data::v_io_handle clientHandle = socket(AF_INET, SOCK_STREAM, 0);
if (clientHandle < 0) {
OATPP_LOGD("SimpleTCPConnectionProvider", "Error creating socket.");
@ -74,7 +75,7 @@ std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getC
#endif
if (connect(clientHandle, (struct sockaddr *)&client, sizeof(client)) != 0 ) {
oatpp::os::io::Library::handle_close(clientHandle);
::close(clientHandle);
OATPP_LOGD("SimpleTCPConnectionProvider", "Could not connect");
return nullptr;
}
@ -90,7 +91,7 @@ oatpp::async::Action SimpleTCPConnectionProvider::getConnectionAsync(oatpp::asyn
private:
oatpp::String m_host;
v_int32 m_port;
oatpp::os::io::Library::v_handle m_clientHandle;
oatpp::data::v_io_handle m_clientHandle;
struct sockaddr_in m_client;
public:
@ -143,7 +144,7 @@ oatpp::async::Action SimpleTCPConnectionProvider::getConnectionAsync(oatpp::asyn
} else if(errno == EINTR) {
return repeat();
}
oatpp::os::io::Library::handle_close(m_clientHandle);
::close(m_clientHandle);
return error("[oatpp::network::client::SimpleTCPConnectionProvider::getConnectionAsync()]: Can't connect");
}

View File

@ -36,15 +36,11 @@
#include "oatpp/core/base/Controllable.hpp"
#include "oatpp/core/base/Environment.hpp"
#include "oatpp/core/os/io/Library.hpp"
#include <atomic>
namespace oatpp { namespace network { namespace server {
class Server : public base::Controllable, public concurrency::Runnable{
public:
typedef oatpp::os::io::Library Library;
private:
void mainLoop();

View File

@ -33,6 +33,7 @@
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <unistd.h>
namespace oatpp { namespace network { namespace server {
@ -44,10 +45,14 @@ SimpleTCPConnectionProvider::SimpleTCPConnectionProvider(v_word16 port, bool non
setProperty(PROPERTY_HOST, "localhost");
setProperty(PROPERTY_PORT, oatpp::utils::conversion::int32ToStr(port));
}
SimpleTCPConnectionProvider::~SimpleTCPConnectionProvider() {
::close(m_serverHandle);
}
oatpp::os::io::Library::v_handle SimpleTCPConnectionProvider::instantiateServer(){
oatpp::data::v_io_handle SimpleTCPConnectionProvider::instantiateServer(){
oatpp::os::io::Library::v_handle serverHandle;
oatpp::data::v_io_handle serverHandle;
v_int32 ret;
int yes = 1;
@ -71,14 +76,14 @@ oatpp::os::io::Library::v_handle SimpleTCPConnectionProvider::instantiateServer(
ret = bind(serverHandle, (struct sockaddr *)&addr, sizeof(addr));
if(ret != 0) {
oatpp::os::io::Library::handle_close(serverHandle);
::close(serverHandle);
throw std::runtime_error("Can't bind to address");
return -1 ;
}
ret = listen(serverHandle, 10000);
if(ret < 0) {
oatpp::os::io::Library::handle_close(serverHandle);
::close(serverHandle);
return -1 ;
}
@ -92,7 +97,7 @@ std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getC
//oatpp::test::PerformanceChecker checker("Accept Checker");
oatpp::os::io::Library::v_handle handle = accept(m_serverHandle, nullptr, nullptr);
oatpp::data::v_io_handle handle = accept(m_serverHandle, nullptr, nullptr);
if (handle < 0) {
v_int32 error = errno;

View File

@ -29,7 +29,6 @@
#include "oatpp/core/data/stream/Stream.hpp"
#include "oatpp/core/Types.hpp"
#include "oatpp/core/os/io/Library.hpp"
namespace oatpp { namespace network { namespace server {
@ -37,9 +36,9 @@ class SimpleTCPConnectionProvider : public base::Controllable, public ServerConn
private:
v_word16 m_port;
bool m_nonBlocking;
oatpp::os::io::Library::v_handle m_serverHandle;
oatpp::data::v_io_handle m_serverHandle;
private:
oatpp::os::io::Library::v_handle instantiateServer();
oatpp::data::v_io_handle instantiateServer();
public:
SimpleTCPConnectionProvider(v_word16 port, bool nonBlocking = false);
public:
@ -48,9 +47,7 @@ public:
return std::make_shared<SimpleTCPConnectionProvider>(port, nonBlocking);
}
~SimpleTCPConnectionProvider() {
oatpp::os::io::Library::handle_close(m_serverHandle);
}
~SimpleTCPConnectionProvider();
std::shared_ptr<IOStream> getConnection() override;

View File

@ -26,18 +26,18 @@
namespace oatpp { namespace network { namespace virtual_ {
void Pipe::Reader::setMaxAvailableToRead(os::io::Library::v_size maxAvailableToRead) {
void Pipe::Reader::setMaxAvailableToRead(data::v_io_size maxAvailableToRead) {
m_maxAvailableToRead = maxAvailableToRead;
}
os::io::Library::v_size Pipe::Reader::read(void *data, os::io::Library::v_size count) {
data::v_io_size Pipe::Reader::read(void *data, data::v_io_size count) {
if(m_maxAvailableToRead > -1 && count > m_maxAvailableToRead) {
count = m_maxAvailableToRead;
}
Pipe& pipe = *m_pipe;
oatpp::os::io::Library::v_size result;
oatpp::data::v_io_size result;
if(m_nonBlocking) {
if(pipe.m_buffer.availableToRead() > 0) {
@ -66,18 +66,18 @@ os::io::Library::v_size Pipe::Reader::read(void *data, os::io::Library::v_size c
}
void Pipe::Writer::setMaxAvailableToWrite(os::io::Library::v_size maxAvailableToWrite) {
void Pipe::Writer::setMaxAvailableToWrite(data::v_io_size maxAvailableToWrite) {
m_maxAvailableToWrtie = maxAvailableToWrite;
}
os::io::Library::v_size Pipe::Writer::write(const void *data, os::io::Library::v_size count) {
data::v_io_size Pipe::Writer::write(const void *data, data::v_io_size count) {
if(m_maxAvailableToWrtie > -1 && count > m_maxAvailableToWrtie) {
count = m_maxAvailableToWrtie;
}
Pipe& pipe = *m_pipe;
oatpp::os::io::Library::v_size result;
oatpp::data::v_io_size result;
if(m_nonBlocking) {
if(pipe.m_buffer.availableToWrite() > 0) {

View File

@ -46,7 +46,7 @@ public:
/**
* this one used for testing purposes only
*/
os::io::Library::v_size m_maxAvailableToRead;
data::v_io_size m_maxAvailableToRead;
public:
Reader(Pipe* pipe, bool nonBlocking = false)
@ -63,9 +63,9 @@ public:
* this one used for testing purposes only
* set to -1 in order to ignore this value
*/
void setMaxAvailableToRead(os::io::Library::v_size maxAvailableToRead);
void setMaxAvailableToRead(data::v_io_size maxAvailableToRead);
os::io::Library::v_size read(void *data, os::io::Library::v_size count) override;
data::v_io_size read(void *data, data::v_io_size count) override;
};
@ -77,7 +77,7 @@ public:
/**
* this one used for testing purposes only
*/
os::io::Library::v_size m_maxAvailableToWrtie;
data::v_io_size m_maxAvailableToWrtie;
public:
Writer(Pipe* pipe, bool nonBlocking = false)
@ -94,9 +94,9 @@ public:
* this one used for testing purposes only
* set to -1 in order to ignore this value
*/
void setMaxAvailableToWrite(os::io::Library::v_size maxAvailableToWrite);
void setMaxAvailableToWrite(data::v_io_size maxAvailableToWrite);
os::io::Library::v_size write(const void *data, os::io::Library::v_size count) override;
data::v_io_size write(const void *data, data::v_io_size count) override;
};

View File

@ -26,16 +26,16 @@
namespace oatpp { namespace network { namespace virtual_ {
void Socket::setMaxAvailableToReadWrtie(os::io::Library::v_size maxToRead, os::io::Library::v_size maxToWrite) {
void Socket::setMaxAvailableToReadWrtie(data::v_io_size maxToRead, data::v_io_size maxToWrite) {
m_pipeIn->getReader()->setMaxAvailableToRead(maxToRead);
m_pipeOut->getWriter()->setMaxAvailableToWrite(maxToWrite);
}
os::io::Library::v_size Socket::read(void *data, os::io::Library::v_size count) {
data::v_io_size Socket::read(void *data, data::v_io_size count) {
return m_pipeIn->getReader()->read(data, count);
}
os::io::Library::v_size Socket::write(const void *data, os::io::Library::v_size count) {
data::v_io_size Socket::write(const void *data, data::v_io_size count) {
return m_pipeOut->getWriter()->write(data, count);
}

View File

@ -52,10 +52,10 @@ public:
* this one used for testing purposes only
* set to -1 in order to ignore this value
*/
void setMaxAvailableToReadWrtie(os::io::Library::v_size maxToRead, os::io::Library::v_size maxToWrite);
void setMaxAvailableToReadWrtie(data::v_io_size maxToRead, data::v_io_size maxToWrite);
os::io::Library::v_size read(void *data, os::io::Library::v_size count) override;
os::io::Library::v_size write(const void *data, os::io::Library::v_size count) override;
data::v_io_size read(void *data, data::v_io_size count) override;
data::v_io_size write(const void *data, data::v_io_size count) override;
void setNonBlocking(bool nonBlocking);

View File

@ -39,14 +39,14 @@ oatpp::async::Action ConnectionProvider::getConnectionAsync(oatpp::async::Abstra
class ConnectCoroutine : public oatpp::async::CoroutineWithResult<ConnectCoroutine, std::shared_ptr<oatpp::data::stream::IOStream>> {
private:
std::shared_ptr<virtual_::Interface> m_interface;
os::io::Library::v_size m_maxAvailableToRead;
os::io::Library::v_size m_maxAvailableToWrite;
data::v_io_size m_maxAvailableToRead;
data::v_io_size m_maxAvailableToWrite;
std::shared_ptr<virtual_::Interface::ConnectionSubmission> m_submission;
public:
ConnectCoroutine(const std::shared_ptr<virtual_::Interface>& interface,
os::io::Library::v_size maxAvailableToRead,
os::io::Library::v_size maxAvailableToWrite)
data::v_io_size maxAvailableToRead,
data::v_io_size maxAvailableToWrite)
: m_interface(interface)
, m_maxAvailableToRead(maxAvailableToRead)
, m_maxAvailableToWrite(maxAvailableToWrite)

View File

@ -33,8 +33,8 @@ namespace oatpp { namespace network { namespace virtual_ { namespace client {
class ConnectionProvider : public oatpp::network::ClientConnectionProvider {
private:
std::shared_ptr<virtual_::Interface> m_interface;
os::io::Library::v_size m_maxAvailableToRead;
os::io::Library::v_size m_maxAvailableToWrite;
data::v_io_size m_maxAvailableToRead;
data::v_io_size m_maxAvailableToWrite;
public:
ConnectionProvider(const std::shared_ptr<virtual_::Interface>& interface)
@ -54,7 +54,7 @@ public:
* this one used for testing purposes only
* set to -1 in order to ignore this value
*/
void setSocketMaxAvailableToReadWrtie(os::io::Library::v_size maxToRead, os::io::Library::v_size maxToWrite) {
void setSocketMaxAvailableToReadWrtie(data::v_io_size maxToRead, data::v_io_size maxToWrite) {
m_maxAvailableToRead = maxToRead;
m_maxAvailableToWrite = maxToWrite;
}

View File

@ -28,7 +28,7 @@ namespace oatpp { namespace network { namespace virtual_ { namespace server {
std::shared_ptr<ConnectionProvider::IOStream> ConnectionProvider::getConnection() {
auto socket = m_interface->accept();
socket->setNonBlocking(false);
socket->setNonBlocking(m_nonBlocking);
socket->setMaxAvailableToReadWrtie(m_maxAvailableToRead, m_maxAvailableToWrite);
return socket;
}

View File

@ -33,12 +33,14 @@ namespace oatpp { namespace network { namespace virtual_ { namespace server {
class ConnectionProvider : public oatpp::network::ServerConnectionProvider {
private:
std::shared_ptr<virtual_::Interface> m_interface;
os::io::Library::v_size m_maxAvailableToRead;
os::io::Library::v_size m_maxAvailableToWrite;
bool m_nonBlocking;
data::v_io_size m_maxAvailableToRead;
data::v_io_size m_maxAvailableToWrite;
public:
ConnectionProvider(const std::shared_ptr<virtual_::Interface>& interface)
ConnectionProvider(const std::shared_ptr<virtual_::Interface>& interface, bool nonBlocking = false)
: m_interface(interface)
, m_nonBlocking(nonBlocking)
, m_maxAvailableToRead(-1)
, m_maxAvailableToWrite(-1)
{
@ -46,15 +48,15 @@ public:
setProperty(PROPERTY_PORT, "0");
}
static std::shared_ptr<ConnectionProvider> createShared(const std::shared_ptr<virtual_::Interface>& interface) {
return std::make_shared<ConnectionProvider>(interface);
static std::shared_ptr<ConnectionProvider> createShared(const std::shared_ptr<virtual_::Interface>& interface, bool nonBlocking = false) {
return std::make_shared<ConnectionProvider>(interface, nonBlocking);
}
/**
* this one used for testing purposes only
* set to -1 in order to ignore this value
*/
void setSocketMaxAvailableToReadWrtie(os::io::Library::v_size maxToRead, os::io::Library::v_size maxToWrite) {
void setSocketMaxAvailableToReadWrtie(data::v_io_size maxToRead, data::v_io_size maxToWrite) {
m_maxAvailableToRead = maxToRead;
m_maxAvailableToWrite = maxToWrite;
}

View File

@ -154,7 +154,7 @@ oatpp::async::Action HttpRequestExecutor::executeAsync(oatpp::async::AbstractCor
std::shared_ptr<oatpp::data::stream::IOStream> m_connection;
std::shared_ptr<oatpp::data::buffer::IOBuffer> m_ioBuffer;
void* m_bufferPointer;
os::io::Library::v_size m_bufferBytesLeftToRead;
data::v_io_size m_bufferBytesLeftToRead;
public:
ExecutorCoroutine(const std::shared_ptr<oatpp::network::ClientConnectionProvider>& connectionProvider,

View File

@ -26,13 +26,13 @@
namespace oatpp { namespace web { namespace protocol {
CommunicationError::CommunicationError(oatpp::os::io::Library::v_size ioStatus, const oatpp::String& message)
CommunicationError::CommunicationError(oatpp::data::v_io_size ioStatus, const oatpp::String& message)
:std::runtime_error(message->std_str())
, m_ioStatus(ioStatus)
, m_message(message)
{}
oatpp::os::io::Library::v_size CommunicationError::getIOStatus() {
oatpp::data::v_io_size CommunicationError::getIOStatus() {
return m_ioStatus;
}

View File

@ -25,19 +25,18 @@
#ifndef oatpp_web_protocol_CommunicationError_hpp
#define oatpp_web_protocol_CommunicationError_hpp
#include "oatpp/core/Types.hpp"
#include "oatpp/core/os/io/Library.hpp"
#include "oatpp/core/data/IODefinitions.hpp"
namespace oatpp { namespace web { namespace protocol {
class CommunicationError : public std::runtime_error {
private:
oatpp::os::io::Library::v_size m_ioStatus;
oatpp::data::v_io_size m_ioStatus;
oatpp::String m_message;
public:
CommunicationError(oatpp::os::io::Library::v_size ioStatus, const oatpp::String& message);
oatpp::os::io::Library::v_size getIOStatus();
CommunicationError(oatpp::data::v_io_size ioStatus, const oatpp::String& message);
oatpp::data::v_io_size getIOStatus();
oatpp::String& getMessage();
};
@ -52,12 +51,12 @@ public:
: ioStatus(0)
{}
Info(oatpp::os::io::Library::v_size pIOStatus, const Status& pStatus)
Info(oatpp::data::v_io_size pIOStatus, const Status& pStatus)
: ioStatus(pIOStatus)
, status(pStatus)
{}
oatpp::os::io::Library::v_size ioStatus;
oatpp::data::v_io_size ioStatus;
Status status;
};

View File

@ -159,8 +159,8 @@ Range Range::parse(oatpp::parser::ParsingCaret& caret) {
caret.findRN();
endLabel.end();
oatpp::os::io::Library::v_size start = oatpp::utils::conversion::strToInt64((const char*) startLabel.getData());
oatpp::os::io::Library::v_size end = oatpp::utils::conversion::strToInt64((const char*) endLabel.getData());
oatpp::data::v_io_size start = oatpp::utils::conversion::strToInt64((const char*) startLabel.getData());
oatpp::data::v_io_size end = oatpp::utils::conversion::strToInt64((const char*) endLabel.getData());
return Range(unitsLabel.toString(true), start, end);
}
@ -220,9 +220,9 @@ ContentRange ContentRange::parse(oatpp::parser::ParsingCaret& caret) {
caret.findRN();
sizeLabel.end();
oatpp::os::io::Library::v_size start = oatpp::utils::conversion::strToInt64((const char*) startLabel.getData());
oatpp::os::io::Library::v_size end = oatpp::utils::conversion::strToInt64((const char*) endLabel.getData());
oatpp::os::io::Library::v_size size = 0;
oatpp::data::v_io_size start = oatpp::utils::conversion::strToInt64((const char*) startLabel.getData());
oatpp::data::v_io_size end = oatpp::utils::conversion::strToInt64((const char*) endLabel.getData());
oatpp::data::v_io_size size = 0;
bool isSizeKnown = false;
if(sizeLabel.getData()[0] != '*') {
isSizeKnown = true;

View File

@ -188,16 +188,16 @@ private:
public:
Range(const oatpp::String& pUnits,
const oatpp::os::io::Library::v_size& pStart,
const oatpp::os::io::Library::v_size& pEnd)
const oatpp::data::v_io_size& pStart,
const oatpp::data::v_io_size& pEnd)
: units(pUnits)
, start(pStart)
, end(pEnd)
{}
oatpp::String units;
oatpp::os::io::Library::v_size start;
oatpp::os::io::Library::v_size end;
oatpp::data::v_io_size start;
oatpp::data::v_io_size end;
oatpp::String toString() const;
@ -220,9 +220,9 @@ private:
public:
ContentRange(const oatpp::String& pUnits,
const oatpp::os::io::Library::v_size& pStart,
const oatpp::os::io::Library::v_size& pEnd,
const oatpp::os::io::Library::v_size& pSize,
const oatpp::data::v_io_size& pStart,
const oatpp::data::v_io_size& pEnd,
const oatpp::data::v_io_size& pSize,
bool pIsSizeKnown)
: units(pUnits)
, start(pStart)
@ -232,9 +232,9 @@ public:
{}
oatpp::String units;
oatpp::os::io::Library::v_size start;
oatpp::os::io::Library::v_size end;
oatpp::os::io::Library::v_size size;
oatpp::data::v_io_size start;
oatpp::data::v_io_size end;
oatpp::data::v_io_size size;
bool isSizeKnown;
oatpp::String toString() const;

View File

@ -28,14 +28,14 @@
namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming {
os::io::Library::v_size RequestHeadersReader::readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
data::v_io_size RequestHeadersReader::readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
oatpp::data::stream::OutputStream* bufferStream,
Result& result) {
v_word32 sectionEnd = ('\r' << 24) | ('\n' << 16) | ('\r' << 8) | ('\n');
v_word32 accumulator = 0;
v_int32 progress = 0;
os::io::Library::v_size res;
data::v_io_size res;
while (true) {
v_int32 desiredToRead = m_bufferSize;

View File

@ -47,7 +47,7 @@ public:
public:
typedef Action (oatpp::async::AbstractCoroutine::*AsyncCallback)(const Result&);
private:
os::io::Library::v_size readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
data::v_io_size readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
oatpp::data::stream::OutputStream* bufferStream,
Result& result);
private:

View File

@ -28,14 +28,14 @@
namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming {
os::io::Library::v_size ResponseHeadersReader::readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
data::v_io_size ResponseHeadersReader::readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
oatpp::data::stream::OutputStream* bufferStream,
Result& result) {
v_word32 sectionEnd = ('\r' << 24) | ('\n' << 16) | ('\r' << 8) | ('\n');
v_word32 accumulator = 0;
v_int32 progress = 0;
os::io::Library::v_size res;
data::v_io_size res;
while (true) {
v_int32 desiredToRead = m_bufferSize;

View File

@ -47,7 +47,7 @@ public:
public:
typedef Action (oatpp::async::AbstractCoroutine::*AsyncCallback)(const Result&);
private:
os::io::Library::v_size readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
data::v_io_size readHeadersSection(const std::shared_ptr<oatpp::data::stream::IOStream>& connection,
oatpp::data::stream::OutputStream* bufferStream,
Result& result);
private:

View File

@ -29,12 +29,12 @@
namespace oatpp { namespace web { namespace protocol { namespace http { namespace incoming {
os::io::Library::v_size SimpleBodyDecoder::readLine(const std::shared_ptr<oatpp::data::stream::InputStream>& fromStream,
data::v_io_size SimpleBodyDecoder::readLine(const std::shared_ptr<oatpp::data::stream::InputStream>& fromStream,
p_char8 buffer,
os::io::Library::v_size maxLineSize) {
data::v_io_size maxLineSize) {
v_char8 a;
os::io::Library::v_size count = 0;
data::v_io_size count = 0;
while (fromStream->read(&a, 1) > 0) {
if(a != '\r') {
if(count + 1 > maxLineSize) {
@ -62,7 +62,7 @@ void SimpleBodyDecoder::doChunkedDecoding(const std::shared_ptr<oatpp::data::str
v_int32 maxLineSize = 8; // 0xFFFFFFFF 4Gb for chunk
v_char8 lineBuffer[maxLineSize + 1];
os::io::Library::v_size countToRead;
data::v_io_size countToRead;
do {
@ -91,7 +91,7 @@ void SimpleBodyDecoder::decode(const Protocol::Headers& headers,
if(transferEncodingIt != headers.end() && transferEncodingIt->second == Header::Value::TRANSFER_ENCODING_CHUNKED) {
doChunkedDecoding(bodyStream, toStream);
} else {
oatpp::os::io::Library::v_size contentLength = 0;
oatpp::data::v_io_size contentLength = 0;
auto contentLengthStrIt = headers.find(Header::CONTENT_LENGTH);
if(contentLengthStrIt == headers.end()) {
return; // DO NOTHING // it is an empty or invalid body
@ -127,7 +127,7 @@ oatpp::async::Action SimpleBodyDecoder::doChunkedDecodingAsync(oatpp::async::Abs
bool m_lineEnding;
v_char8 m_lineBuffer [16]; // used max 8
void* m_skipData;
os::io::Library::v_size m_skipSize;
data::v_io_size m_skipSize;
bool m_done = false;
private:
void prepareSkipRN() {
@ -187,7 +187,7 @@ oatpp::async::Action SimpleBodyDecoder::doChunkedDecodingAsync(oatpp::async::Abs
}
Action onLineRead() {
os::io::Library::v_size countToRead = std::strtol((const char*) m_lineBuffer, nullptr, 16);
data::v_io_size countToRead = std::strtol((const char*) m_lineBuffer, nullptr, 16);
if(countToRead > 0) {
prepareSkipRN();
return oatpp::data::stream::transferAsync(this, yieldTo(&ChunkedDecoder::skipRN), m_fromStream, m_toStream, countToRead, m_buffer);
@ -226,7 +226,7 @@ oatpp::async::Action SimpleBodyDecoder::decodeAsync(oatpp::async::AbstractCorout
if(transferEncodingIt != headers.end() && transferEncodingIt->second == Header::Value::TRANSFER_ENCODING_CHUNKED) {
return doChunkedDecodingAsync(parentCoroutine, actionOnReturn, bodyStream, toStream);
} else {
oatpp::os::io::Library::v_size contentLength = 0;
oatpp::data::v_io_size contentLength = 0;
auto contentLengthStrIt = headers.find(Header::CONTENT_LENGTH);
if(contentLengthStrIt == headers.end()) {
return actionOnReturn; // DO NOTHING // it is an empty or invalid body

View File

@ -31,9 +31,9 @@ namespace oatpp { namespace web { namespace protocol { namespace http { namespac
class SimpleBodyDecoder : public BodyDecoder {
private:
static os::io::Library::v_size readLine(const std::shared_ptr<oatpp::data::stream::InputStream>& fromStream,
static data::v_io_size readLine(const std::shared_ptr<oatpp::data::stream::InputStream>& fromStream,
p_char8 buffer,
os::io::Library::v_size maxLineSize);
data::v_io_size maxLineSize);
static void doChunkedDecoding(const std::shared_ptr<oatpp::data::stream::InputStream>& from,
const std::shared_ptr<oatpp::data::stream::OutputStream>& toStream);

View File

@ -62,7 +62,7 @@ public:
std::shared_ptr<BufferBody> m_body;
std::shared_ptr<OutputStream> m_stream;
const void* m_currData;
oatpp::os::io::Library::v_size m_currDataSize;
oatpp::data::v_io_size m_currDataSize;
public:
WriteToStreamCoroutine(const std::shared_ptr<BufferBody>& body,

View File

@ -92,7 +92,7 @@ public:
std::shared_ptr<oatpp::data::stream::ChunkedBuffer::Chunks> m_chunks;
oatpp::data::stream::ChunkedBuffer::Chunks::LinkedListNode* m_currChunk;
const void* m_currData;
oatpp::os::io::Library::v_size m_currDataSize;
oatpp::data::v_io_size m_currDataSize;
Action m_nextAction;
v_char8 m_buffer[16];
public:

View File

@ -46,7 +46,7 @@ public:
};
void runTests() {
OATPP_RUN_TEST(oatpp::test::base::RegRuleTest);
/*OATPP_RUN_TEST(oatpp::test::base::RegRuleTest);
OATPP_RUN_TEST(oatpp::test::base::CommandLineArgumentsTest);
OATPP_RUN_TEST(oatpp::test::memory::MemoryPoolTest);
OATPP_RUN_TEST(oatpp::test::memory::PerfTest);
@ -59,8 +59,8 @@ void runTests() {
OATPP_RUN_TEST(oatpp::test::encoding::UnicodeTest);
OATPP_RUN_TEST(oatpp::test::core::data::share::MemoryLabelTest);
OATPP_RUN_TEST(oatpp::test::network::virtual_::PipeTest);
OATPP_RUN_TEST(oatpp::test::network::virtual_::InterfaceTest);
OATPP_RUN_TEST(oatpp::test::web::FullTest);
OATPP_RUN_TEST(oatpp::test::network::virtual_::InterfaceTest);*/
//OATPP_RUN_TEST(oatpp::test::web::FullTest);
OATPP_RUN_TEST(oatpp::test::web::FullAsyncTest);
}

View File

@ -40,14 +40,14 @@ namespace {
typedef oatpp::network::virtual_::Pipe Pipe;
const char* DATA_CHUNK = "<0123456789/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ>";
const os::io::Library::v_size CHUNK_SIZE = std::strlen(DATA_CHUNK);
const data::v_io_size CHUNK_SIZE = std::strlen(DATA_CHUNK);
class WriterTask : public oatpp::concurrency::Runnable {
private:
std::shared_ptr<Pipe> m_pipe;
v_int32 m_chunksToTransfer;
os::io::Library::v_size m_position = 0;
os::io::Library::v_size m_transferedBytes = 0;
data::v_io_size m_position = 0;
data::v_io_size m_transferedBytes = 0;
public:
WriterTask(const std::shared_ptr<Pipe>& pipe, v_int32 chunksToTransfer)

View File

@ -46,7 +46,7 @@ bool FullAsyncTest::onRun() {
auto interface = oatpp::network::virtual_::Interface::createShared("virtualhost");
auto serverConnectionProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface);
auto serverConnectionProvider = oatpp::network::virtual_::server::ConnectionProvider::createShared(interface, true);
auto clientConnectionProvider = oatpp::network::virtual_::client::ConnectionProvider::createShared(interface);
serverConnectionProvider->setSocketMaxAvailableToReadWrtie(1, 1);
@ -69,21 +69,21 @@ bool FullAsyncTest::onRun() {
std::thread clientThread([client, server, connectionHandler, objectMapper]{
for(v_int32 i = 0; i < 10; i ++) {
{ /* test simple GET */
/*
{ // test simple GET
auto response = client->getRoot();
auto value = response->readBodyToString();
OATPP_ASSERT(value == "Hello World Async!!!");
}
{ /* test GET with path parameter */
{ // test GET with path parameter
auto response = client->getWithParams("my_test_param-Async");
auto dto = response->readBodyToDto<app::TestDto>(objectMapper);
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_param-Async");
}
{ /* test GET with header parameter */
{ // test GET with header parameter
auto response = client->getWithHeaders("my_test_header-Async");
//auto str = response->readBodyToString();
//OATPP_LOGE("AAA", "code=%d, str='%s'", response->statusCode, str->c_str());
@ -92,12 +92,24 @@ bool FullAsyncTest::onRun() {
OATPP_ASSERT(dto->testValue == "my_test_header-Async");
}
{ /* test POST with body */
{ // test POST with body
auto response = client->postBody("my_test_body-Async");
auto dto = response->readBodyToDto<app::TestDto>(objectMapper);
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_body-Async");
}
*/
{ // test Big Echo with body
oatpp::data::stream::ChunkedBuffer stream;
for(v_int32 i = 0; i < oatpp::data::buffer::IOBuffer::BUFFER_SIZE; i++) {
stream.write("0123456789", 10);
}
auto data = stream.toString();
auto response = client->echoBody(data);
auto returnedData = response->readBodyToString();
OATPP_ASSERT(returnedData);
OATPP_ASSERT(returnedData == data);
}
}

View File

@ -71,28 +71,28 @@ bool FullTest::onRun() {
std::thread clientThread([client, server, objectMapper]{
for(v_int32 i = 0; i < 10; i ++) {
{ /* test simple GET */
{ // test simple GET
auto response = client->getRoot();
auto value = response->readBodyToString();
OATPP_ASSERT(value == "Hello World!!!");
}
{ /* test GET with path parameter */
{ // test GET with path parameter
auto response = client->getWithParams("my_test_param");
auto dto = response->readBodyToDto<app::TestDto>(objectMapper);
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_param");
}
{ /* test GET with header parameter */
{ // test GET with header parameter
auto response = client->getWithHeaders("my_test_header");
auto dto = response->readBodyToDto<app::TestDto>(objectMapper);
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->testValue == "my_test_header");
}
{ /* test POST with body */
{ // test POST with body
auto response = client->postBody("my_test_body");
auto dto = response->readBodyToDto<app::TestDto>(objectMapper);
OATPP_ASSERT(dto);

View File

@ -39,6 +39,7 @@ class Client : public oatpp::web::client::ApiClient {
API_CALL("GET", "params/{param}", getWithParams, PATH(String, param))
API_CALL("GET", "headers", getWithHeaders, HEADER(String, param, "X-TEST-HEADER"))
API_CALL("POST", "body", postBody, BODY_STRING(String, body))
API_CALL("POST", "echo", echoBody, BODY_STRING(String, body))
#include OATPP_CODEGEN_END(ApiClient)
};

View File

@ -39,7 +39,7 @@ private:
static constexpr const char* TAG = "test::web::app::ControllerAsync";
public:
ControllerAsync(const std::shared_ptr<ObjectMapper>& objectMapper)
: oatpp::web::server::api::ApiController(objectMapper)
: oatpp::web::server::api::ApiController(objectMapper)
{}
public:
@ -105,6 +105,22 @@ public:
}
};
ENDPOINT_ASYNC("POST", "echo", Echo) {
ENDPOINT_ASYNC_INIT(Echo)
Action act() {
OATPP_LOGD(TAG, "POST body(echo). Reading body...");
return request->readBodyToStringAsync(this, &PostBody::onBodyRead);
}
Action onBodyRead(const String& body) {
OATPP_LOGD(TAG, "POST echo size=%d", body->getSize());
return _return(controller->createResponse(Status::CODE_200, body));
}
};
#include OATPP_CODEGEN_END(ApiController)