Skip to content

Commit 12c4130

Browse files
User can initiate a connection close. (#22)
1 parent c6add17 commit 12c4130

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

include/aws/http/connection.h

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ AWS_EXTERN_C_BEGIN
127127
AWS_HTTP_API
128128
int aws_http_client_connect(const struct aws_http_client_connection_options *options);
129129

130+
/**
131+
* Begin shutdown sequence of the connection if it hasn't already started. It's safe to call this
132+
* function regardless of the connection state as long as you hold a reference to the connection.
133+
*/
134+
AWS_HTTP_API
135+
int aws_http_client_connection_close(struct aws_http_connection *connection);
136+
130137
/**
131138
* Users must release the connection when they are done with it.
132139
* The connection's memory cannot be reclaimed until this is done.

source/connection.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ static struct aws_http_connection *s_connection_new(
166166
return NULL;
167167
}
168168

169-
/* TODO: probably should have a aws_http_connection_close(int error_code) function */
169+
int aws_http_client_connection_close(struct aws_http_connection *connection) {
170+
if (connection->channel_slot->channel) {
171+
return aws_channel_shutdown(connection->channel_slot->channel, AWS_ERROR_SUCCESS);
172+
}
173+
174+
return AWS_OP_SUCCESS;
175+
}
170176

171177
void aws_http_connection_release(struct aws_http_connection *connection) {
172178
assert(connection);

0 commit comments

Comments
 (0)