TCPFindArrayEx Function

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
TCPFindArrayEx Function
C
WORD TCPFindArrayEx(
    TCP_SOCKET hTCP, 
    BYTE* cFindArray, 
    WORD wLen, 
    WORD wStart, 
    WORD wSearchLen, 
    BOOL bTextCompare
);
Description

This function finds the first occurrance of an array of bytes in the TCP RX buffer. It can be used by an application to abstract searches out of their own application code. For increased efficiency, the function is capable of limiting the scope of search to a specific range of bytes. It can also perform a case-insensitive search if required. 

For example, if the buffer contains "I love PIC MCUs!" and the search array is "love" with a length of 4, a value of 2 will be returned.

Preconditions

TCP is initialized.

Parameters
Parameters 
Description 
hTCP 
The socket to search within. 
cFindArray 
The array of bytes to find in the buffer. 
wLen 
Length of cFindArray. 
wStart 
Zero-indexed starting position within the buffer. 
wSearchLen 
Length from wStart to search in the buffer. 
bTextCompare 
TRUE for case-insensitive text search, FALSE for binary search 
Return Values
Return Values 
Description 
0xFFFF 
Search array not found 
Otherwise 
Zero-indexed position of the first occurrance 
Remarks

Since this function usually must transfer data from external storage to internal RAM for comparison, its performance degrades significantly when the buffer is full and the array is not found. For better performance, try to search for characters that are expected to exist or limit the scope of the search as much as possible. The HTTP2 module, for example, uses this function to parse headers. However, it searches for newlines, then the separating colon, then reads the header name to RAM for final comparison. This has proven to be significantly faster than searching for full header name strings outright.

Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.