Skip to content

Commit 4218e7d

Browse files
author
Paul Sokolovsky
committed
asyncio_micro: Implement start_server().
1 parent 4e3964d commit 4218e7d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

asyncio_micro/asyncio_micro.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,23 @@ def open_connection(host, port):
235235
s = yield IOWrite(s)
236236
log.debug("open_connection: After iowait: %s", s)
237237
return StreamReader(s), StreamWriter(s)
238+
239+
240+
def start_server(client_coro, host, port):
241+
log.debug("start_server(%s, %s)", host, port)
242+
s = _socket.socket()
243+
s.setblocking(False)
244+
245+
ai = _socket.getaddrinfo(host, port)
246+
addr = ai[0][4]
247+
s.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, 1)
248+
s.bind(addr)
249+
s.listen(10)
250+
while True:
251+
log.debug("start_server: Before accept")
252+
yield IORead(s)
253+
log.debug("start_server: After iowait")
254+
s2, client_addr = s.accept()
255+
s2.setblocking(False)
256+
log.debug("start_server: After accept: %s", s2)
257+
yield client_coro(StreamReader(s2), StreamWriter(s2))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy