tcp: check SO_ERROR only for active connections
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).
@@ -275,25 +275,23 @@ 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 */
+ /* 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);
@@ -301,6 +299,11 @@ static void tcp_recv_handler(int flags, void *arg)
}
#endif
+ if (err) {
+ conn_close(tc, err);
+ return;
+ }
+
if (flags & FD_WRITE) {
if (tc->connected) {
