Function anjay_download

Function Documentation

avs_error_t anjay_download(anjay_t *anjay, const anjay_download_config_t *config, anjay_download_handle_t *out_handle)

Requests asynchronous download of an external resource.

Download will create a new socket that will be later included in the list returned by anjay_get_sockets . Calling anjay_serve on such socket may cause calling anjay_download_config_t::on_next_block if received packet is the next expected chunk of downloaded data and anjay_download_finished_handler_t if the transfer completes or fails. Request packet retransmissions are managed by Anjay scheduler, and sent by anjay_sched_run whenever required.

No network activity is performed immediately during the call to anjay_download(). Instead, the TCP and/or (D)TLS handshakes and the first request packet, will be sent during subsequent calls to anjay_sched_run. This also means that you can create a postponed download by calling anjay_download_suspend immediately afterwards.

The behavior of the CoAP downloader can be also affected by the anjay_configuration_t::coap_downloader_retry_count and anjay_configuration_t::coap_downloader_retry_delay.

Parameters:
  • anjay – Anjay object that will manage the download process.

  • config – Download configuration.

  • out_handle – Pointer to a variable that will be set to a download handle, that may be used for aborting the download. MUST NOT be NULL.

Returns:

  • AVS_OK on success, in which case *out_handle is set to a handle to the created download,

  • Code of the error that happened, in which case *out_handle is not modified, and anjay_download_config_t::on_download_finished handler is NOT called.