Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jdavidb (1361)

jdavidb
  (email not shown publicly)
http://voiceofjohn.blogspot.com/

J. David Blackstone has a Bachelor of Science in Computer Science and Engineering and nine years of experience at a wireless telecommunications company, where he learned Perl and never looked back. J. David has an advantage in that he works really hard, he has a passion for writing good software, and he knows many of the world's best Perl programmers.

Journal of jdavidb (1361)

Tuesday May 07, 2002
01:04 PM

Timed reads again

[ #4725 ]

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.)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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
    • 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/servic

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers