[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Adding an API hook to enable a select extension
From: |
Andrew J. Schorr |
Subject: |
Re: [bug-gawk] Adding an API hook to enable a select extension |
Date: |
Thu, 30 May 2013 21:12:14 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
On Thu, May 30, 2013 at 09:53:32AM -0400, Andrew J. Schorr wrote:
> It would be really nice to add a "select" extension to gawk to solve
> this type of problem and enable I/O multiplexing. I don't think the
> existing extension API provides enough features for this to be implemented.
>
> I think we need an API hook to call the getredirect function. Arnold, do you
> have any thoughts on this?
At the risk of making Brian Kernighan throw up, since he believes no awk
program should be longer than 2 lines, I propose the attached patch to the API.
I could be mistaken, but I think this should be enough to implement a select
extension. If the name argument is NULL, it would return &curfile.public.
Otherwise, it would return &getredirect(name, strlen(name))->iop->public. We
might want to replace the red_head array with a hash table to optimize the
performance of getredirect.
User code might look something like this:
@load "select"
BEGIN {
server1 = "/inet4/tcp/0/127.0.0.1/12345"
server2 = "/inet4/tcp/0/127.0.0.1/23451"
delete writefds
delete exceptfds
timeout = 1.0 # in seconds
while (1) {
readfds[server1] = ""
readfds[server2] = ""
switch (select(readfds, writefds, exceptfds, timeout)) {
case -1:
printf "Error: select failed: %s\n", ERRNO > "/dev/stderr"
exit 1
case 0:
print "Timeout. Trying again."
break
default:
for (i in readfds) {
if ((i |& getline) > 0)
print "Received from %s:", i, $0
else {
printf "I/O error from %s: %s\n", i, ERRNO > "/dev/stderr"
exit 1
}
}
break
}
}
}
Thoughts?
Regards,
Andy
gawkapi.patch
Description: Text document
- [bug-gawk] Issue with read timeout on TCP socket, Serge A. Zaitsev, 2013/05/29
- Re: [bug-gawk] Issue with read timeout on TCP socket, Davide Brini, 2013/05/30
- Re: [bug-gawk] Issue with read timeout on TCP socket, Andrew J. Schorr, 2013/05/30
- Re: [bug-gawk] Adding an API hook to enable a select extension,
Andrew J. Schorr <=
- Re: [bug-gawk] Adding an API hook to enable a select extension, Eli Zaretskii, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Andrew J. Schorr, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Aharon Robbins, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Eli Zaretskii, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Andrew J. Schorr, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Eli Zaretskii, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Andrew J. Schorr, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Eli Zaretskii, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Andrew J. Schorr, 2013/05/31
- Re: [bug-gawk] Adding an API hook to enable a select extension, Eli Zaretskii, 2013/05/31