Skip to content

Commit

Permalink
tcp: check SO_ERROR only for active connections (#667)
Browse files Browse the repository at this point in the history
only needed for connect(2):
  * use getsockopt to read the SO_ERROR option at
  * level SOL_SOCKET to determine whether connect() completed
  * successfully (if SO_ERROR is zero).
  • Loading branch information
sreimers authored Jan 29, 2023
1 parent 58b6efc commit b025063
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/tcp/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,32 +275,35 @@ static void tcp_recv_handler(int flags, void *arg)
bool hlp_estab = false;
struct le *le;
ssize_t n;
int err;
int err = 0;
socklen_t err_len = sizeof(err);

if (flags & FD_EXCEPT) {
DEBUG_INFO("recv handler: got FD_EXCEPT on fd=%d\n", tc->fdc);
}

/* check for any errors */
if (-1 == getsockopt(tc->fdc, SOL_SOCKET, SO_ERROR,
BUF_CAST &err, &err_len)) {
DEBUG_WARNING("recv handler: getsockopt: (%m)\n",
RE_ERRNO_SOCK);
return;
/* check for connection errors */
if (tc->active && !tc->connected) {
if (-1 == getsockopt(tc->fdc, SOL_SOCKET, SO_ERROR,
BUF_CAST &err, &err_len)) {
DEBUG_WARNING("recv handler: getsockopt: (%m)\n",
RE_ERRNO_SOCK);
return;
}
}

if (err) {
conn_close(tc, err);
return;
}
#if 0
if (EINPROGRESS != err && EALREADY != err) {
DEBUG_WARNING("recv handler: Socket error (%m)\n", err);
return;
}
#endif

if (err) {
conn_close(tc, err);
return;
}

if (flags & FD_WRITE) {

if (tc->connected) {
Expand Down

0 comments on commit b025063

Please sign in to comment.