| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __PSOCKET_FLAG_H__ | ||
| 8 | #define __PSOCKET_FLAG_H__ | ||
| 9 | |||
| 10 | #include <string> | ||
| 11 | |||
| 12 | namespace PSendFlag{ | ||
| 13 | ///@brief describe the sending flag of the Socket | ||
| 14 | enum PSendFlag{ | ||
| 15 | BLOCK, //Normal usage of the Socket. Blocking until a message is sent | ||
| 16 | NON_BLOCK //The Socket send does not stop the execution of the program | ||
| 17 | }; | ||
| 18 | } | ||
| 19 | |||
| 20 | std::string daemonToString(PSendFlag::PSendFlag flag); | ||
| 21 | PSendFlag::PSendFlag daemonSendFlagFromString(const std::string & str); | ||
| 22 | |||
| 23 | namespace PSendStatus{ | ||
| 24 | ///@brief describe the result of the send | ||
| 25 | enum PSendStatus{ | ||
| 26 | OK, //Everything is OK | ||
| 27 | SOCKET_NOT_AVAILABLE, //The socket is not available | ||
| 28 | NO_ROUTE_TO_RECEIVER, //The receiver cannot be reached, maybe caused by network problem | ||
| 29 | SIGNAL_INTERRUPTION, //The socket caught a signal | ||
| 30 | BROKEN_BACKEND, //The backend is broken | ||
| 31 | BROKEN_SOCKET, //The socket is broken and cannot longer be used | ||
| 32 | CANNOT_SERIALIZE_DATA //The data cannot be serialized in the message | ||
| 33 | }; | ||
| 34 | } | ||
| 35 | |||
| 36 | std::string daemonToString(PSendStatus::PSendStatus flag); | ||
| 37 | PSendStatus::PSendStatus daemonSendStatusFromString(const std::string & str); | ||
| 38 | |||
| 39 | namespace PRecvFlag{ | ||
| 40 | ///@brief describe the receiving flag of the Socket | ||
| 41 | enum PRecvFlag{ | ||
| 42 | BLOCK, //Normal usage of the Socket. Blocking until a message comes | ||
| 43 | NON_BLOCK //The Socket recv does not stop the execution of the program | ||
| 44 | }; | ||
| 45 | } | ||
| 46 | |||
| 47 | std::string daemonToString(PRecvFlag::PRecvFlag flag); | ||
| 48 | PRecvFlag::PRecvFlag daemonRecvFlagFromString(const std::string & str); | ||
| 49 | |||
| 50 | namespace PRecvStatus{ | ||
| 51 | ///@brief describe the result of the recv | ||
| 52 | enum PRecvStatus{ | ||
| 53 | OK, //Everything is OK | ||
| 54 | NO_MESSAGE_RECEIVED, //No message was received | ||
| 55 | INVALID_MESSAGE, //The received message is invalid | ||
| 56 | SOCKET_NOT_AVAILABLE, //The socket is not available | ||
| 57 | SIGNAL_INTERRUPTION, //The socket caught a signal | ||
| 58 | BROKEN_BACKEND, //The backend is broken | ||
| 59 | BROKEN_SOCKET, //The socket is broken and cannot longer be used | ||
| 60 | CANNOT_DESERIALIZE_DATA //Cannot deserialize data | ||
| 61 | }; | ||
| 62 | } | ||
| 63 | |||
| 64 | std::string daemonToString(PRecvStatus::PRecvStatus flag); | ||
| 65 | PRecvStatus::PRecvStatus daemonRecvStatusFromString(const std::string & str); | ||
| 66 | |||
| 67 | ///@brief Parameters to create a socket | ||
| 68 | struct PSocketParam{ | ||
| 69 | ///Name of the host to be connected to | ||
| 70 | std::string hostname; | ||
| 71 | ///Port to be connected to | ||
| 72 | size_t port; | ||
| 73 | ///Timeout of the recv method | ||
| 74 | int recvTimeOut{-1}; | ||
| 75 | ///Timeout of the send method | ||
| 76 | int sendTimeOut{-1}; | ||
| 77 | }; | ||
| 78 | |||
| 79 | ///Assert especially designed to catch exception and abort if no exception is raised | ||
| 80 | #define PHOENIX_ASSERT_EXCEPTION(X) {\ | ||
| 81 | bool isWrongSend = false;\ | ||
| 82 | try{\ | ||
| 83 | X;\ | ||
| 84 | }catch(...){\ | ||
| 85 | isWrongSend = true;\ | ||
| 86 | }\ | ||
| 87 | data_stream_assert(isWrongSend);\ | ||
| 88 | } | ||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 |