|
32 | 32 | xor (Server and then PSK_Server_Callback not in null) |
33 | 33 | else |
34 | 34 | (PSK_Client_Callback not in null xor PSK_Server_Callback not in null)), |
35 | | - Relaxed_Initialization => Socket, |
36 | | - Global => null; |
| 35 | + Relaxed_Initialization => Socket; |
37 | 36 |
|
| 37 | + -- Accept client connections on a server socket. |
38 | 38 | procedure Accept_Connection |
39 | 39 | (Socket : in out Socket_Type) |
40 | 40 | with |
41 | | - -- Pre => Is_Valid (Socket), |
42 | | - Global => |
43 | | - null; |
| 41 | + Pre => Is_Valid (Socket); |
44 | 42 |
|
45 | 43 | procedure Shutdown |
46 | 44 | (Socket : in out Socket_Type) |
47 | 45 | with |
48 | | - Pre => Is_Valid (Socket), |
49 | | - Global => null; |
| 46 | + Pre => Is_Valid (Socket); |
50 | 47 |
|
| 48 | + -- When the socket is valid, it means that it has been correctly initialized. |
51 | 49 | function Is_Valid (Socket : Socket_Type) return Boolean with |
52 | 50 | Global => |
53 | 51 | null; |
54 | 52 |
|
| 53 | + -- Is ready to send or receive data. Is ready to connect, when it is a client socket. |
| 54 | + function Is_Ready (Socket : Socket_Type) return Boolean with |
| 55 | + Global => |
| 56 | + null; |
| 57 | + |
| 58 | + -- Connect to a server. |
55 | 59 | procedure Connect (Socket : in out Socket_Type; |
56 | 60 | Server : String; |
57 | 61 | Port : Port_Type := Default_Port) with |
58 | | - Pre => Is_Valid (Socket), |
59 | | - Global => |
60 | | - null; |
| 62 | + Pre => Is_Ready (Socket); |
61 | 63 |
|
62 | 64 | use type RFLX.RFLX_Builtin_Types.Index; |
63 | 65 |
|
64 | 66 | procedure Send (Socket : in out Socket_Type; |
65 | 67 | Buffer : RFLX.RFLX_Builtin_Types.Bytes) with |
66 | | - Pre => Is_Valid (Socket) and then Buffer'First = 1, |
67 | | - Global => |
68 | | - null; |
69 | | - |
70 | | - procedure Send_To (Socket : in out Socket_Type; |
71 | | - Buffer : RFLX.RFLX_Builtin_Types.Bytes; |
72 | | - To : Address_Type) with |
73 | | - Pre => Is_Valid (Socket) and then |
74 | | - Buffer'First = 1 and then |
75 | | - Is_Valid (To), |
76 | | - Global => |
77 | | - null; |
| 68 | + Pre => Is_Ready (Socket) and then Buffer'First = 1; |
78 | 69 |
|
79 | 70 | use type RFLX.RFLX_Builtin_Types.Length; |
80 | 71 |
|
81 | 72 | procedure Receive (Socket : in out Socket_Type; |
82 | 73 | Buffer : out RFLX.RFLX_Builtin_Types.Bytes; |
83 | 74 | Length : out RFLX.RFLX_Builtin_Types.Length) with |
84 | 75 | Relaxed_Initialization => (Buffer), |
85 | | - Pre => Is_Valid (Socket) and then Buffer'First = 1, |
| 76 | + Pre => Is_Ready (Socket) and then Buffer'First = 1, |
86 | 77 | Post => |
87 | 78 | Length <= Buffer'Length and then |
88 | | - Buffer (Buffer'First .. RFLX.RFLX_Builtin_Types.Index'Base (Length))'Initialized, |
89 | | - Global => |
90 | | - null; |
91 | | - |
92 | | - procedure Receive (Socket : in out Socket_Type; |
93 | | - Buffer : out RFLX.RFLX_Builtin_Types.Bytes; |
94 | | - Length : out RFLX.RFLX_Builtin_Types.Length; |
95 | | - From : out Address_Type) with |
96 | | - Relaxed_Initialization => (Buffer), |
97 | | - Pre => Is_Valid (Socket) and then Buffer'First = 1, |
98 | | - Post => |
99 | | - Length <= Buffer'Length and then |
100 | | - Buffer (Buffer'First .. RFLX.RFLX_Builtin_Types.Index'Base (Length))'Initialized and then |
101 | | - Is_Valid (From), |
102 | | - Global => |
103 | | - null; |
| 79 | + Buffer (Buffer'First .. RFLX.RFLX_Builtin_Types.Index'Base (Length))'Initialized; |
104 | 80 |
|
105 | 81 | function Has_Attached_Socket (Socket : Socket_Type) return Boolean; |
106 | 82 |
|
@@ -141,7 +117,10 @@ private |
141 | 117 | (Has_Attached_Socket (Socket) |
142 | 118 | and then |
143 | 119 | (if Socket.Is_Secure then Socket.Result = WolfSSL.Success and then |
144 | | - -- WolfSSL.Is_Valid (Socket.Ssl) and then |
145 | 120 | WolfSSL.Is_Valid (Socket.Ctx))); |
146 | 121 |
|
| 122 | + function Is_Ready (Socket : Socket_Type) return Boolean |
| 123 | + is (Is_Valid (Socket) |
| 124 | + and then (if Socket.Is_Secure then WolfSSL.Is_Valid (Socket.Ssl))); |
| 125 | + |
147 | 126 | end CoAP_SPARK.Channel; |
0 commit comments