rustyphoenixsocket/socket_flag.rs
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7///The Socket mode determine how the PGenericSocket will behave :
8/// - `NoMock` : Normal usage of the socket with the official backend
9/// - `Mock` : Mock backend is used and replace the official backend behaviour
10/// - `MockRecord` : Mock backend is spying what the official backend is doing, so it can be replayed after
11#[derive(Debug, PartialEq, Copy, Clone)]
12pub enum PSocketMode {
13 ///Normal usage of the socket with the official backend
14 NoMock,
15 ///Mock backend is used and replace the official backend behaviour
16 Mock,
17 ///Mock backend is spying what the official backend is doing, so it can be replayed after
18 MockRecord,
19}
20
21///Describe the sending flag of the Socket
22/// - `Block` : Normal usage of the Socket. Blocking until a message is sent
23/// - `NonBlock` : The Socket send does not stop the execution of the program
24#[derive(Debug, PartialEq, Copy, Clone)]
25pub enum PSendFlag {
26 ///Normal usage of the Socket. Blocking until a message is sent
27 Block,
28 ///The Socket send does not stop the execution of the program
29 NonBlock,
30}
31
32///Describe the result of the send
33/// - `Ok` : Everything is OK
34/// - `SocketNotAvailable` : The socket is not available
35/// - `NoRouteToReciever` : The reciever cannot be reached, maybe caused by network problem
36/// - `SignalInteruption` : The socket cought a signal
37/// - `BrokenBackend` : The backend is broken
38/// - `BrokenSocket` : The socket is broken and cannot longer be used
39/// - `CannotSerializeData` : The data cannot be serialized in the message. Could happened from the [DataStream](rusty_phoenix_data_stream::DataStream) if some types do not implement well the [DataStream](rusty_phoenix_data_stream::DataStream) trait.
40#[derive(Debug, PartialEq, Copy, Clone)]
41pub enum PSendStatus {
42 ///Everything is OK
43 Ok,
44 ///The socket is not available
45 SocketNotAvailable,
46 ///The reciever cannot be reached, maybe caused by network problem
47 NoRouteToReciever,
48 ///The socket cought a signal. This value exist because zeromq socket tends to take it very badly when it recieves a signal. Thus, this is quite anoying and we have to take that int account
49 SignalInteruption,
50 ///The backend is broken
51 BrokenBackend,
52 ///The socket is broken and cannot longer be used
53 BrokenSocket,
54 ///The data cannot be serialized in the message
55 CannotSerializeData
56}
57
58///describe the receiving flag of the Socket
59/// - `Block` : Normal usage of the Socket. Blocking until a message comes
60/// - `NonBlock` : The Socket recv does not stop the execution of the program
61#[derive(Debug, PartialEq, Copy, Clone)]
62pub enum PRecvFlag {
63 ///Normal usage of the Socket. Blocking until a message comes
64 Block,
65 ///The Socket recv does not stop the execution of the program
66 NonBlock,
67}
68
69///describe the result of the recv
70/// - `Ok` : Everything is OK and a message was recieved
71/// - `NoMessageRecieved` : No message was recieved
72/// - `InvalidMessage` : The recieved message is invalid
73/// - `SocketNotAvailable` : The socket is not available
74/// - `NoRouteToSender` : The sender cannot be reached, maybe caused by network problem
75/// - `SignalInteruption` : The socket cought a signal. This value exist because zeromq socket tends to take it very badly when it recieves a signal. Thus, this is quite anoying and we have to take that int account
76/// - `BrokenBackend` : The backend is broken. Sounds not obvious but this could happened again in zeromq.
77/// - `BrokenSocket` : The socket is broken and cannot longer be used
78/// - `CannotDeserializeData` : The data cannot be deserialize from the message. Could happened from the [DataStream](rusty_phoenix_data_stream::DataStream) trait maybe with wrongly formated data.
79#[derive(Debug, PartialEq, Copy, Clone)]
80pub enum PRecvStatus {
81 ///Everything is OK and a message was recieved
82 Ok,
83 ///No message was recieved
84 NoMessageRecieved,
85 ///The recieved message is invalid
86 InvalidMessage,
87 ///The socket is not available
88 SocketNotAvailable,
89 ///The sender cannot be reached, maybe caused by network problem
90 NoRouteToSender,
91 ///The socket cought a signal. This value exist because zeromq socket tends to take it very badly when it recieves a signal. Thus, this is quite anoying and we have to take that int account
92 SignalInteruption,
93 ///The backend is broken
94 BrokenBackend,
95 ///The socket is broken and cannot longer be used
96 BrokenSocket,
97 ///The data cannot be deserialize from the message
98 CannotDeserializeData
99}
100
101///Parameters to create a socket
102#[derive(Debug, PartialEq, Clone)]
103pub struct PSocketParam{
104 ///Name of the host to be connected to
105 hostname: String,
106 ///Port to be connected to
107 port: u16,
108 ///Timeout of the recv method
109 recv_time_out: i32,
110 ///Timeout of the send method
111 send_time_out: i32,
112}
113
114impl PSocketParam{
115 ///Create a PGenericSocketManager
116 /// # Parameters
117 /// - `mode` - mode of the PGenericSocketManager
118 /// # Returns
119 /// constructed PGenericSocketManager
120 pub fn new(hostname: &String, port: u16, recv_time_out: i32, send_time_out: i32) -> Self {
121 PSocketParam{
122 hostname: hostname.to_string(),
123 port: port,
124 recv_time_out: recv_time_out,
125 send_time_out: send_time_out,
126 }
127 }
128}
129
130impl Default for PSocketParam{
131 ///Default constructor of PSocketParam
132 fn default() -> Self{
133 PSocketParam{
134 hostname: String::from("localhost"),
135 port: 3390,
136 recv_time_out: -1,
137 send_time_out: -1
138 }
139 }
140}
141
142
143
144
145
146