better sigpipe handling

This commit is contained in:
lganzzzo 2018-04-02 04:38:57 +03:00
parent a8e85fa6d5
commit 82c0d19600
6 changed files with 15 additions and 22 deletions

View File

@ -87,7 +87,7 @@ class AbstractCoroutine {
friend oatpp::collection::FastQueue<AbstractCoroutine>;
friend Processor;
public:
typedef Action Action;
typedef oatpp::async::Action Action;
typedef Action (AbstractCoroutine::*FunctionPtr)();
public:

View File

@ -31,7 +31,7 @@
#include <atomic>
#include <list>
#include <unordered_map>
#include <cstring>
//#define OATPP_DISABLE_POOL_ALLOCATIONS
//#ifndef OATPP_MEMORY_POOL_SHARDING
@ -201,7 +201,7 @@ private:
v_int32 newSize = m_size + m_growSize;
T** newIndex = new T*[newSize];
memcmp(newIndex, m_index, m_size);
std::memcpy(newIndex, m_index, m_size);
Block* b = new Block(new v_char8 [m_growSize * sizeof(T)], m_blocks);
m_blocks = b;

View File

@ -75,13 +75,7 @@ oatpp::async::Action IOStream::writeDataAsyncInline(oatpp::data::stream::OutputS
const void*& data,
os::io::Library::v_size& size,
const oatpp::async::Action& nextAction) {
os::io::Library::v_size chunkSize;
if(size > oatpp::data::buffer::IOBuffer::BUFFER_SIZE){
chunkSize = oatpp::data::buffer::IOBuffer::BUFFER_SIZE;
} else {
chunkSize = size;
}
auto res = stream->write(data, chunkSize);
auto res = stream->write(data, size);
if(res == oatpp::data::stream::IOStream::ERROR_IO_WAIT_RETRY) {
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::IOStream::ERROR_IO_RETRY) {
@ -107,8 +101,6 @@ oatpp::async::Action IOStream::readSomeDataAsyncInline(oatpp::data::stream::Inpu
return oatpp::async::Action::_WAIT_RETRY;
} else if(res == oatpp::data::stream::IOStream::ERROR_IO_RETRY) {
return oatpp::async::Action::_REPEAT;
} else if(res == oatpp::data::stream::IOStream::ERROR_IO_PIPE) {
return oatpp::async::Action::_ABORT;
} else if( res < 0) {
return oatpp::async::Action(oatpp::async::Error(ERROR_ASYNC_FAILED_TO_READ_DATA));
} else if(res < bytesLeftToRead) {

View File

@ -39,7 +39,11 @@ Library::v_size Library::handle_read(v_handle handle, void *buf, v_size count){
}
Library::v_size Library::handle_write(v_handle handle, const void *buf, v_size count){
return write(handle, buf, count);
v_int32 flags = 0;
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
#endif
return send(handle, buf, count, flags);
}
}}}

View File

@ -61,11 +61,6 @@ oatpp::os::io::Library::v_handle SimpleTCPConnectionProvider::instantiateServer(
OATPP_LOGD("SimpleTCPConnectionProvider", "Warning failed to set %s for accepting socket", "SO_REUSEADDR");
}
ret = setsockopt(serverHandle, SOL_SOCKET, SO_NOSIGPIPE, &yes, sizeof(int));
if(ret < 0) {
OATPP_LOGD("SimpleTCPConnectionProvider", "Warning failed to set %s for accepting socket", "SO_NOSIGPIPE");
}
ret = bind(serverHandle, (struct sockaddr *)&addr, sizeof(addr));
if(ret != 0) {
@ -102,11 +97,13 @@ std::shared_ptr<oatpp::data::stream::IOStream> SimpleTCPConnectionProvider::getC
}
}
#ifdef SO_NOSIGPIPE
int yes = 1;
v_int32 ret = setsockopt(handle, SOL_SOCKET, SO_NOSIGPIPE, &yes, sizeof(int));
if(ret < 0) {
OATPP_LOGD("SimpleTCPConnectionProvider", "Warning failed to set %s for accepting socket", "SO_NOSIGPIPE");
OATPP_LOGD("SimpleTCPConnectionProvider", "Warning failed to set %s for socket", "SO_NOSIGPIPE");
}
#endif
int flags = 0;
if(m_nonBlocking) {

View File

@ -198,11 +198,11 @@ HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::onRequestDone() {
HttpProcessor::Coroutine::Action HttpProcessor::Coroutine::handleError(const oatpp::async::Error& error) {
if(m_currentResponse) {
if(error.isExceptionThrown) {
OATPP_LOGD("Server", "onHandleError. Forwarding error. %s", "Unknown");
OATPP_LOGD("Server", "Unhandled exception. Dropping connection");
} else {
OATPP_LOGD("Server", "onHandleError. Forwarding error. %s", error.message);
OATPP_LOGD("Server", "Unhandled error. '%s'. Dropping connection", error.message);
}
return error;
return abort();
}
if (error.isExceptionThrown) {
try{