Skip to content

Commit

Permalink
Merge pull request #142 from jhawthorn/connect_internal_timeout_rc
Browse files Browse the repository at this point in the history
Return rc from trilogy_sock_wait_write in connect
  • Loading branch information
jhawthorn authored Dec 28, 2023
2 parents e577853 + 77f5a0f commit 66d6e4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 0 additions & 3 deletions contrib/ruby/ext/trilogy-ruby/cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,6 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE encoding, VALUE charset, VALUE
}

int rc = try_connect(ctx, &handshake, &connopt);
if (rc == TRILOGY_TIMEOUT) {
rb_raise(Trilogy_TimeoutError, "trilogy_connect_recv");
}
if (rc != TRILOGY_OK) {
if (connopt.path) {
handle_trilogy_error(ctx, rc, "trilogy_connect - unable to connect to %s", connopt.path);
Expand Down
9 changes: 6 additions & 3 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static int raw_connect_internal(struct trilogy_sock *sock, const struct addrinfo
{
int sockerr;
socklen_t sockerr_len = sizeof(sockerr);
int rc = TRILOGY_SYSERR;

sock->fd = socket(ai->ai_family, SOCK_STREAM, ai->ai_protocol);
if (sock->fd < 0) {
Expand Down Expand Up @@ -244,8 +245,8 @@ static int raw_connect_internal(struct trilogy_sock *sock, const struct addrinfo
}
}

if (trilogy_sock_wait_write((trilogy_sock_t *)sock) < 0) {
goto fail;
if ((rc = trilogy_sock_wait_write((trilogy_sock_t *)sock)) < 0) {
goto failrc;
}

if (getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, &sockerr, &sockerr_len) < 0) {
Expand All @@ -263,9 +264,11 @@ static int raw_connect_internal(struct trilogy_sock *sock, const struct addrinfo
return TRILOGY_OK;

fail:
rc = TRILOGY_SYSERR;
failrc:
close(sock->fd);
sock->fd = -1;
return TRILOGY_SYSERR;
return rc;
}

static int _cb_raw_connect(trilogy_sock_t *_sock)
Expand Down

0 comments on commit 66d6e4e

Please sign in to comment.