3 # Copyright 2011 Facebook
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License. You may obtain
7 # a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
17 """Posix implementations of platform-specific functionality."""
19 from __future__ import absolute_import, division, print_function, with_statement
24 from . import interface
27 def set_close_exec(fd):
28 flags = fcntl.fcntl(fd, fcntl.F_GETFD)
29 fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
32 def _set_nonblocking(fd):
33 flags = fcntl.fcntl(fd, fcntl.F_GETFL)
34 fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK)
37 class Waker(interface.Waker):
44 self.reader = os.fdopen(r, "rb", 0)
45 self.writer = os.fdopen(w, "wb", 0)
48 return self.reader.fileno()
50 def write_fileno(self):
51 return self.writer.fileno()
55 self.writer.write(b"x")
62 result = self.reader.read()