Timed reads again

jdavidb on 2002-05-07T18:04:00

Well, I may have found The Right Way to accomplish my timed reads. Term::ReadKey has a ReadKey() function (exported by default) that accepts a timeout and returns a first keystroke or undef if the timeout occurs. So I can write a timed_read() routine around it which goes ahead and reads until $/ with <>, prepends the first character, and moves on.

I've already got a routine with IO::Select, but it appears to not be working sometimes, and I don't know why. Sometimes it times out when the input should be there. I'll implement the ReadKey() version and see if it makes a difference.

Of course, when I discovered ReadKey() gave me what I needed, I looked to see how it was implemented. The answer was that the author checks far more things about the system than I knew existed and then eval's one of many ReadKey() definitions into existence. Wow! Talk about a motivator for calling a module instead of cut-and-paste.

I'm doing all this over sockets, through inetd, just to be difficult, you know. :) One of the first things I checked with Term::ReadKey was if it would work with a socket. (Or, at least, a socket that looks like a STDIN.) BTW, I absolutely love the Net::DummyInetd module, removed from the libnet distribution, but still available unless the author has done housekeeping. (Like Matt Sergeant, who recently removed the older, pure-Perl version of Time::Object from CPAN before last Friday when I really needed it all of a sudden. I forgive you, Matt! :) ) DummyInetd.pm can let you write your programs for inetd without having to set up inetd yourself. (I let the sysadmins do that; they always want to keep control, anyway.)


user run inetd

Dom2 on 2002-05-08T07:45:38

You don't need a sysadmin to set up inetd for you. Just write your own configuration file and do:

      % /usr/sbin/inetd ~/my-inetd.conf

So long as the port you are using isn't below 1024 there shouldn't be any problem.

BTW, if your sysadmin notices two copies of inetd running, she may start getting confused, so it's probably an idea to let her know what you're doing even though it's perfectly reasonable.

-Dom

Re:user run inetd

jdavidb on 2002-05-08T14:00:33

BTW, if your sysadmin notices two copies of inetd running, she may start getting confused, so it's probably an idea to let her know what you're doing even though it's perfectly reasonable.

Yep. That's another advantage of the wrapper script. :)

I think I did the personally run inetd a couple of years back, but the wrapper I've written with the DummyInetd module makes it easier because I don't have to do any setup. It's just ./inetd path/to/program. Also, don't you still have to configure /etc/services with inetd even if you're not root? It's been awhile, so I don't remember.