Mercurial > hg > nnchat
comparison nnchat.c @ 130:352ec3c300e4
A different initialization.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 30 Oct 2010 15:19:34 +0300 |
parents | 4235ff4ced04 |
children | 10daf4660cae |
comparison
equal
deleted
inserted
replaced
129:4235ff4ced04 | 130:352ec3c300e4 |
---|---|
532 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); | 532 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); |
533 | 533 |
534 | 534 |
535 int handleProtocol(const int sock, const char *buf, const ssize_t bufLen) | 535 int handleProtocol(const int sock, const char *buf, const ssize_t bufLen) |
536 { | 536 { |
537 static BOOL protoCmdsInit = FALSE; | |
537 int i; | 538 int i; |
539 | |
540 if (!protoCmdsInit) { | |
541 for (i = 0; i < nprotoCmds; i++) | |
542 protoCmds[i].len = strlen(protoCmds[i].cmd); | |
543 protoCmdsInit = TRUE; | |
544 } | |
538 | 545 |
539 for (i = 0; i < nprotoCmds; i++) { | 546 for (i = 0; i < nprotoCmds; i++) { |
540 ssize_t cmdLen = protoCmds[i].len; | 547 ssize_t cmdLen = protoCmds[i].len; |
541 if (cmdLen < 0) | |
542 cmdLen = protoCmds[i].len = strlen(protoCmds[i].cmd); | |
543 | |
544 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) | 548 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) |
545 return protoCmds[i].handler(sock, buf + cmdLen); | 549 return protoCmds[i].handler(sock, buf + cmdLen); |
546 } | 550 } |
547 | 551 |
548 return 1; | 552 return 1; |