* Network optimizations - buffer output server-side for better network
authorMichael Hampton <io_error@uncensored.citadel.org>
Sun, 5 Sep 2004 15:41:46 +0000 (15:41 +0000)
committerMichael Hampton <io_error@uncensored.citadel.org>
Sun, 5 Sep 2004 15:41:46 +0000 (15:41 +0000)
  utilization; one client-side optimization

citadel/ChangeLog
citadel/citadel_ipc.c
citadel/citserver.c
citadel/serv_chat.c
citadel/serv_crypto.c
citadel/sysdep.c

index dc2b440ef201317814fad564d16b25b3964b0cd0..1bc3cd77c9a488781968112188768f9d6c386570 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 625.12  2004/09/05 15:41:45  error
+ * Network optimizations - buffer output server-side for better network
+   utilization; one client-side optimization
+
  Revision 625.11  2004/09/05 15:20:41  error
  * sysdep.c: unbuffer_output(): Split the writing part to a new function
    flush_output() for more precise control
@@ -6042,4 +6046,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 9a07aa2cdb403c95229bd7c74667f2adc6c0a81e..ce5729cb21ae75992982d71baf0ad7186d21c041 100644 (file)
@@ -2834,9 +2834,22 @@ void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf)
  */
 static void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
 {
-       /* error_printf("< %s\n", buf); */
-       serv_write(ipc, buf, strlen(buf));
-       serv_write(ipc, "\n", 1);
+       char *cmd = NULL;
+       int len;
+
+       len = strlen(buf);
+       cmd = malloc(len + 2);
+       if (!cmd) {
+               /* This requires no extra memory */
+               serv_write(ipc, buf, len);
+               serv_write(ipc, "\n", 1);
+       } else {
+               /* This is network-optimized */
+               strncpy(cmd, buf, len);
+               strcpy(cmd + len, "\n");
+               serv_write(ipc, cmd, len + 1);
+               free(cmd);
+       }
 
        ipc->last_command_sent = time(NULL);
 }
index 1e52d43e209fcb3a428dc268f52c2571a6d355dd..c38cc0b4ca05a6b4e82596b45b1e5f517f5925d8 100644 (file)
@@ -948,6 +948,8 @@ void do_command_loop(void) {
        }
        lprintf(CTDL_INFO, "Citadel: %s\n", cmdbuf);
 
+       buffer_output();
+
        /*
         * Let other clients see the last command we executed, and
         * update the idle time, but not NOOP, QNOP, PEXP, or GEXP.
@@ -1316,6 +1318,8 @@ void do_command_loop(void) {
                        ERROR + CMD_NOT_SUPPORTED);
               }
 
+       unbuffer_output();
+
        /* Run any after-each-command routines registered by modules */
        PerformSessionHooks(EVT_CMD);
 }
index 89d715faa6d50103990329fa564e45e4a788d5eb..ce5770b3279e1d9da28d72665cbec6cb34dc7bd7 100644 (file)
@@ -241,6 +241,8 @@ void cmd_chat(char *argbuf)
        struct CitContext *t_context;
        int retval;
 
+       unbuffer_output();
+
        if (!(CC->logged_in)) {
                cprintf("%d Not logged in.\n", ERROR + NOT_LOGGED_IN);
                return;
index a2593aaa0623854ab61d21a04d04349046df63aa..19df6a87959c759d0c9556060e37bba2b6d013b6 100644 (file)
@@ -515,6 +515,8 @@ void cmd_stls(char *params)
        char nosup_response[SIZ];
        char error_response[SIZ];
 
+       unbuffer_output();
+
        sprintf(ok_response,
                "%d Begin TLS negotiation now\n",
                CIT_OK);
index 5925aa6137bfcc3fb267e972a80d49db8945f3b8..d2c509248422ea8728a852371e727fad5a19600d 100644 (file)
@@ -482,8 +482,10 @@ void flush_output(void) {
  */
 void unbuffer_output(void) {
        if (CC->buffering == 1) {
-               flush_output();
                CC->buffering = 0;
+               /* We don't call flush_output because we can't. */
+               client_write(CC->output_buffer, CC->buffer_len);
+               CC->buffer_len = 0;
                free(CC->output_buffer);
                CC->output_buffer = NULL;
        }