Author: hbelusca
Date: Tue Apr 23 00:41:45 2013
New Revision: 58834
URL: http://svn.reactos.org/svn/reactos?rev=58834&view=rev
Log:
[KDCOM]
- Use stdlib.h header instead of declaring the atol function's prototype (caught by Jérôme).
- Clarify the loop in KdpSendPacket (by Timo).
NOTE: I also noticed that it was not this loop-change that fixed reconnection (see commit message of r58823), but one of the changes of revision r58822 (certainly the one in the KdpReceiveByte function) (ironically I said "Seems to fix..." since I noticed that change of behaviour when I was trying to play with the code in KdpSendPacket with modifications of r58822, but I didn't notice that in fact it happened with changes of r58822. It is only today that I constated that, during a revert of r58823 + test + a remark from Timo).
Modified:
trunk/reactos/drivers/base/kddll/kdcom.c
trunk/reactos/drivers/base/kddll/kddll.c
trunk/reactos/drivers/base/kddll/kdserial.c
Modified: trunk/reactos/drivers/base/kddll/kdcom.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kdcom.c…
==============================================================================
--- trunk/reactos/drivers/base/kddll/kdcom.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/base/kddll/kdcom.c [iso-8859-1] Tue Apr 23 00:41:45 2013
@@ -8,8 +8,7 @@
#include "kddll.h"
#include <cportlib/cportlib.h>
-
-long atol(const char *str);
+#include <stdlib.h>
/* Serial debug connection */
Modified: trunk/reactos/drivers/base/kddll/kddll.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kddll.c…
==============================================================================
--- trunk/reactos/drivers/base/kddll/kddll.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/base/kddll/kddll.c [iso-8859-1] Tue Apr 23 00:41:45 2013
@@ -34,7 +34,10 @@
PUCHAR ByteBuffer = Buffer;
ULONG Checksum = 0;
- while (Length-- > 0) Checksum += (ULONG)*ByteBuffer++;
+ while (Length-- > 0)
+ {
+ Checksum += (ULONG)*ByteBuffer++;
+ }
return Checksum;
}
@@ -335,18 +338,8 @@
Retries = KdContext->KdpDefaultRetries;
- do
+ for (;;)
{
- if (Retries == 0)
- {
- /* PACKET_TYPE_KD_DEBUG_IO is allowed to instantly timeout */
- if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
- {
- /* No response, silently fail. */
- return;
- }
- }
-
/* Set the packet id */
Packet.PacketId = CurrentPacketId;
@@ -357,7 +350,10 @@
KdpSendBuffer(MessageHeader->Buffer, MessageHeader->Length);
/* If we have meesage data, also send it */
- if (MessageData) KdpSendBuffer(MessageData->Buffer, MessageData->Length);
+ if (MessageData)
+ {
+ KdpSendBuffer(MessageData->Buffer, MessageData->Length);
+ }
/* Finalize with a trailing byte */
KdpSendByte(PACKET_TRAILING_BYTE);
@@ -368,17 +364,37 @@
NULL,
NULL,
KdContext);
- if (KdStatus == KDP_PACKET_TIMEOUT)
- {
- if (Retries > 0) Retries--;
- }
+
+ /* Did we succeed? */
+ if (KdStatus == KDP_PACKET_RECEIVED)
+ {
+ /* Packet received, we can quit the loop */
+ CurrentPacketId &= ~SYNC_PACKET_ID;
+ break;
+ }
+ else if (KdStatus == KDP_PACKET_TIMEOUT)
+ {
+ /* Timeout, decrement the retry count */
+ if (Retries > 0)
+ Retries--;
+
+ /*
+ * If the retry count reaches zero, bail out
+ * for packet types allowed to timeout.
+ */
+ if (Retries == 0)
+ {
+ if (PacketType == PACKET_TYPE_KD_DEBUG_IO)
+ {
+ return;
+ }
+ }
+ }
+ // else (KdStatus == KDP_PACKET_RESEND) /* Resend the packet */
/* Packet timed out, send it again */
KDDBGPRINT("KdSendPacket got KdStatus 0x%x\n", KdStatus);
-
- } while (KdStatus != KDP_PACKET_RECEIVED);
-
- CurrentPacketId &= ~SYNC_PACKET_ID;
+ }
}
/* EOF */
Modified: trunk/reactos/drivers/base/kddll/kdserial.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/base/kddll/kdseria…
==============================================================================
--- trunk/reactos/drivers/base/kddll/kdserial.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/base/kddll/kdserial.c [iso-8859-1] Tue Apr 23 00:41:45 2013
@@ -24,7 +24,10 @@
{
PUCHAR ByteBuffer = Buffer;
- while (Size-- > 0) KdpSendByte(*ByteBuffer++);
+ while (Size-- > 0)
+ {
+ KdpSendByte(*ByteBuffer++);
+ }
}
/******************************************************************************
@@ -49,7 +52,9 @@
{
/* Try to get a byte from the port */
Status = KdpReceiveByte(&Byte);
- if (Status != KDP_PACKET_RECEIVED) return Status;
+ if (Status != KDP_PACKET_RECEIVED)
+ return Status;
+
*ByteBuffer++ = Byte;
}