1 // 2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 #pragma once 6 7 #include <sstream> 8 #include <stdexcept> 9 #include <string> 10 11 #include "NetworkSockets.hpp" 12 13 namespace arm 14 { 15 16 namespace pipe 17 { 18 19 /// Socket Connection Exception for profiling 20 class SocketConnectionException : public std::exception 21 { 22 public: SocketConnectionException(const std::string & message,arm::pipe::Socket socket)23 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) {}; 33 SocketConnectionException(const std::string & message,arm::pipe::Socket socket,int errNo)34 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) {}; 44 45 /// @return - Error message of SocketProfilingConnection what() const46 virtual const char* what() const noexcept override 47 { 48 return m_Message.c_str(); 49 } 50 51 /// @return - Socket File Descriptor of SocketProfilingConnection 52 /// or '-1', an invalid file descriptor 53 #if !defined(ARMNN_DISABLE_SOCKETS) GetSocketFd() const54 arm::pipe::Socket GetSocketFd() const noexcept 55 { 56 return m_Socket; 57 } 58 #endif 59 60 /// @return - errno of SocketProfilingConnection GetErrorNo() const61 int GetErrorNo() const noexcept 62 { 63 return m_ErrNo; 64 } 65 66 private: 67 std::string m_Message; 68 #if !defined(ARMNN_DISABLE_SOCKETS) 69 arm::pipe::Socket m_Socket; 70 #endif 71 int m_ErrNo; 72 }; 73 } // namespace pipe 74 } // namespace arm 75