478 { |
478 { |
479 BYTE* ptr = m_pBuffer; |
479 BYTE* ptr = m_pBuffer; |
480 long bytesRemaining = m_numberBytes; |
480 long bytesRemaining = m_numberBytes; |
481 long usedLen = 0; |
481 long usedLen = 0; |
482 bool done = false; |
482 bool done = false; |
|
483 long numberSkipped=0; |
483 |
484 |
484 while (!done) |
485 while (!done) |
485 { |
486 { |
486 DWORD fullMessageLength = bytesRemaining; |
487 DWORD fullMessageLength = bytesRemaining; |
487 DWORD rawLength = 0; |
488 DWORD rawLength = 0; |
488 BYTE* fullMessage = ptr; |
489 BYTE* fullMessage = ptr; |
489 BYTE* rawMessage = ptr; |
490 BYTE* rawMessage = ptr; |
490 BYTE msgId = 0; |
491 BYTE msgId = 0; |
491 if (m_Protocol->DecodeMessage(fullMessage, fullMessageLength, msgId, rawMessage, rawLength)) |
492 int result = m_Protocol->DecodeMessage(fullMessage, fullMessageLength, msgId, rawMessage, rawLength); |
|
493 if (result == DECODE_NOT_ENOUGH_BYTES_TO_SEARCH) |
|
494 { |
|
495 done = true; |
|
496 } |
|
497 else if (result == DECODE_MESSAGE_NOT_FOUND) |
|
498 { |
|
499 numberSkipped++; |
|
500 usedLen += fullMessageLength; |
|
501 bytesRemaining -= fullMessageLength; |
|
502 ptr += fullMessageLength; |
|
503 if (bytesRemaining < protocolHeaderLength) |
|
504 done = true; |
|
505 } |
|
506 else if (result == DECODE_MESSAGE_FOUND) |
492 { |
507 { |
493 err = PreProcessMessage(msgId, fullMessageLength, fullMessage); |
508 err = PreProcessMessage(msgId, fullMessageLength, fullMessage); |
494 if (err != TCAPI_ERR_NONE) |
509 if (err != TCAPI_ERR_NONE) |
495 { |
510 { |
496 PROCLOGOPEN(); |
511 PROCLOGOPEN(); |
500 pConn->NotifyClientsCommError(err, false, 0); |
515 pConn->NotifyClientsCommError(err, false, 0); |
501 err = TCAPI_ERR_NONE; |
516 err = TCAPI_ERR_NONE; |
502 } |
517 } |
503 #ifdef _DEBUG |
518 #ifdef _DEBUG |
504 int reallen = fullMessageLength; |
519 int reallen = fullMessageLength; |
505 if (reallen > 50) reallen = 50; |
520 if (reallen > 80) reallen = 80; |
506 char msg[6]; |
521 char msg[6]; |
507 msg[0] = '\0'; |
522 msg[0] = '\0'; |
508 |
523 |
509 sTcpLogMsg[0] = '\0'; |
524 sTcpLogMsg[0] = '\0'; |
510 if (reallen > 0) |
525 if (reallen > 0) |
511 { |
526 { |
512 sTcpLogMsg[0] = '\0'; |
527 sTcpLogMsg[0] = '\0'; |
513 for (int i = 0; i < reallen; i++) |
528 for (int i = 0; i < reallen; i++) |
514 { |
529 { |
515 sprintf(msg, "%02.2x ", ptr[i]); |
530 if (isalnum(ptr[i])) |
|
531 { |
|
532 sprintf(msg, "%c", ptr[i]); |
|
533 } |
|
534 else |
|
535 { |
|
536 sprintf(msg, "%02.2x ", ptr[i]); |
|
537 } |
516 strcat(sTcpLogMsg, msg); |
538 strcat(sTcpLogMsg, msg); |
517 } |
539 } |
518 } |
540 } |
519 #endif |
541 #endif |
520 PROCLOGOPEN(); |
542 PROCLOGOPEN(); |
521 PROCLOGA5("CTcpComm::ProcessBuffer - RouteMesssage pRegistry = %x id=%x len=%d len=%d\n msg=%s\n", pRegistry, msgId, fullMessageLength, rawLength, sTcpLogMsg); |
543 PROCLOGA5("CTcpComm::ProcessBuffer - RouteMesssage pRegistry = %x id=%x len=%d len=%d msg=%s\n", pRegistry, msgId, fullMessageLength, rawLength, sTcpLogMsg); |
522 PROCLOGCLOSE(); |
544 PROCLOGCLOSE(); |
523 |
545 |
524 err = pRegistry->RouteMessage(msgId, fullMessage, fullMessageLength, rawMessage, rawLength); |
546 err = pRegistry->RouteMessage(msgId, fullMessage, fullMessageLength, rawMessage, rawLength); |
525 if (err != TCAPI_ERR_NONE) routingErr = err; // saved for future |
547 if (err != TCAPI_ERR_NONE) routingErr = err; // saved for future |
526 |
548 |
529 bytesRemaining -= fullMessageLength; |
551 bytesRemaining -= fullMessageLength; |
530 ptr += fullMessageLength; |
552 ptr += fullMessageLength; |
531 if (bytesRemaining < protocolHeaderLength) |
553 if (bytesRemaining < protocolHeaderLength) |
532 done = true; |
554 done = true; |
533 } |
555 } |
534 else |
|
535 { |
|
536 numberProcessed++; |
|
537 usedLen += fullMessageLength; |
|
538 bytesRemaining -= fullMessageLength; |
|
539 ptr += fullMessageLength; |
|
540 if (bytesRemaining < protocolHeaderLength) |
|
541 done = true; |
|
542 } |
|
543 } |
556 } |
544 DeleteMsg(usedLen); |
557 DeleteMsg(usedLen); |
|
558 PROCLOGOPEN(); |
|
559 PROCLOGA2("CTcpComm::ProcessBuffer - numberSkipped=%d numberProcessed=%d\n", numberSkipped, numberProcessed); |
|
560 PROCLOGCLOSE(); |
545 } |
561 } |
546 } |
562 } |
547 |
563 |
548 if (routingErr == TCAPI_ERR_NONE) |
564 if (routingErr == TCAPI_ERR_NONE) |
549 return err; |
565 return err; |