Skip to content

Commit

Permalink
User can initiate a connection close. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanHenson authored Mar 27, 2019
1 parent c6add17 commit 12c4130
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/aws/http/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ AWS_EXTERN_C_BEGIN
AWS_HTTP_API
int aws_http_client_connect(const struct aws_http_client_connection_options *options);

/**
* Begin shutdown sequence of the connection if it hasn't already started. It's safe to call this
* function regardless of the connection state as long as you hold a reference to the connection.
*/
AWS_HTTP_API
int aws_http_client_connection_close(struct aws_http_connection *connection);

/**
* Users must release the connection when they are done with it.
* The connection's memory cannot be reclaimed until this is done.
Expand Down
8 changes: 7 additions & 1 deletion source/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ static struct aws_http_connection *s_connection_new(
return NULL;
}

/* TODO: probably should have a aws_http_connection_close(int error_code) function */
int aws_http_client_connection_close(struct aws_http_connection *connection) {
if (connection->channel_slot->channel) {
return aws_channel_shutdown(connection->channel_slot->channel, AWS_ERROR_SUCCESS);
}

return AWS_OP_SUCCESS;
}

void aws_http_connection_release(struct aws_http_connection *connection) {
assert(connection);
Expand Down

0 comments on commit 12c4130

Please sign in to comment.