/*
- * Copyright (c) 2017-2022 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2017-2024 Samsung Electronics Co., Ltd. All rights reserved.
*
* This file is licensed under the terms of MIT License or the Apache License
* Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
#include <utility>
#include <channel.h>
+#include <dpl/log/log.h>
#define BUFFER_SIZE 4096
const auto s = TEMP_FAILURE_RETRY(::read(m_in, buffer.Ptr(), buffer.InputSize()));
if (s <= 0)
return false;
- switch (buffer.InputDone(s)) {
- case MessageBuffer::InputResult::ProtocolBroken:
- return false;
- case MessageBuffer::InputResult::Pending:
- break;
- case MessageBuffer::InputResult::Done:
- buffer.ModeStreaming();
- return true;
+ try {
+ switch (buffer.InputDone(s)) {
+ case MessageBuffer::InputResult::ProtocolBroken:
+ return false;
+ case MessageBuffer::InputResult::Pending:
+ break;
+ case MessageBuffer::InputResult::Done:
+ buffer.ModeStreaming();
+ return true;
+ }
+ } catch (const std::bad_alloc &e) {
+ LogError("Allocation problem in channel::read " << e.what());
+ return false;
}
}
}
LogErrno("read");
return SECURITY_MANAGER_ERROR_SOCKET;
}
- switch (buffer.InputDone(temp)) {
- case MessageBuffer::InputResult::ProtocolBroken:
- return SECURITY_MANAGER_ERROR_SOCKET;
- case MessageBuffer::InputResult::Pending:
- break;
- case MessageBuffer::InputResult::Done:
- buffer.ModeStreaming();
- return SECURITY_MANAGER_SUCCESS;
+ try {
+ switch (buffer.InputDone(temp)) {
+ case MessageBuffer::InputResult::ProtocolBroken:
+ return SECURITY_MANAGER_ERROR_SOCKET;
+ case MessageBuffer::InputResult::Pending:
+ break;
+ case MessageBuffer::InputResult::Done:
+ buffer.ModeStreaming();
+ return SECURITY_MANAGER_SUCCESS;
+ }
+ } catch (const std::bad_alloc &e) {
+ LogError("Allocation problem in sendToServer " << e.what());
+ return SECURITY_MANAGER_ERROR_SOCKET;
}
}
}
goto close;
}
} else {
- switch (buffer.InputDone(size)) {
- case MessageBuffer::InputResult::ProtocolBroken:
- goto close;
- case MessageBuffer::InputResult::Pending:
- break;
- case MessageBuffer::InputResult::Done:
- buffer.ModeStreaming();
-
- if (buffer.DeserializationDone()) {
- LogError("No priority, closing socket");
- goto close;
- }
- std::underlying_type_t<Priority> priority;
- Deserialization::Deserialize(buffer, priority);
- if (priority >= Priority::END) {
- LogError("Invalid priority: " << priority);
+ try {
+ switch (buffer.InputDone(size)) {
+ case MessageBuffer::InputResult::ProtocolBroken:
goto close;
- }
-
- FD_CLR(sock, &m_readSet); // the one and only call on this socket is complete
- m_service->PutEvent(static_cast<Priority>(priority),
- ConnectionID{sock, desc.counter},
- Credentials::getCredentialsFromSocket(sock),
- std::move(buffer));
- break;
+ case MessageBuffer::InputResult::Pending:
+ break;
+ case MessageBuffer::InputResult::Done:
+ buffer.ModeStreaming();
+
+ if (buffer.DeserializationDone()) {
+ LogError("No priority, closing socket");
+ goto close;
+ }
+ std::underlying_type_t<Priority> priority;
+ Deserialization::Deserialize(buffer, priority);
+ if (priority >= Priority::END) {
+ LogError("Invalid priority: " << priority);
+ goto close;
+ }
+
+ FD_CLR(sock, &m_readSet); // the one and only call on this socket is complete
+ m_service->PutEvent(static_cast<Priority>(priority),
+ ConnectionID{sock, desc.counter},
+ Credentials::getCredentialsFromSocket(sock),
+ std::move(buffer));
+ break;
+ }
+ } catch (const std::bad_alloc &e) {
+ LogError("Allocation problem in ReadyForRead " << e.what());
+ goto close;
}
}