From 58059755f7010fd12507068f815632db05ad0935 Mon Sep 17 00:00:00 2001 From: cliechti Date: Mon, 4 Aug 2014 10:29:24 +0000 Subject: [Bug pyserial:157] Implement inWaiting in protocol_socket git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@506 f19166aa-fa4f-0410-85c2-fa1106f25c8a --- CHANGES.txt | 1 + serial/urlhandler/protocol_socket.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 96de156..663dbeb 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -489,6 +489,7 @@ Version 2.8 2014-xx-xx Bugfixes: +- [Bug pyserial:157] Implement inWaiting in protocol_socket - [Bug pyserial:166] RFC2217 connections always fail Bugfixes (posix): diff --git a/serial/urlhandler/protocol_socket.py b/serial/urlhandler/protocol_socket.py index 41e59b1..dc59923 100644 --- a/serial/urlhandler/protocol_socket.py +++ b/serial/urlhandler/protocol_socket.py @@ -20,6 +20,7 @@ from serial.serialutil import * import time import socket +import select import logging # map log level names to constants. used in fromURL() @@ -130,10 +131,10 @@ class SocketSerial(SerialBase): 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.select([self._socket], [], [], 0) + return len(lr) def read(self, size=1): """\ -- cgit v1.2.1