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

def _handle_socket(self, event, fd, multi, data):

    event_map = {pycurl.POLL_NONE: ioloop.IOLoop.NONE, pycurl.POLL_IN: ioloop.IOLoop.READ, pycurl.POLL_OUT: ioloop.IOLoop.WRITE, pycurl.POLL_INOUT: (ioloop.IOLoop.READ | ioloop.IOLoop.WRITE)}
    if (event == pycurl.POLL_REMOVE):
        if (fd in self._fds):
            self.io_loop.remove_handler(fd)
            del self._fds[fd]
    else:
        ioloop_event = event_map[event]
        if (fd in self._fds):
            self.io_loop.remove_handler(fd)
        self.io_loop.add_handler(fd, self._handle_events, ioloop_event)
        self._fds[fd] = ioloop_event
