blob: f4ed2ebb23cd922405f9ea502dcca6934d5f4ebe [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynnbbfe6032020-07-20 16:57:44 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Sadik Armagana97a0be2020-03-03 10:44:56 +00003// SPDX-License-Identifier: MIT
4//
5#pragma once
6
7#include <sstream>
8#include <stdexcept>
9#include <string>
10
Rob Hughesb98032f2020-04-24 11:41:34 +010011#include "NetworkSockets.hpp"
12
Jim Flynnbbfe6032020-07-20 16:57:44 +010013namespace arm
14{
15
16namespace pipe
Sadik Armagana97a0be2020-03-03 10:44:56 +000017{
18
19/// Socket Connection Exception for profiling
20class SocketConnectionException : public std::exception
21{
22public:
Jim Flynne195a042022-04-12 17:19:28 +010023 explicit SocketConnectionException(const std::string& message
24#if !defined(ARMNN_DISABLE_SOCKETS)
25 , arm::pipe::Socket socket
26#endif
27 )
28 : m_Message(message),
29#if !defined(ARMNN_DISABLE_SOCKETS)
30 m_Socket(socket),
31#endif
32 m_ErrNo(-1) {};
Sadik Armagana97a0be2020-03-03 10:44:56 +000033
Jim Flynne195a042022-04-12 17:19:28 +010034 explicit SocketConnectionException(const std::string& message,
35#if !defined(ARMNN_DISABLE_SOCKETS)
36 arm::pipe::Socket socket,
37#endif
38 int errNo)
39 : m_Message(message),
40#if !defined(ARMNN_DISABLE_SOCKETS)
41 m_Socket(socket),
42#endif
43 m_ErrNo(errNo) {};
Sadik Armagana97a0be2020-03-03 10:44:56 +000044
45 /// @return - Error message of SocketProfilingConnection
Jim Flynne195a042022-04-12 17:19:28 +010046 virtual const char* what() const noexcept override
Sadik Armagana97a0be2020-03-03 10:44:56 +000047 {
48 return m_Message.c_str();
49 }
50
51 /// @return - Socket File Descriptor of SocketProfilingConnection
52 /// or '-1', an invalid file descriptor
Jim Flynne195a042022-04-12 17:19:28 +010053#if !defined(ARMNN_DISABLE_SOCKETS)
Jim Flynnbbfe6032020-07-20 16:57:44 +010054 arm::pipe::Socket GetSocketFd() const noexcept
Sadik Armagana97a0be2020-03-03 10:44:56 +000055 {
56 return m_Socket;
57 }
Jim Flynne195a042022-04-12 17:19:28 +010058#endif
Sadik Armagana97a0be2020-03-03 10:44:56 +000059
60 /// @return - errno of SocketProfilingConnection
61 int GetErrorNo() const noexcept
62 {
63 return m_ErrNo;
64 }
65
66private:
67 std::string m_Message;
Jim Flynne195a042022-04-12 17:19:28 +010068#if !defined(ARMNN_DISABLE_SOCKETS)
Jim Flynnbbfe6032020-07-20 16:57:44 +010069 arm::pipe::Socket m_Socket;
Jim Flynne195a042022-04-12 17:19:28 +010070#endif
Sadik Armagana97a0be2020-03-03 10:44:56 +000071 int m_ErrNo;
72};
Jim Flynnbbfe6032020-07-20 16:57:44 +010073} // namespace pipe
74} // namespace arm