From: rs <> Date: Thu, 24 Feb 2022 07:23:58 +0000 (-0600) Subject: Use sendall() instead of send() X-Git-Url: https://git.the-white-hart.net/?a=commitdiff_plain;h=43a636967db1027b1969acee762b8ff428fe83de;p=gemini%2Fcbs-server.git Use sendall() instead of send() Images weren't being served up properly because there was too much data for send() to get through before the connection was closed out from under it. --- diff --git a/cbs-srv.py b/cbs-srv.py index 4cf633d..2a0fd2e 100755 --- a/cbs-srv.py +++ b/cbs-srv.py @@ -174,7 +174,7 @@ def serve_cgi(conn: SSL.Connection, addr, req_path, extra_path, url, conf: dict) raise CBSException(42, 'CGI script error', '{} -> {}'.format(req_path, x.returncode)) except PermissionError: raise CBSException(42, 'CGI not executable', req_path) - conn.send(proc.stdout) + conn.sendall(proc.stdout) def serve_file(conn: SSL.Connection, filedir): @@ -185,8 +185,8 @@ def serve_file(conn: SSL.Connection, filedir): f.close() except Exception as x: raise CBSException(40, 'Server error accessing content', x) - conn.send('20 {}\r\n'.format(mime_type or 'application/octet-stream').encode('utf-8')) - conn.send(content) + conn.sendall('20 {}\r\n'.format(mime_type or 'application/octet-stream').encode('utf-8')) + conn.sendall(content) # ------------------------------------------------------------------------------ @@ -225,10 +225,10 @@ def main(): serve_req(conn, addr, req, conf) except CBSException as x: logging.error('{} {} {}'.format(x.code, x.meta, x.logdata)) - conn.send('{} {}\r\n'.format(x.code, x.meta).encode('utf-8')) + conn.sendall('{} {}\r\n'.format(x.code, x.meta).encode('utf-8')) except Exception as x: logging.error('Exception: {}'.format(x)) - conn.send('40 Server error\r\n') + conn.sendall('40 Server error\r\n') conn.shutdown() conn.sock_shutdown(socket.SHUT_RDWR)