Permalink
Browse files

Trying to better re-use code

  • Loading branch information...
1 parent 248c578 commit bec0552eff1160c601c3c96adaf03bc78d9845d8 unknown committed Mar 10, 2010
Showing with 9 additions and 9 deletions.
  1. +9 −9 tornado/ioloop.py
View
@@ -39,8 +39,10 @@ def __init__(self):
self.reader_fd = -1
if os.name == 'posix':
self.reader_fd, w = os.pipe()
- self._set_posix_nonblocking(self.reader_fd)
- self._set_posix_nonblocking(w)
+ IOLoop.set_nonblocking(self.reader_fd)
+ IOLoop.set_nonblocking(w)
+ IOLoop.set_close_exec(self.reader_fd)
+ IOLoop.set_close_exec(w)
self.reader = os.fdopen(self.reader_fd, "r", 0)
self.writer = os.fdopen(w, "w", 0)
else:
@@ -94,10 +96,6 @@ def __init__(self):
a.close()
self.reader_fd = self.reader.fileno()
- def _set_posix_nonblocking(self, fd):
- flags = fcntl.fcntl(fd, fcntl.F_GETFL)
- fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
-
def read(self):
try:
return self.reader.recv(1)
@@ -167,7 +165,7 @@ def connection_ready(sock, fd, events):
def __init__(self, impl=None):
self._impl = impl or _poll()
if hasattr(self._impl, 'fileno'):
- self._set_close_exec(self._impl.fileno())
+ self.set_close_exec(self._impl.fileno())
self._handlers = {}
self._events = {}
self._callbacks = set()
@@ -366,11 +364,13 @@ def _read_waker(self, fd, events):
except IOError:
pass
- def _set_nonblocking(self, fd):
+ @staticmethod
+ def set_nonblocking(fd):
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
- def _set_close_exec(self, fd):
+ @staticmethod
+ def set_close_exec(fd):
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)

0 comments on commit bec0552

Please sign in to comment.