changeset 130:352ec3c300e4

A different initialization.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 30 Oct 2010 15:19:34 +0300
parents 4235ff4ced04
children 3896861974ac
files nnchat.c
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Sat Oct 30 15:07:03 2010 +0300
+++ b/nnchat.c	Sat Oct 30 15:19:34 2010 +0300
@@ -534,13 +534,17 @@
 
 int handleProtocol(const int sock, const char *buf, const ssize_t bufLen)
 {
+    static BOOL protoCmdsInit = FALSE;
     int i;
+
+    if (!protoCmdsInit) {
+        for (i = 0; i < nprotoCmds; i++)
+            protoCmds[i].len = strlen(protoCmds[i].cmd);
+        protoCmdsInit = TRUE;
+    }
     
     for (i = 0; i < nprotoCmds; i++) {
         ssize_t cmdLen = protoCmds[i].len;
-        if (cmdLen < 0)
-            cmdLen = protoCmds[i].len = strlen(protoCmds[i].cmd);
-
         if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen))
             return protoCmds[i].handler(sock, buf + cmdLen);
     }