'Tests:
>>> l = listen()
>>> r = remote(\'localhost\', l.lport)
>>> r.connected()
True
>>> l.close()
>>> time.sleep(1) # Avoid race condition
>>> r.connected()
False'

def connected_raw(self, direction):

    if (not self.sock):
        return False
    if self.closed.get(direction, False):
        return False
    if all(self.closed.values()):
        return False
    want = {'recv': select.POLLIN, 'send': select.POLLOUT, 'any': (select.POLLIN | select.POLLOUT)}[direction]
    poll = select.poll()
    poll.register(self, ((want | select.POLLHUP) | select.POLLERR))
    for (fd, event) in poll.poll(0):
        if (event & select.POLLHUP):
            self.close()
            return False
        if (event & select.POLLIN):
            return True
        if (event & select.POLLOUT):
            return True
    return True
