def METHOD_NAME(self, direction):
    if self.closed[direction]:
        return
    self.closed[direction] = True
    if direction == "send":
        try:
            self.sock.shutdown(socket.SHUT_WR)
        except IOError as e:
            if e.errno == errno.ENOTCONN:
                pass
            else:
                raise
    if direction == "recv":
        try:
            self.sock.shutdown(socket.SHUT_RD)
        except IOError as e:
            if e.errno == errno.ENOTCONN:
                pass
            else:
                raise
    if False not in self.closed.values():
        self.close()