MCPcopy Create free account
hub / github.com/EasyIME/PIME / _handle_socket

Method _handle_socket

python/python3/tornado/curl_httpclient.py:105–132  ·  view source on GitHub ↗

Called by libcurl when it wants to change the file descriptors it cares about.

(self, event: int, fd: int, multi: Any, data: bytes)

Source from the content-addressed store, hash-verified

103 self._set_timeout(0)
104
105 def _handle_socket(self, event: int, fd: int, multi: Any, data: bytes) -> None:
106 """Called by libcurl when it wants to change the file descriptors
107 it cares about.
108 """
109 event_map = {
110 pycurl.POLL_NONE: ioloop.IOLoop.NONE,
111 pycurl.POLL_IN: ioloop.IOLoop.READ,
112 pycurl.POLL_OUT: ioloop.IOLoop.WRITE,
113 pycurl.POLL_INOUT: ioloop.IOLoop.READ | ioloop.IOLoop.WRITE,
114 }
115 if event == pycurl.POLL_REMOVE:
116 if fd in self._fds:
117 self.io_loop.remove_handler(fd)
118 del self._fds[fd]
119 else:
120 ioloop_event = event_map[event]
121 # libcurl sometimes closes a socket and then opens a new
122 # one using the same FD without giving us a POLL_NONE in
123 # between. This is a problem with the epoll IOLoop,
124 # because the kernel can tell when a socket is closed and
125 # removes it from the epoll automatically, causing future
126 # update_handler calls to fail. Since we can't tell when
127 # this has happened, always use remove and re-add
128 # instead of update.
129 if fd in self._fds:
130 self.io_loop.remove_handler(fd)
131 self.io_loop.add_handler(fd, self._handle_events, ioloop_event)
132 self._fds[fd] = ioloop_event
133
134 def _set_timeout(self, msecs: int) -> None:
135 """Called by libcurl to schedule a timeout."""

Callers

nothing calls this directly

Calls 2

remove_handlerMethod · 0.45
add_handlerMethod · 0.45

Tested by

no test coverage detected