mirror of
https://github.com/oatpp/oatpp.git
synced 2025-04-12 18:50:22 +08:00
better sigpipe handling
This commit is contained in:
parent
a8e85fa6d5
commit
82c0d19600
@ -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:
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}}}
|
||||
|
@ -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) {
|
||||
|
@ -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{
|
||||
|
Loading…
x
Reference in New Issue
Block a user