Closed YoSTEALTH closed 1 month ago
This code works and return data as it should:
from shakti import run, socket, connect, recv, send, shutdown, close
async def client(host, port, header):
received = bytearray()
client_fd = await socket()
await connect(client_fd, host, port)
print('client sent:', await send(client_fd, header))
while data := await recv(client_fd, 1024):
received.extend(data)
print('client recv:', received)
await close(client_fd)
print('closed')
if __name__ == '__main__':
host = 'example.com'
port = 80
header = f'GET / HTTP/1.0\nHost: {host}\nUser-Agent: Testing\n\n'.encode()
run(client(host, port, header))
# client sent: 54
# result: 1024
# result: 424
# result: 169
# result: 0
# client recv: bytearray(b'HTTP/1.0 200 OK ...')
# closed
changing the code to HTTP/1.1
does not return 0
and hangs!
header = f'GET / HTTP/1.1\nHost: {host}\nUser-Agent: Testing\n\n'.encode()
Not a bug, was having a brain fart not using Connection: close
for HTTP/1.1
While using
recv
in C, you get-1
on error,0
on EOF and>0
on success.In python its
>0
on success0
on EOF andOSError
In
io_uring_prep_recv
I am not getting0
on EOF but just hangs till connection times out. Tried withSOCK_NONBLOCK
as well.having to kill the process: