Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reset link credit with drain feature #367

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/azure_uamqp_c/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ MOCKABLE_FUNCTION(, int, link_attach, LINK_HANDLE, link, ON_TRANSFER_RECEIVED, o
MOCKABLE_FUNCTION(, int, link_detach, LINK_HANDLE, link, bool, close, const char*, error_condition, const char*, error_description, AMQP_VALUE, info);
MOCKABLE_FUNCTION(, ASYNC_OPERATION_HANDLE, link_transfer_async, LINK_HANDLE, handle, message_format, message_format, PAYLOAD*, payloads, size_t, payload_count, ON_DELIVERY_SETTLED, on_delivery_settled, void*, callback_context, LINK_TRANSFER_RESULT*, link_transfer_result,tickcounter_ms_t, timeout);
MOCKABLE_FUNCTION(, void, link_dowork, LINK_HANDLE, link);
MOCKABLE_FUNCTION(, int, link_reset_link_credit, LINK_HANDLE, link, uint32_t, link_credit, bool, drain);

MOCKABLE_FUNCTION(, ON_LINK_DETACH_EVENT_SUBSCRIPTION_HANDLE, link_subscribe_on_link_detach_received, LINK_HANDLE, link, ON_LINK_DETACH_RECEIVED, on_link_detach_received, void*, context);
MOCKABLE_FUNCTION(, void, link_unsubscribe_on_link_detach_received, ON_LINK_DETACH_EVENT_SUBSCRIPTION_HANDLE, event_subscription);
Expand Down
68 changes: 68 additions & 0 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,74 @@ int link_set_max_link_credit(LINK_HANDLE link, uint32_t max_link_credit)
return result;
}

int link_reset_link_credit(LINK_HANDLE link, uint32_t link_credit, bool drain)
{
int result;
FLOW_HANDLE flow;
LINK_INSTANCE* link_instance = (LINK_INSTANCE*)link;

if (link == NULL)
{
result = MU_FAILURE;
}
else
{
if(link_instance->role == role_sender)
{
LogError("Sender is not allowed to reset link credit");
result = MU_FAILURE;
}
else
{
link->current_link_credit = link_credit;

flow = flow_create(0, 0, 0);
if (flow == NULL)
{
LogError("NULL flow performative");
result = MU_FAILURE;
}
else
{
if (flow_set_link_credit(flow, link->current_link_credit) != 0)
{
LogError("Cannot set link credit on flow performative");
result = MU_FAILURE;
}
else if (flow_set_handle(flow, link->handle) != 0)
{
LogError("Cannot set handle on flow performative");
result = MU_FAILURE;
}
else if (flow_set_delivery_count(flow, link->delivery_count) != 0)
{
LogError("Cannot set delivery count on flow performative");
result = MU_FAILURE;
}
else if (drain && flow_set_drain(flow, drain) != 0)
{
LogError("Cannot set drain on flow performative");
result = MU_FAILURE;
}
else
{
if (session_send_flow(link->link_endpoint, flow) != 0)
{
LogError("Sending flow frame failed in session send");
result = MU_FAILURE;
}
else
{
result = 0;
}
}
flow_destroy(flow);
}
}
}
return result;
}

int link_attach(LINK_HANDLE link, ON_TRANSFER_RECEIVED on_transfer_received, ON_LINK_STATE_CHANGED on_link_state_changed, ON_LINK_FLOW_ON on_link_flow_on, void* callback_context)
{
int result;
Expand Down