def _bind_posix_socket(socket_name=None):
assert socket_name is None or isinstance(socket_name, six.text_type)<EOL>s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)<EOL>if socket_name:<EOL><INDENT>s.bind(socket_name)<EOL>return socket_name, s<EOL><DEDENT>else:<EOL><INDENT>i = <NUM_LIT:0><EOL>while True:<EOL><INDENT>try:<EOL><INDENT>socket_name = '<STR_LIT>' % (<EOL>tempfile.gettempdir(), getpass.getuser(), i)<EOL>s.bind(socket_name)<EOL>return socket_name, s<EOL><DEDENT>except (OSError, socket.error):<EOL><INDENT>i += <NUM_LIT:1><EOL>if i == <NUM_LIT:100>:<EOL><INDENT>logger.warning('<STR_LIT>'<EOL>'<STR_LIT>')<EOL>raise<EOL><DEDENT><DEDENT><DEDENT><DEDENT>
Find a socket to listen on and return it.

Returns (socket_name, sock_obj)