07da6babdbdcc929037401252ce2c613b77d5dd5
[trex.git] /
1 #!/usr/bin/env python
2 #
3 # Copyright 2011 Facebook
4 #
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
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
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
15 # under the License.
16
17 """Interfaces for platform-specific functionality.
18
19 This module exists primarily for documentation purposes and as base classes
20 for other tornado.platform modules.  Most code should import the appropriate
21 implementation from `tornado.platform.auto`.
22 """
23
24 from __future__ import absolute_import, division, print_function, with_statement
25
26
27 def set_close_exec(fd):
28     """Sets the close-on-exec bit (``FD_CLOEXEC``)for a file descriptor."""
29     raise NotImplementedError()
30
31
32 class Waker(object):
33     """A socket-like object that can wake another thread from ``select()``.
34
35     The `~tornado.ioloop.IOLoop` will add the Waker's `fileno()` to
36     its ``select`` (or ``epoll`` or ``kqueue``) calls.  When another
37     thread wants to wake up the loop, it calls `wake`.  Once it has woken
38     up, it will call `consume` to do any necessary per-wake cleanup.  When
39     the ``IOLoop`` is closed, it closes its waker too.
40     """
41     def fileno(self):
42         """Returns the read file descriptor for this waker.
43
44         Must be suitable for use with ``select()`` or equivalent on the
45         local platform.
46         """
47         raise NotImplementedError()
48
49     def write_fileno(self):
50         """Returns the write file descriptor for this waker."""
51         raise NotImplementedError()
52
53     def wake(self):
54         """Triggers activity on the waker's file descriptor."""
55         raise NotImplementedError()
56
57     def consume(self):
58         """Called after the listen has woken up to do any necessary cleanup."""
59         raise NotImplementedError()
60
61     def close(self):
62         """Closes the waker's file descriptor(s)."""
63         raise NotImplementedError()