#157 Implement inWaiting in protocol_socket

v2.7
closed-accepted
None
5
2014-08-26
2014-01-23
xOneca
No

Sort of basic implementation with select.select.

--- a/serial/urlhandler/protocol_socket.py  2014-01-23 13:31:09.000000000 +0100
+++ b/serial/urlhandler/protocol_socket.py  2014-01-23 14:03:13.000000000 +0100
@@ -20,6 +20,7 @@
from serial.serialutil import *
import time
import socket
+from select import select
import logging

# map log level names to constants. used in fromURL()
@@ -126,10 +127,10 @@
    def inWaiting(self):
        """Return the number of characters currently in the input buffer."""
        if not self._isOpen: raise portNotOpenError
-        if self.logger:
-            # set this one to debug as the function could be called often...
-            self.logger.debug('WARNING: inWaiting returns dummy value')
-        return 0 # hmmm, see comment in read()
+        # Poll the socket to see if it is ready for reading.
+        # If ready, at least one byte will be to read.
+        lr, lw, lx = select([self._socket], [], [], 0)
+        return len(lr)

    def read(self, size=1):
        """Read size bytes from the serial port. If a timeout is set it may

Discussion

  • Chris Liechti

    Chris Liechti - 2014-08-04
    • status: open --> closed-accepted
    • assigned_to: Chris Liechti
    • Group: v1.0 (example) --> v2.7
     
  • Chris Liechti

    Chris Liechti - 2014-08-04

    Thanks, committed.

     

Log in to post a comment.