Throw exception instead of returning error code from send function.
Change-Id: I87d2805dfb7f8757c0366600d8937023edddf54a
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/message_handler.cpp b/message_handler.cpp
index ef9eb06..e66e39c 100644
--- a/message_handler.cpp
+++ b/message_handler.cpp
@@ -163,7 +163,7 @@
return command;
}
-int Handler::send(Message& outMessage)
+void Handler::send(Message& outMessage)
{
auto session = (std::get<session::Manager&>(singletonPool).getSession(
sessionID)).lock();
@@ -171,15 +171,12 @@
// Flatten the packet
auto packet = parser::flatten(outMessage, sessionHeader, *session);
- // Read the packet
+ // Write the packet
auto writeStatus = channel->write(packet);
if (writeStatus < 0)
{
- std::cerr << "E> Error in writing : " << std::hex << writeStatus
- << "\n";
+ throw std::runtime_error("Error in writing to socket");
}
-
- return writeStatus;
}
void Handler::setChannelInSession() const
diff --git a/message_handler.hpp b/message_handler.hpp
index 0f553b7..882a077 100644
--- a/message_handler.hpp
+++ b/message_handler.hpp
@@ -50,17 +50,14 @@
*/
std::unique_ptr<Message> executeCommand(Message& inMessage);
- /*
- * @brief Send the outgoing message
+ /** @brief Send the outgoing message
*
- * The payload in the outgoing message is flattened and sent out on the
- * socket
+ * The payload in the outgoing message is flattened and sent out on the
+ * socket
*
- * @param[in] outMessage - Outgoing Message
- *
- * @return Zero on success and <0 on failure
+ * @param[in] outMessage - Outgoing Message
*/
- int send(Message& outMessage);
+ void send(Message& outMessage);
/** @brief Set socket channel in session object */
void setChannelInSession() const;