@@ -35,12 +35,6 @@ static void _on_response_timeout(unicoap_scheduled_event_t* timeout) {
3535 unicoap_client_memo_free (unicoap_client_memo_of_timeout (timeout ));
3636}
3737
38- static void _on_multicast_response_timeout (unicoap_scheduled_event_t * timeout )
39- {
40- _CLIENT_DEBUG ("multicast window closed\n" );
41- unicoap_client_memo_free (unicoap_client_memo_of_multicast_timeout (timeout ));
42- }
43-
4438int unicoap_client_callback_success (unicoap_client_memo_t * memo , const unicoap_packet_t * packet ,
4539 unicoap_block_option_t block ) {
4640 (void )block ;
@@ -141,6 +135,18 @@ int unicoap_client_send_request_body(unicoap_message_t* request,
141135 .token_length = sizeof (token ),
142136 } };
143137
138+ ipv6_addr_t ep_addr ;
139+ memcpy (ep_addr .u8 , endpoint -> _tl_ep .addr .ipv6 , 16 );
140+ bool multicast = endpoint -> _tl_ep .family == AF_INET6 && ipv6_addr_is_multicast (& ep_addr );
141+
142+ if (multicast ) {
143+ if (flags && UNICOAP_CLIENT_FLAG_RELIABLE ) {
144+ _CLIENT_DEBUG ("error trying to send reliable datagram via multicast\n" );
145+ return - EINVAL ;
146+ }
147+ flags |= UNICOAP_CLIENT_FLAG_MULTICAST ;
148+ }
149+
144150 if (unicoap_callback_is_present (callback )) {
145151 _CLIENT_DEBUG ("need a memo\n" );
146152 if (!(memo = unicoap_client_memo_create (endpoint ))) {
@@ -150,26 +156,13 @@ int unicoap_client_send_request_body(unicoap_message_t* request,
150156 memo -> callback_arg = callback_arg ;
151157 memo -> flags = flags ;
152158
153- unicoap_event_schedule (& memo -> super .exchange .timeout , _on_response_timeout ,
154- CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS );
155- }
156-
157- ipv6_addr_t addr ;
158- memcpy (addr .u8 , endpoint -> _tl_ep .addr .ipv6 , 16 );
159-
160- if (endpoint -> _tl_ep .family == AF_INET6 && ipv6_addr_is_multicast (& addr )) {
161- flags |= UNICOAP_CLIENT_FLAG_MULTICAST ;
162-
163- if (memo && (CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS > 0 )) {
164- unicoap_event_schedule (& memo -> super .multicast .timeout , _on_multicast_response_timeout ,
159+ if (!multicast ) {
160+ unicoap_event_schedule (& memo -> super .exchange .timeout , _on_response_timeout ,
161+ CONFIG_UNICOAP_TIMEOUT_CLIENT_RESPONSE_MS );
162+ } else if (CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS > 0 ) {
163+ unicoap_event_schedule (& memo -> super .exchange .timeout , _on_response_timeout ,
165164 CONFIG_UNICOAP_TIMEOUT_CLIENT_MULTICAST_RESPONSE_MS );
166165 }
167-
168- if (flags == UNICOAP_CLIENT_FLAG_RELIABLE ) {
169- _CLIENT_DEBUG ("error trying to send reliable datagram via multicastn" );
170- unicoap_client_callback_failure (memo , - EINVAL );
171- goto error ;
172- }
173166 }
174167
175168 /* TODO: OSCORE */
0 commit comments