Revision: 1260
Author: g.rodola
Date: Fri Apr 11 21:12:11 2014 UTC
Log: fix issue 282: add /dev/poll support for solaris
http://code.google.com/p/pyftpdlib/source/detail?r=1260
Modified:
/trunk/HISTORY
/trunk/pyftpdlib/ioloop.py
=======================================
--- /trunk/HISTORY Fri Apr 11 18:39:23 2014 UTC
+++ /trunk/HISTORY Fri Apr 11 21:12:11 2014 UTC
@@ -14,6 +14,7 @@
* #277: added a make file for running tests and for other repetitive tasks
(also for Windows).
* #281: tarballs are now hosted on PYPI.
+ * #282: support for /dev/poll on Solaris.
* #285: test suite requires unittest2 module on python < 2.7.
BUG FIXES
=======================================
--- /trunk/pyftpdlib/ioloop.py Fri Apr 4 13:10:40 2014 UTC
+++ /trunk/pyftpdlib/ioloop.py Fri Apr 11 21:12:11 2014 UTC
@@ -461,8 +461,9 @@
# ===================================================================
class _BasePollEpoll(_IOLoop):
- """This is common to both poll/epoll implementations which
- almost share the same interface.
+ """This is common to both poll() (UNIX), epoll() (Linux) and
+ /dev/poll (Solaris) implementations which share almost the same
+ interface.
Not supposed to be used directly.
"""
@@ -538,6 +539,44 @@
_BasePollEpoll.poll(self, timeout)
+# ===================================================================
+# --- /dev/poll - Solaris (introduced in python 3.3)
+# ===================================================================
+
+if hasattr(select, 'devpoll'):
+
+ class DevPoll(_BasePollEpoll):
+ """/dev/poll based poller (introduced in python 3.3)."""
+
+ READ = select.POLLIN
+ WRITE = select.POLLOUT
+ _ERROR = select.POLLERR | select.POLLHUP | select.POLLNVAL
+ _poller = select.devpoll
+
+ # introduced in python 3.4
+ if hasattr(select.devpoll, 'fileno'):
+ def fileno(self):
+ """Return devpoll() fd."""
+ return self._poller.fileno()
+
+ def modify(self, fd, events):
+ inst = self.socket_map[fd]
+ self.unregister(fd)
+ self.register(fd, inst, events)
+
+ def poll(self, timeout):
+ # /dev/poll timeout is expressed in milliseconds
+ if timeout is not None:
+ timeout = int(timeout * 1000)
+ _BasePollEpoll.poll(self, timeout)
+
+ # introduced in python 3.4
+ if hasattr(select.devpoll, 'close'):
+ def close(self):
+ _IOLoop.close(self)
+ self._poller.close()
+
+
# ===================================================================
# --- epoll() - Linux
# ===================================================================
@@ -666,10 +705,12 @@
# --- choose the better poller for this platform
# ===================================================================
-if hasattr(select, 'epoll'): # epoll() - Linux only
+if hasattr(select, 'epoll'): # epoll() - Linux
IOLoop = Epoll
elif hasattr(select, 'kqueue'): # kqueue() - BSD / OSX
IOLoop = Kqueue
+elif hasattr(select, 'devpoll'): # /dev/poll - Solaris
+ IOLoop = DevPoll
elif hasattr(select, 'poll'): # poll() - POSIX
IOLoop = Poll
else: # select() - POSIX and Windows