From b30d32159dc3c7052f4bfdf36357996c905af739 Mon Sep 17 00:00:00 2001 From: "djm@openbsd.org" Date: Sat, 22 Jan 2022 00:49:34 +0000 Subject: upstream: add a ssh_packet_process_read() function that reads from a fd directly into the transport input buffer. Use this in the client and server mainloops to avoid unnecessary copying. It also lets us use a more greedy read size without penalty. Yields a 2-3% performance gain on cipher-speed.sh (in a fairly unscientific test tbf) feedback dtucker@ ok markus@ OpenBSD-Commit-ID: df4112125bf79d8e38e79a77113e1b373078e632 --- clientloop.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'clientloop.c') diff --git a/clientloop.c b/clientloop.c index 5145f011..fd190980 100644 --- a/clientloop.c +++ b/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.377 2022/01/21 07:04:19 djm Exp $ */ +/* $OpenBSD: clientloop.c,v 1.378 2022/01/22 00:49:34 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -630,40 +630,25 @@ client_suspend_self(struct sshbuf *bin, struct sshbuf *bout, struct sshbuf *berr static void client_process_net_input(struct ssh *ssh) { - char buf[SSH_IOBUFSZ]; - int len; + int r; /* * Read input from the server, and add any such data to the buffer of * the packet subsystem. */ schedule_server_alive_check(); - /* Read as much as possible. */ - len = read(connection_in, buf, sizeof(buf)); - if (len == 0) { - /* Received EOF. The remote host has closed the connection. */ - quit_message("Connection to %.300s closed by remote host.", - host); - return; - } - /* - * There is a kernel bug on Solaris that causes poll to - * sometimes wake up even though there is no data available. - */ - if (len == -1 && - (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)) - len = 0; - - if (len == -1) { - /* - * An error has encountered. Perhaps there is a - * network problem. - */ - quit_message("Read from remote host %s: %s", - host, strerror(errno)); - return; + if ((r = ssh_packet_process_read(ssh, connection_in)) == 0) + return; /* success */ + if (r == SSH_ERR_SYSTEM_ERROR) { + if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) + return; + if (errno == EPIPE) { + quit_message("Connection to %s closed by remote host.", + host); + return; + } } - ssh_packet_process_incoming(ssh, buf, len); + quit_message("Read from remote host %s: %s", host, ssh_err(r)); } static void -- cgit v1.2.1