don't use select.POLL* constants
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Sun, 18 Nov 2012 18:50:52 +0000 (03:50 +0900)
committerBen Pfaff <blp@nicira.com>
Mon, 19 Nov 2012 17:11:12 +0000 (09:11 -0800)
Python doesn't have select.POLL* constants on some architectures
(e.g. MacOSX). This code needs to define the constants for itself. It
uses select.POLL* constants only internally (doesn't pass them
outside). So there is no harm even if the definition would conflict
with Python's those.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
AUTHORS
python/ovs/poller.py
python/ovs/socket_util.py
python/ovs/stream.py

diff --git a/AUTHORS b/AUTHORS
index 46878657eb3edd1a295ec8df38bc547d3bbbc15a..18a0be668338a4a15f607d0664097dea49ef2387 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -26,6 +26,7 @@ Dominic Curran          dominic.curran@citrix.com
 Ed Maste                emaste at freebsd.org
 Edward Tomasz NapieraƂa trasz@freebsd.org
 Ethan Jackson           ethan@nicira.com
+FUJITA Tomonori         fujita.tomonori@lab.ntt.co.jp
 Gaetano Catalli         gaetano.catalli@gmail.com
 Giuseppe Lettieri       g.lettieri@iet.unipi.it
 Glen Gibb               grg@stanford.edu
index c04c9b36f2738c5d22af8674aa587be4c3b16873..7d15f3edb6a8b9cb3cde7b531898fdfc3925f627 100644 (file)
@@ -20,6 +20,11 @@ import socket
 
 vlog = ovs.vlog.Vlog("poller")
 
+POLLIN = 0x001
+POLLOUT = 0x004
+POLLERR = 0x008
+POLLHUP = 0x010
+POLLNVAL = 0x020
 
 # eventlet/gevent doesn't support select.poll. If select.poll is used,
 # python interpreter is blocked as a whole instead of switching from the
@@ -39,12 +44,12 @@ class _SelectSelect(object):
         if isinstance(fd, socket.socket):
             fd = fd.fileno()
         assert isinstance(fd, int)
-        if events & select.POLLIN:
+        if events & POLLIN:
             self.rlist.append(fd)
-            events &= ~select.POLLIN
-        if events & select.POLLOUT:
+            events &= ~POLLIN
+        if events & POLLOUT:
             self.wlist.append(fd)
-            events &= ~select.POLLOUT
+            events &= ~POLLOUT
         if events:
             self.xlist.append(fd)
 
@@ -63,13 +68,13 @@ class _SelectSelect(object):
         # events_dict[fd] |= event
         events_dict = {}
         for fd in rlist:
-            events_dict[fd] = events_dict.get(fd, 0) | select.POLLIN
+            events_dict[fd] = events_dict.get(fd, 0) | POLLIN
         for fd in wlist:
-            events_dict[fd] = events_dict.get(fd, 0) | select.POLLOUT
+            events_dict[fd] = events_dict.get(fd, 0) | POLLOUT
         for fd in xlist:
-            events_dict[fd] = events_dict.get(fd, 0) | (select.POLLERR |
-                                                        select.POLLHUP |
-                                                        select.POLLNVAL)
+            events_dict[fd] = events_dict.get(fd, 0) | (POLLERR |
+                                                        POLLHUP |
+                                                        POLLNVAL)
         return events_dict.items()
 
 
@@ -168,15 +173,15 @@ class Poller(object):
             for fd, revents in events:
                 if revents != 0:
                     s = ""
-                    if revents & select.POLLIN:
+                    if revents & POLLIN:
                         s += "[POLLIN]"
-                    if revents & select.POLLOUT:
+                    if revents & POLLOUT:
                         s += "[POLLOUT]"
-                    if revents & select.POLLERR:
+                    if revents & POLLERR:
                         s += "[POLLERR]"
-                    if revents & select.POLLHUP:
+                    if revents & POLLHUP:
                         s += "[POLLHUP]"
-                    if revents & select.POLLNVAL:
+                    if revents & POLLNVAL:
                         s += "[POLLNVAL]"
                     vlog.dbg("%s on fd %d" % (s, fd))
 
index dd45fe4b92520561442d990ffdbe55f3ec2d5623..1fc80fd3a1add02446f26e3d5153e3b45fd855e4 100644 (file)
@@ -77,7 +77,7 @@ def make_unix_socket(style, nonblock, bind_path, connect_path):
 
 def check_connection_completion(sock):
     p = ovs.poller.SelectPoll()
-    p.register(sock, select.POLLOUT)
+    p.register(sock, ovs.poller.POLLOUT)
     if len(p.poll(0)) == 1:
         return get_socket_error(sock)
     else:
index dad68483e7a8ea72735397a470be85e972f22a6b..c4d243d0d61f2598bb2145a39a57c8423274ef34 100644 (file)
@@ -14,7 +14,6 @@
 
 import errno
 import os
-import select
 import socket
 
 import ovs.poller
@@ -236,9 +235,9 @@ class Stream(object):
         if self.state == Stream.__S_CONNECTING:
             wait = Stream.W_CONNECT
         if wait == Stream.W_RECV:
-            poller.fd_wait(self.socket, select.POLLIN)
+            poller.fd_wait(self.socket, ovs.poller.POLLIN)
         else:
-            poller.fd_wait(self.socket, select.POLLOUT)
+            poller.fd_wait(self.socket, ovs.poller.POLLOUT)
 
     def connect_wait(self, poller):
         self.wait(poller, Stream.W_CONNECT)
@@ -324,7 +323,7 @@ class PassiveStream(object):
                 return error, None
 
     def wait(self, poller):
-        poller.fd_wait(self.socket, select.POLLIN)
+        poller.fd_wait(self.socket, ovs.poller.POLLIN)
 
     def __del__(self):
         # Don't delete the file: we might have forked.