Lines Matching refs:internal_req

28 static bool timeout_expired(struct coap_client_internal_request *internal_req);
89 struct coap_client_internal_request *internal_req) in coap_client_schedule_poll() argument
92 memcpy(&internal_req->coap_request, req, sizeof(struct coap_client_request)); in coap_client_schedule_poll()
93 internal_req->request_ongoing = true; in coap_client_schedule_poll()
100 static bool exchange_lifetime_exceeded(struct coap_client_internal_request *internal_req) in exchange_lifetime_exceeded() argument
104 if (coap_header_get_type(&internal_req->request) == COAP_TYPE_NON_CON) { in exchange_lifetime_exceeded()
108 if (internal_req->pending.t0 == 0) { in exchange_lifetime_exceeded()
112 time_since_t0 = k_uptime_get() - internal_req->pending.t0; in exchange_lifetime_exceeded()
114 (internal_req->pending.params.ack_timeout * COAP_EXCHANGE_LIFETIME_FACTOR); in exchange_lifetime_exceeded()
199 struct coap_client_internal_request *internal_req, in coap_client_init_request() argument
211 internal_req->last_id = coap_next_id(); in coap_client_init_request()
212 internal_req->request_tkl = COAP_TOKEN_MAX_LEN & 0xf; in coap_client_init_request()
213 memcpy(internal_req->request_token, token, internal_req->request_tkl); in coap_client_init_request()
216 ret = coap_packet_init(&internal_req->request, client->send_buf, MAX_COAP_MSG_LEN, in coap_client_init_request()
218 COAP_TOKEN_MAX_LEN, internal_req->request_token, req->method, in coap_client_init_request()
219 internal_req->last_id); in coap_client_init_request()
226 ret = coap_packet_set_path(&internal_req->request, req->path); in coap_client_init_request()
235 ret = coap_append_option_int(&internal_req->request, in coap_client_init_request()
245 if (internal_req->recv_blk_ctx.current > 0) { in coap_client_init_request()
247 ret = coap_append_block2_option(&internal_req->request, in coap_client_init_request()
248 &internal_req->recv_blk_ctx); in coap_client_init_request()
266 ret = coap_packet_append_option(&internal_req->request, req->options[i].code, in coap_client_init_request()
280 if (internal_req->send_blk_ctx.total_size > 0 || in coap_client_init_request()
283 if (internal_req->send_blk_ctx.total_size == 0) { in coap_client_init_request()
284 coap_block_transfer_init(&internal_req->send_blk_ctx, in coap_client_init_request()
290 memcpy(internal_req->request_tag, tag, COAP_TOKEN_MAX_LEN); in coap_client_init_request()
292 ret = coap_append_block1_option(&internal_req->request, in coap_client_init_request()
293 &internal_req->send_blk_ctx); in coap_client_init_request()
300 ret = coap_packet_append_option(&internal_req->request, in coap_client_init_request()
301 COAP_OPTION_REQUEST_TAG, internal_req->request_tag, in coap_client_init_request()
310 ret = coap_packet_append_payload_marker(&internal_req->request); in coap_client_init_request()
317 if (internal_req->send_blk_ctx.total_size > 0) { in coap_client_init_request()
319 coap_block_size_to_bytes(internal_req->send_blk_ctx.block_size); in coap_client_init_request()
321 payload_len = internal_req->send_blk_ctx.total_size - in coap_client_init_request()
322 internal_req->send_blk_ctx.current; in coap_client_init_request()
326 offset = internal_req->send_blk_ctx.current; in coap_client_init_request()
332 ret = coap_packet_append_payload(&internal_req->request, req->payload + offset, in coap_client_init_request()
340 if (internal_req->send_blk_ctx.total_size > 0) { in coap_client_init_request()
341 coap_next_block(&internal_req->request, &internal_req->send_blk_ctx); in coap_client_init_request()
352 struct coap_client_internal_request *internal_req; in coap_client_req() local
360 internal_req = get_free_request(client); in coap_client_req()
362 if (internal_req == NULL) { in coap_client_req()
399 reset_internal_request(internal_req); in coap_client_req()
401 ret = coap_client_init_request(client, req, internal_req, false); in coap_client_req()
408 ret = coap_packet_append_option(&internal_req->request, COAP_OPTION_ECHO, in coap_client_req()
417 ret = coap_client_schedule_poll(client, sock, req, internal_req); in coap_client_req()
423 ret = coap_pending_init(&internal_req->pending, &internal_req->request, in coap_client_req()
434 if (coap_header_get_type(&internal_req->request) == COAP_TYPE_NON_CON) { in coap_client_req()
435 internal_req->pending.retries = 0; in coap_client_req()
437 coap_pending_cycle(&internal_req->pending); in coap_client_req()
438 internal_req->is_observe = coap_request_is_observe(&internal_req->request); in coap_client_req()
439 LOG_DBG("Request is_observe %d", internal_req->is_observe); in coap_client_req()
441 ret = send_request(sock, internal_req->request.data, internal_req->request.offset, 0, in coap_client_req()
450 reset_internal_request(internal_req); in coap_client_req()
460 static void report_callback_error(struct coap_client_internal_request *internal_req, int error_code) in report_callback_error() argument
462 if (internal_req->coap_request.cb) { in report_callback_error()
463 if (!atomic_set(&internal_req->in_callback, 1)) { in report_callback_error()
464 internal_req->coap_request.cb(error_code, 0, NULL, 0, true, in report_callback_error()
465 internal_req->coap_request.user_data); in report_callback_error()
466 atomic_clear(&internal_req->in_callback); in report_callback_error()
473 static bool timeout_expired(struct coap_client_internal_request *internal_req) in timeout_expired() argument
475 if (internal_req->pending.timeout == 0) { in timeout_expired()
479 return (internal_req->request_ongoing && in timeout_expired()
480 internal_req->pending.timeout <= (k_uptime_get() - internal_req->pending.t0)); in timeout_expired()
484 struct coap_client_internal_request *internal_req) in resend_request() argument
489 struct coap_pending tmp = internal_req->pending; in resend_request()
491 if (internal_req->request_ongoing && in resend_request()
492 internal_req->pending.timeout != 0 && in resend_request()
493 coap_pending_cycle(&internal_req->pending)) { in resend_request()
497 if (internal_req->send_blk_ctx.total_size > 0) { in resend_request()
498 internal_req->send_blk_ctx.current = internal_req->offset; in resend_request()
500 ret = coap_client_init_request(client, &internal_req->coap_request, in resend_request()
501 internal_req, true); in resend_request()
507 ret = send_request(client->fd, internal_req->request.data, in resend_request()
508 internal_req->request.offset, 0, &client->address, in resend_request()
514 internal_req->pending = tmp; in resend_request()
777 struct coap_client_internal_request *internal_req; in handle_response() local
794 internal_req = get_request_with_mid(client, response_id); in handle_response()
795 if (!internal_req) { in handle_response()
799 report_callback_error(internal_req, -ECONNRESET); in handle_response()
800 release_internal_request(internal_req); in handle_response()
807 internal_req = get_request_with_mid(client, response_id); in handle_response()
808 if (!internal_req) { in handle_response()
812 internal_req->pending.t0 = k_uptime_get(); in handle_response()
813 internal_req->pending.timeout = COAP_SEPARATE_TIMEOUT; in handle_response()
814 internal_req->pending.retries = 0; in handle_response()
818 internal_req = get_request_with_token(client, response); in handle_response()
819 if (!internal_req) { in handle_response()
829 ret = coap_client_init_request(client, &internal_req->coap_request, in handle_response()
830 internal_req, false); in handle_response()
837 ret = coap_packet_append_option(&internal_req->request, COAP_OPTION_ECHO, in handle_response()
845 if (coap_header_get_type(&internal_req->request) == COAP_TYPE_CON) { in handle_response()
847 internal_req->pending.params; in handle_response()
848 ret = coap_pending_init(&internal_req->pending, in handle_response()
849 &internal_req->request, &client->address, in handle_response()
856 coap_pending_cycle(&internal_req->pending); in handle_response()
859 ret = send_request(client->fd, internal_req->request.data, in handle_response()
860 internal_req->request.offset, 0, &client->address, in handle_response()
884 if (response_id == internal_req->last_response_id) { in handle_response()
889 internal_req->last_response_id = response_id; in handle_response()
891 if (!internal_req->request_ongoing) { in handle_response()
892 if (internal_req->is_observe) { in handle_response()
900 if (internal_req->pending.timeout != 0) { in handle_response()
901 coap_pending_clear(&internal_req->pending); in handle_response()
912 coap_block_transfer_init(&internal_req->recv_blk_ctx, in handle_response()
915 internal_req->offset = 0; in handle_response()
918 ret = coap_update_from_block(response, &internal_req->recv_blk_ctx); in handle_response()
922 coap_next_block(response, &internal_req->recv_blk_ctx); in handle_response()
924 internal_req->offset = 0; in handle_response()
929 if (internal_req->send_blk_ctx.total_size > 0) { in handle_response()
931 internal_req->offset = internal_req->send_blk_ctx.current; in handle_response()
932 if (internal_req->send_blk_ctx.total_size == internal_req->send_blk_ctx.current) { in handle_response()
947 if (internal_req->coap_request.cb) { in handle_response()
948 if (!atomic_set(&internal_req->in_callback, 1)) { in handle_response()
949 internal_req->coap_request.cb(response_code, internal_req->offset, payload, in handle_response()
951 internal_req->coap_request.user_data); in handle_response()
952 atomic_clear(&internal_req->in_callback); in handle_response()
954 if (!internal_req->request_ongoing) { in handle_response()
960 internal_req->offset += payload_len; in handle_response()
966 ret = coap_client_init_request(client, &internal_req->coap_request, internal_req, in handle_response()
974 struct coap_transmission_parameters params = internal_req->pending.params; in handle_response()
975 ret = coap_pending_init(&internal_req->pending, &internal_req->request, in handle_response()
981 coap_pending_cycle(&internal_req->pending); in handle_response()
983 ret = send_request(client->fd, internal_req->request.data, in handle_response()
984 internal_req->request.offset, 0, &client->address, in handle_response()
995 report_callback_error(internal_req, ret); in handle_response()
997 if (!internal_req->is_observe) { in handle_response()
998 release_internal_request(internal_req); in handle_response()