MCPcopy Index your code
hub / github.com/python/cpython / create_unix_server

Method create_unix_server

Lib/asyncio/unix_events.py:272–352  ·  view source on GitHub ↗
(
            self, protocol_factory, path=None, *,
            sock=None, backlog=100, ssl=None,
            ssl_handshake_timeout=None,
            ssl_shutdown_timeout=None,
            start_serving=True, cleanup_socket=True)

Source from the content-addressed store, hash-verified

270 return transport, protocol
271
272 async def create_unix_server(
273 self, protocol_factory, path=None, *,
274 sock=None, backlog=100, ssl=None,
275 ssl_handshake_timeout=None,
276 ssl_shutdown_timeout=None,
277 start_serving=True, cleanup_socket=True):
278 if isinstance(ssl, bool):
279 raise TypeError('ssl argument must be an SSLContext or None')
280
281 if ssl_handshake_timeout is not None and not ssl:
282 raise ValueError(
283 'ssl_handshake_timeout is only meaningful with ssl')
284
285 if ssl_shutdown_timeout is not None and not ssl:
286 raise ValueError(
287 'ssl_shutdown_timeout is only meaningful with ssl')
288
289 if path is not None:
290 if sock is not None:
291 raise ValueError(
292 'path and sock can not be specified at the same time')
293
294 path = os.fspath(path)
295 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
296
297 # Check for abstract socket. `str` and `bytes` paths are supported.
298 if path[0] not in (0, '\x00'):
299 try:
300 if stat.S_ISSOCK(os.stat(path).st_mode):
301 os.remove(path)
302 except FileNotFoundError:
303 pass
304 except OSError as err:
305 # Directory may have permissions only to create socket.
306 logger.error('Unable to check or remove stale UNIX socket '
307 '%r: %r', path, err)
308
309 try:
310 sock.bind(path)
311 except OSError as exc:
312 sock.close()
313 if exc.errno == errno.EADDRINUSE:
314 # Let's improve the error message by adding
315 # with what exact address it occurs.
316 msg = f'Address {path!r} is already in use'
317 raise OSError(errno.EADDRINUSE, msg) from None
318 else:
319 raise
320 except:
321 sock.close()
322 raise
323 else:
324 if sock is None:
325 raise ValueError(
326 'path was not specified, and no sock specified')
327
328 if (sock.family != socket.AF_UNIX or
329 sock.type != socket.SOCK_STREAM):

Callers

nothing calls this directly

Calls 10

_start_servingMethod · 0.95
socketMethod · 0.80
statMethod · 0.45
removeMethod · 0.45
errorMethod · 0.45
bindMethod · 0.45
closeMethod · 0.45
getsocknameMethod · 0.45
setblockingMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected