Skip to content

Commit

Permalink
plgd-time: fix closing of session on fetch
Browse files Browse the repository at this point in the history
Only OC_CONNECTION_CLOSED closes the session and invokes the
session handler. Timeout status code just invoke and remove
the client cb, the session is kept intact.
  • Loading branch information
Danielius1922 authored and Daniel Adam committed May 1, 2023
1 parent 3ce7375 commit c35939c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 11 deletions.
8 changes: 0 additions & 8 deletions api/oc_ri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,14 +1658,6 @@ oc_ri_remove_client_cb(void *data)
return OC_EVENT_DONE;
}

bool
oc_ri_client_cb_terminated(oc_status_t code)
{
return code == OC_PING_TIMEOUT || code == OC_REQUEST_TIMEOUT ||
code == OC_CONNECTION_CLOSED || code == OC_TRANSACTION_TIMEOUT ||
code == OC_CANCELLED;
}

static void
notify_client_cb_with_code(oc_client_cb_t *cb, oc_status_t code)
{
Expand Down
3 changes: 1 addition & 2 deletions api/plgd/plgd_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,7 @@ dev_time_on_fetch(oc_client_response_t *data)
OC_DBG("plgd-time: on_fetch time=%d time=%u", (int)code, (unsigned)time);
fp->on_fetch(code, time, fp->on_fetch_data);
#if defined(OC_TCP) || defined(OC_SECURITY)
// session is closed automatically on timeout, close or cancel
if (fp->close_peer_after_fetch && !oc_ri_client_cb_terminated(code)) {
if (fp->close_peer_after_fetch && (code != OC_CONNECTION_CLOSED)) {
OC_DBG("plgd-time: close fetch time session");
oc_close_session(data->endpoint);
}
Expand Down
2 changes: 1 addition & 1 deletion api/unittest/plgdtimetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ TEST_F(TestPlgdTimeWithServer, FetchTimeFail)

auto fetch_handler = [](oc_status_t code, oc_clock_time_t, void *data) {
OC_DBG("fetch time handler timeout");
EXPECT_TRUE(oc_ri_client_cb_terminated(code));
EXPECT_TRUE(code == OC_CONNECTION_CLOSED || code == OC_REQUEST_TIMEOUT);
*(static_cast<bool *>(data)) = true;
oc::TestDevice::Terminate();
};
Expand Down

0 comments on commit c35939c

Please sign in to comment.