Skip to content

Commit bcbf807

Browse files
committed
Modify echoserver to have a stats key in addition to the
cancel session key.
1 parent ef1a92f commit bcbf807

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,19 @@ static INLINE void tcp_bind(SOCKET_T* sockFd, uint16_t port, int useAnyAddr)
269269
}
270270

271271

272-
static int find_char(uint8_t ch, const uint8_t* buf, uint32_t bufSz)
272+
static uint8_t find_char(const uint8_t* str, const uint8_t* buf, uint32_t bufSz)
273273
{
274+
const uint8_t* cur;
275+
274276
while (bufSz) {
275-
if (ch == *buf)
276-
return 1;
277-
else {
278-
buf++;
279-
bufSz--;
277+
cur = str;
278+
while (*cur != '\0') {
279+
if (*cur == *buf)
280+
return *cur;
281+
cur++;
280282
}
283+
buf++;
284+
bufSz--;
281285
}
282286

283287
return 0;
@@ -318,10 +322,19 @@ static THREAD_RETURN CYASSL_THREAD server_worker(void* vArgs)
318322
backlogSz - txSum);
319323

320324
if (txSz > 0) {
321-
if (find_char(0x03, buf + txSum, txSz))
322-
stop = 1;
323-
else
324-
txSum += txSz;
325+
uint8_t c;
326+
const uint8_t matches[] = { 0x03, 0x04, 0x05, 0x00 };
327+
328+
c = find_char(matches, buf + txSum, txSz);
329+
switch (c) {
330+
case 0x03:
331+
stop = 1;
332+
break;
333+
case 0x05:
334+
fprintf(stderr, "dump stats\n");
335+
default:
336+
txSum += txSz;
337+
}
325338
}
326339
else if (txSz != WS_REKEYING)
327340
stop = 1;

0 commit comments

Comments
 (0)