aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-03-08 06:06:19 +0200
committerArnold D. Robbins <arnold@skeeve.com>2015-03-08 06:06:19 +0200
commitb108a3ba2ab12dd7274589c6fe09c882df02827c (patch)
treeacc493b1eb37c9e9a3144e388aa341b20fbb6a3d /io.c
parentb8ba9836e05eb96daeed9614f045f5b81a826730 (diff)
downloadegawk-b108a3ba2ab12dd7274589c6fe09c882df02827c.tar.gz
egawk-b108a3ba2ab12dd7274589c6fe09c882df02827c.tar.bz2
egawk-b108a3ba2ab12dd7274589c6fe09c882df02827c.zip
Make nonfatal override GAWK_SOCK_RETRIES. Document it.
Diffstat (limited to 'io.c')
-rw-r--r--io.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/io.c b/io.c
index 162fb4e8..55c5d3a5 100644
--- a/io.c
+++ b/io.c
@@ -1661,20 +1661,20 @@ devopen(const char *name, const char *mode)
goto strictopen;
} else if (inetfile(name, & isi)) {
#ifdef HAVE_SOCKETS
- cp = (char *) name;
-
- /* socketopen requires NUL-terminated strings */
- cp[isi.localport.offset+isi.localport.len] = '\0';
- cp[isi.remotehost.offset+isi.remotehost.len] = '\0';
- /* remoteport comes last, so already NUL-terminated */
-
- {
#define DEFAULT_RETRIES 20
static unsigned long def_retries = DEFAULT_RETRIES;
static bool first_time = true;
unsigned long retries = 0;
static long msleep = 1000;
bool hard_error = false;
+ bool non_fatal = is_non_fatal_redirect(name);
+
+ cp = (char *) name;
+
+ /* socketopen requires NUL-terminated strings */
+ cp[isi.localport.offset+isi.localport.len] = '\0';
+ cp[isi.remotehost.offset+isi.remotehost.len] = '\0';
+ /* remoteport comes last, so already NUL-terminated */
if (first_time) {
char *cp, *end;
@@ -1701,28 +1701,39 @@ devopen(const char *name, const char *mode)
msleep *= 1000;
}
}
- retries = def_retries;
+ /*
+ * PROCINFO["NONFATAL"] or PROCINFO[name, "NONFATAL"] overrrides
+ * GAWK_SOCK_RETRIES. The explicit code in the program carries
+ * a bigger stick than the environment variable does.
+ */
+ retries = non_fatal ? 1 : def_retries;
errno = 0;
do {
- openfd = socketopen(isi.family, isi.protocol, name+isi.localport.offset, name+isi.remoteport.offset, name+isi.remotehost.offset, & hard_error);
+ openfd = socketopen(isi.family, isi.protocol, name+isi.localport.offset,
+ name+isi.remoteport.offset, name+isi.remotehost.offset,
+ & hard_error);
retries--;
} while (openfd == INVALID_HANDLE && ! hard_error && retries > 0 && usleep(msleep) == 0);
save_errno = errno;
- }
- /* restore original name string */
- cp[isi.localport.offset+isi.localport.len] = '/';
- cp[isi.remotehost.offset+isi.remotehost.len] = '/';
+ /* restore original name string */
+ cp[isi.localport.offset+isi.localport.len] = '/';
+ cp[isi.remotehost.offset+isi.remotehost.len] = '/';
#else /* ! HAVE_SOCKETS */
- fatal(_("TCP/IP communications are not supported"));
+ fatal(_("TCP/IP communications are not supported"));
#endif /* HAVE_SOCKETS */
}
strictopen:
if (openfd == INVALID_HANDLE) {
openfd = open(name, flag, 0666);
- if (openfd == INVALID_HANDLE && save_errno)
+ /*
+ * ENOENT means there is no such name in the filesystem.
+ * Therefore it's ok to propagate up the error from
+ * getaddrinfo() that's in save_errno.
+ */
+ if (openfd == INVALID_HANDLE && errno == ENOENT && save_errno)
errno = save_errno;
}
#if defined(__EMX__) || defined(__MINGW32__)