[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
network time service, non-blocking?
From: |
Petr Slansky |
Subject: |
network time service, non-blocking? |
Date: |
Wed, 11 May 2022 10:39:14 +0200 |
Hello Gawk,
this is not real bug report, it is something like a feedback. I use gawk
4.1.4.
I tried to use gawk for some network service, to report progress of data
processed from pipeline to websocket but I think I cannot do that because
gawk doesn't support non-blocking sockets. To illustrate that, I use
example with simple time service, similar to
https://www.gnu.org/software/gawk/manual/gawkinet/html_node/Setting-Up.html#Setting-Up
$ cat timesrv.awk
# Time server
BEGIN {
service = "/inet/tcp/8888/0/0";
while (1) {
time = strftime();
print time;
print time |& service;
close(service);
}
}
# run it
$ gawk -f timeserv.awk
# other terminal
$ sleep 45; date; curl http://localhost:8888
The problem of this server is that it reports "old" time. It samples time
to a variable and it waits for an incoming connection from a client, then
it reports time and samples new time. When clients don't connect
frequently, they get wrong (old) time.
Is there a way, to check if client connected to listening socket? Open
server socket, do some other tasks and from time to time check if client is
connected; when client is connected, serve fresh data otherwise continue to
process data. It is possible that I cannot use gawk for my task and I have
to use Python, Go or other tool.
Petr
- network time service, non-blocking?,
Petr Slansky <=