[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk's inet hanging?
From: |
Jeff Chua |
Subject: |
Re: gawk's inet hanging? |
Date: |
Wed, 10 Feb 2010 10:34:43 +0800 |
On Fri, Nov 6, 2009 at 6:17 PM, Aharon Robbins <address@hidden> wrote:
> Hi. I'll review the patch. I note that gawk is checking an environment
> variable and not an awk variable, thus your initial script was not
> correct.
Aharon,
Have you had a chance to look into the patch I sent earlier (see below)?
Without it, gawk would hang forever instead of returning an error.
Thanks,
Jeff
On Fri, Nov 6, 2009 at 11:27 AM, Jeff Chua <address@hidden>wrote:
>
>
> Arnold,
>
>
> I'm trying put gawk inet connection to the local smtp port and would like
>> it to detect error conditions, but don't know how.
>>
>
>
> I looked into the source code and it seems the code is testing "unsigned
> long" for negative value ... and that won't work.
>
> I've also modify the code to return ERRNO to user instead of exiting with a
> fatal error in case the socket is no available, and also modified sleep() to
> usleep() and allow GAWK_MSEC_SLEEP to retry in milliseconds interval instead
> of the default 1 second.
>
> Tested with this script.
>
>
> export GAWK_SOCK_RETRIES=3;
> export GAWK_MSEC_SLEEP=200;
> gawk 'BEGIN {
>
> serv = "/inet/tcp/0/localhost/25";
> status = (serv |& getline);
> printf("(%s) (%s) [%s]\n", ERRNO, status, $0);
> }'
>
>
> Patch below. Please consider.
>
>
> Thanks,
> Jeff.
>
>
> --- gawk-stable/io.c 2009-10-30 21:46:43.000000000 +0800
> +++ a/io.c 2009-11-06 10:55:01.000000000 +0800
> @@ -708,10 +708,12 @@
> if (! two_way_open(str, rp)) {
> #ifdef HAVE_SOCKETS
> /* multiple messages make life easier for
> translators */
> - if (STREQN(str, "/inet/", 6))
> - fatal(_("can't open two way socket
> `%s' for input/output (%s)"),
> - str, strerror(errno));
> - else
> + if (STREQN(str, "/inet/", 6)) {
> + *errflg = errno;
> + free_temp(tmp);
> + free_rp(rp);
> + return NULL;
> + } else
> #endif
> fatal(_("can't open two way pipe
> `%s' for input/output (%s)"),
> str, strerror(errno));
> @@ -1457,27 +1459,41 @@
>
> {
> #define DEFAULT_RETRIES 20
> - static unsigned long def_retries = DEFAULT_RETRIES;
> + static long def_retries = DEFAULT_RETRIES;
> static int first_time = TRUE;
> - unsigned long retries = 0;
> + long retries = 0;
> + static long msleep = 1000;
>
> if (first_time) {
> char *cp, *end;
> - unsigned long count = 0;
> + long count = 0;
> + char *ms2;
>
> first_time = FALSE;
> - if ((cp = getenv("GAWK_SOCK_RETRIES")) !=
> NULL) {
> +
> + if((cp = getenv("GAWK_SOCK_RETRIES")) !=
> NULL) {
> count = strtoul(cp, &end, 10);
> if (end != cp && count > 0)
> def_retries = count;
> + //warning(_("retries %d %d"),
> def_retries, count);
> + }
> +
> + if((ms2 = getenv("GAWK_MSEC_SLEEP")) !=
> NULL) {
> + msleep = atoi(ms2);
> + if(msleep < 0)
> + msleep = 1000;
> + //warning(_("msleep %d"), msleep);
> }
> }
> retries = def_retries;
>
> + msleep *= 1000;
> +
> do {
> openfd = socketopen(protocol, localpname,
> cp, hostname);
> + //warning(_("retries %d"), retries);
> retries--;
> - } while (openfd == INVALID_HANDLE && retries >= 0
> && sleep(1) == 0);
> + } while (openfd == INVALID_HANDLE && retries >= 0
> && usleep(msleep) == 0);
> }
>
> *localpnamelastcharp = '/';
>
>
>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: gawk's inet hanging?,
Jeff Chua <=