]> andersk Git - openssh.git/commitdiff
- markus@cvs.openbsd.org 2008/05/08 06:59:01
authordjm <djm>
Mon, 19 May 2008 04:59:37 +0000 (04:59 +0000)
committerdjm <djm>
Mon, 19 May 2008 04:59:37 +0000 (04:59 +0000)
     [bufaux.c buffer.h channels.c packet.c packet.h]
     avoid extra malloc/copy/free when receiving data over the net;
     ~10% speedup for localhost-scp; ok djm@

ChangeLog
bufaux.c
buffer.h
channels.c
packet.c
packet.h

index cf3907edb98e7577f0e1500e57446d667c11d196..56a1d55b9b173053c92609412a5bf85dfb833a28 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
    - jmc@cvs.openbsd.org 2008/05/07 08:00:14
      [sshd_config.5]
      sort;
+   - markus@cvs.openbsd.org 2008/05/08 06:59:01
+     [bufaux.c buffer.h channels.c packet.c packet.h]
+     avoid extra malloc/copy/free when receiving data over the net;
+     ~10% speedup for localhost-scp; ok djm@
 
 20080403
  - (djm) [openbsd-compat/bsd-poll.c] Include stdlib.h to avoid compile-
index cbdc22c64288d4c1fe24fc972490b2a4620bda62..f033639940de17266c107532ed2f5614d071f717 100644 (file)
--- a/bufaux.c
+++ b/bufaux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bufaux.c,v 1.44 2006/08/03 03:34:41 deraadt Exp $ */
+/* $OpenBSD: bufaux.c,v 1.45 2008/05/08 06:59:01 markus Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -197,6 +197,22 @@ buffer_get_string(Buffer *buffer, u_int *length_ptr)
        return (ret);
 }
 
+void *
+buffer_get_string_ptr(Buffer *buffer, u_int *length_ptr)
+{
+       void *ptr;
+       u_int len;
+
+       len = buffer_get_int(buffer);
+       if (len > 256 * 1024)
+               fatal("buffer_get_string_ptr: bad string length %u", len);
+       ptr = buffer_ptr(buffer);
+       buffer_consume(buffer, len);
+       if (length_ptr)
+               *length_ptr = len;
+       return (ptr);
+}
+
 /*
  * Stores and arbitrary binary string in the buffer.
  */
index ecc4aea83193405b762397c6d47918e2369eb5ae..d0f354ee7bf7e685a51f6edf44b60aef603e5837 100644 (file)
--- a/buffer.h
+++ b/buffer.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.h,v 1.16 2006/08/03 03:34:41 deraadt Exp $ */
+/* $OpenBSD: buffer.h,v 1.17 2008/05/08 06:59:01 markus Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -66,6 +66,7 @@ int     buffer_get_char(Buffer *);
 void    buffer_put_char(Buffer *, int);
 
 void   *buffer_get_string(Buffer *, u_int *);
+void   *buffer_get_string_ptr(Buffer *, u_int *);
 void    buffer_put_string(Buffer *, const void *, u_int);
 void   buffer_put_cstring(Buffer *, const char *);
 
index b6bd901f053d24a5d3bd45527c449494e065d3a2..05c23e59c2b14551621b38de6ebc28c163ae11c6 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.273 2008/04/02 21:36:51 markus Exp $ */
+/* $OpenBSD: channels.c,v 1.274 2008/05/08 06:59:01 markus Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -2012,7 +2012,7 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
                return;
 
        /* Get the data. */
-       data = packet_get_string(&data_len);
+       data = packet_get_string_ptr(&data_len);
 
        /*
         * Ignore data for protocol > 1.3 if output end is no longer open.
@@ -2026,7 +2026,6 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
                        c->local_window -= data_len;
                        c->local_consumed += data_len;
                }
-               xfree(data);
                return;
        }
 
@@ -2038,17 +2037,15 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
                if (data_len > c->local_window) {
                        logit("channel %d: rcvd too much data %d, win %d",
                            c->self, data_len, c->local_window);
-                       xfree(data);
                        return;
                }
                c->local_window -= data_len;
        }
-       packet_check_eom();
        if (c->datagram)
                buffer_put_string(&c->output, data, data_len);
        else
                buffer_append(&c->output, data, data_len);
-       xfree(data);
+       packet_check_eom();
 }
 
 /* ARGSUSED */
index 6afe24b9fe4fa7680e374ba9e8d232444d2ab448..a34c040d6940224685c91552576ef68161ba48f2 100644 (file)
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.151 2008/02/22 20:44:02 dtucker Exp $ */
+/* $OpenBSD: packet.c,v 1.152 2008/05/08 06:59:01 markus Exp $ */
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1332,6 +1332,12 @@ packet_get_string(u_int *length_ptr)
        return buffer_get_string(&incoming_packet, length_ptr);
 }
 
+void *
+packet_get_string_ptr(u_int *length_ptr)
+{
+       return buffer_get_string_ptr(&incoming_packet, length_ptr);
+}
+
 /*
  * Sends a diagnostic message from the server to the client.  This message
  * can be sent at any time (but not while constructing another message). The
index c1b9b3bd190c2b778ce021c64ddf29dc9ebb468d..927e0831ce240ef655afe15fec6a3caa59b77d8f 100644 (file)
--- a/packet.h
+++ b/packet.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.h,v 1.46 2008/02/22 20:44:02 dtucker Exp $ */
+/* $OpenBSD: packet.h,v 1.47 2008/05/08 06:59:01 markus Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -58,6 +58,7 @@ void     packet_get_bignum(BIGNUM * value);
 void     packet_get_bignum2(BIGNUM * value);
 void   *packet_get_raw(u_int *length_ptr);
 void   *packet_get_string(u_int *length_ptr);
+void   *packet_get_string_ptr(u_int *length_ptr);
 void     packet_disconnect(const char *fmt,...) __attribute__((format(printf, 1, 2)));
 void     packet_send_debug(const char *fmt,...) __attribute__((format(printf, 1, 2)));
 
This page took 0.885171 seconds and 5 git commands to generate.