in reply to Writing a serial-to-Ethernet adapter with Win32::SerialPort

I'd spawn a thread to handle the serialport, and use a Thread::Queue to communicate between that thread and the main thread handling the socket.

You should then be able to use blocking IO on the serial port to provide timely servicing of that without the need to poll.

Using a combination of select on the socket, and $Q->pending() will allow the main thread to manage both the socket and input from the serialport (via the queue) on demand.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
  • Comment on Re: Writing a serial-to-Ethernet adapter with Win32::SerialPort

Replies are listed 'Best First'.
Re: Re: Writing a serial-to-Ethernet adapter with Win32::SerialPort
by sgifford (Prior) on May 14, 2004 at 19:33 UTC
    Thanks BrowserUK! I followed part of your advice and created a seperate thread to handle the serial IO, but instead of using a Thread::Queue I simply created a socket with socketpair, and used it to communicate back to the main thread. That way I could use IO::Select to handle everything.

    Here's the code I ended up with.

      Nice++


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail