Groups | Search | Server Info | Login | Register
| From | Janis Papanagnou <janis_papanagnou@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: getline timeout (revisited) |
| Date | 2011-04-19 17:38 +0200 |
| Organization | (posted via) M-net Telekommunikations GmbH |
| Message-ID | <ioka93$13e$1@news.m-online.net> (permalink) |
| References | <inmun6$lq1$1@speranza.aioe.org> <CsqdnTvy49IoCjDQnZ2dnUVZ_t2dnZ2d@mchsi.com> |
On 19.04.2011 16:09, j.eh@mchsi.com wrote:
> In article <inmun6$lq1$1@speranza.aioe.org>, Janis Papanagnou wrote:
>> I've been currently looking for a timeout option for getline in
>> the context of an /inet/tcp/... socket communication with gawk.
>>
>> This topic had already been addressed here in c.l.a many many
>> years ago, as my google search showed, but I haven't found any
>> positive answers. Has there been something incorporated in gawk
>> or xgawk, meanwhile, or is the status unchanged. I suppose the
>> latter, but asking for a confirmation anyway.
>
> [ Janis, I hit the wrong button. My intention was to post to
> the group, not to send a personal email. Sorry about that. ]
Don't worry; in my mailbox only spam isn't welcome. :-)
>
>
> I find the discussions in the old threads interesting, but I have
> a question. Let's assume we use PROCINFO to specify timeout like
> this:
>
> PROCINFO["/inet/tcp/..", "TIMEOUT"] = 1000 (ms)
>
> and a value of 0 means the default behavior i.e. no timeout.
Yes.
>
> Also, assume the existence of a builtin either in the gawk source
> or in a extension:
>
> readline("/inet/tcp/..")
Hmm.. - why a new function or builtin 'readline()' and not extending
the functionality of 'getline'? (Shouldn't conflict given the PROCINFO
approach.)
>
> which other than being a function call behaves exactly like getline
> w.r.t. RS, RT and setting fields. We modify 'readline' to handle
> timeout anyway you think is suitable to serve our purpose. The question
> is then, if a script using 'readline' going to look any different
> than from the one that uses getline with exactly the same
> modifications.
I don't understand what you're saying above, and what you're aiming at.
> If possible, please consider providing the outline
> of such a script illustrating the usage of 'readline' or getline
> with timeout.
In my specific primitive application - which is by no means meant to be
a general example, covering all needs, or considering any corner cases -
it was just something like (simplified code)...
BEGIN { P = "/inet/tcp/0/a.b.c.d/e" }
{ print some_funct($0) |& P }
/pat/ { P |& getline ; do_sth_w($0) }
END { close(P) }
which might, with timeouts, morph to something like...
BEGIN { P = "/inet/tcp/0/a.b.c.d/e"
PROCINFO[ P, "TIMEOUT"] = 1000
}
{ print some_funct($0) |& P }
/pat/ { if( (P |& getline) > 0) do_sth_w($0)
else print "Error:", PROCINFO[ P, "ERROR"]
}
END { close(P) }
Using PROCINFO as a means to return the error is just an ad hoc thought
based on your timeout setting example. (So feel free to ignore it and
introduce something else.)
> To keep things uniform, assume we parse ERRNO to
> find out the cause of error. Not very gifted when it comes to writing
> awk scripts that doesn't look like C, so I hope you understand my
> request in this context.
If I've misunderstood your request, please clarify.
Thanks.
Janis
>
> Thanks,
>
> John
>
>>
>> Thanks.
>>
>> Janis
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
getline timeout (revisited) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-08 14:23 +0200
Re: getline timeout (revisited) arnold@skeeve.com (Aharon Robbins) - 2011-04-10 18:49 +0000
Re: getline timeout (revisited) j.eh@mchsi.com - 2011-04-19 09:09 -0500
Re: getline timeout (revisited) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-19 17:38 +0200
Re: getline timeout (revisited) j.eh@mchsi.com - 2011-04-20 06:51 -0500
Re: getline timeout (revisited) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-04-20 14:20 +0200
Re: getline timeout (revisited) j.eh@mchsi.com - 2011-04-20 08:21 -0500
Re: getline timeout (revisited) j.eh@mchsi.com - 2011-04-21 05:46 -0500
Re: getline timeout (revisited) arnold@skeeve.com (Aharon Robbins) - 2011-04-22 13:55 +0000
Re: getline timeout (revisited) Grant <omg@grrr.id.au> - 2011-04-23 06:50 +1000
csiph-web