From 43a636967db1027b1969acee762b8ff428fe83de Mon Sep 17 00:00:00 2001 From: rs <> Date: Thu, 24 Feb 2022 01:23:58 -0600 Subject: [PATCH] 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. --- cbs-srv.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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) -- 2.43.0