From e01ddaf1e8008d67b269dbd4707a065a16c5a282 Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 30 Dec 2019 16:14:10 +0000 Subject: [PATCH] Avoid retrying iod_read if we already got ENOTSOCK. --- nsock/src/nsock_core.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/nsock/src/nsock_core.c b/nsock/src/nsock_core.c index caa670160..3830effa0 100644 --- a/nsock/src/nsock_core.c +++ b/nsock/src/nsock_core.c @@ -603,6 +603,7 @@ static int do_actual_read(struct npool *ms, struct nevent *nse) { int err = 0; int max_chunk = NSOCK_READ_CHUNK_SIZE; int startlen = fs_length(&nse->iobuf); + int enotsock = 0; /* Did we get ENOTSOCK once? */ if (nse->readinfo.read_type == NSOCK_READBYTES) max_chunk = nse->readinfo.num; @@ -613,16 +614,24 @@ static int do_actual_read(struct npool *ms, struct nevent *nse) { socklen_t peerlen; peerlen = sizeof(peer); - buflen = ms->engine->io_operations->iod_read(ms, iod->sd, buf, sizeof(buf), 0, (struct sockaddr *)&peer, &peerlen); + if (enotsock) { + peer.ss_family = AF_UNSPEC; + peerlen = 0; + buflen = read(iod->sd, buf, sizeof(buf)); + } + else { + buflen = ms->engine->io_operations->iod_read(ms, iod->sd, buf, sizeof(buf), 0, (struct sockaddr *)&peer, &peerlen); - /* Using recv() was failing, at least on UNIX, for non-network sockets - * (i.e. stdin) in this case, a read() is done - as on ENOTSOCK we may - * have a non-network socket */ - if (buflen == -1) { - if (socket_errno() == ENOTSOCK) { - peer.ss_family = AF_UNSPEC; - peerlen = 0; - buflen = read(iod->sd, buf, sizeof(buf)); + /* Using recv() was failing, at least on UNIX, for non-network sockets + * (i.e. stdin) in this case, a read() is done - as on ENOTSOCK we may + * have a non-network socket */ + if (buflen == -1) { + if (socket_errno() == ENOTSOCK) { + enotsock = 1; + peer.ss_family = AF_UNSPEC; + peerlen = 0; + buflen = read(iod->sd, buf, sizeof(buf)); + } } } if (buflen == -1) {