Have one call to from_backend() per call to do_telnet_read(),
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 8 Jan 2007 18:54:49 +0000 (18:54 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 8 Jan 2007 18:54:49 +0000 (18:54 +0000)
instead of the previous rate of one per character. In `Flush log
file frequently' mode, the latter was causing excessive slowdown due
to fflush()ing once per byte.

git-svn-id: svn://svn.tartarus.org/sgt/putty@7076 cda61777-01e9-0310-a592-d414129be87e

telnet.c

index 0d32f8c..e6ad83e 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -254,11 +254,10 @@ typedef struct telnet_tag {
 
 #define SB_DELTA 1024
 
-static void c_write1(Telnet telnet, int c)
+static void c_write(Telnet telnet, char *buf, int len)
 {
     int backlog;
-    char cc = (char) c;
-    backlog = from_backend(telnet->frontend, 0, &cc, 1);
+    backlog = from_backend(telnet->frontend, 0, buf, len);
     sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG);
 }
 
@@ -541,6 +540,16 @@ static void process_subneg(Telnet telnet)
 
 static void do_telnet_read(Telnet telnet, char *buf, int len)
 {
+    char *outbuf = NULL;
+    int outbuflen = 0, outbufsize = 0;
+
+#define ADDTOBUF(c) do { \
+    if (outbuflen >= outbufsize) { \
+       outbufsize = outbuflen + 256; \
+        outbuf = sresize(outbuf, outbufsize, char); \
+    } \
+    outbuf[outbuflen++] = (c); \
+} while (0)
 
     while (len--) {
        int c = (unsigned char) *buf++;
@@ -554,7 +563,7 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
                telnet->state = SEENIAC;
            else {
                if (!telnet->in_synch)
-                   c_write1(telnet, c);
+                   ADDTOBUF(c);
 
 #if 1
                /* I can't get the F***ing winsock to insert the urgent IAC
@@ -591,7 +600,7 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
            } else {
                /* ignore everything else; print it if it's IAC */
                if (c == IAC) {
-                   c_write1(telnet, c);
+                   ADDTOBUF(c);
                }
                telnet->state = TOP_LEVEL;
            }
@@ -641,6 +650,10 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
            break;
        }
     }
+
+    if (outbuflen)
+       c_write(telnet, outbuf, outbuflen);
+    sfree(outbuf);
 }
 
 static void telnet_log(Plug plug, int type, SockAddr addr, int port,