int TcpClient::peekByte(size_t index)
{
     size_t cbReady = 0;

    if( (cbReady = available()) > 0 )
    {
        if(index >= cbReady)
        {
            return(-1);
        }

        return((int) TCPPeek(_hTCP, index));
    }

     return(-1);
}
예제 #2
0
/****************************************************************************
  Function:
    int ChipKITClientPeek(TCP_SOCKET hTCP)

  Description:
    This routine returns the next byte in the buffer without removing it from the buffer
	or -1 if no byes are available.

  Precondition:
    hTCP must be open and valid.

  Parameters:
    hTCP - The socket to check

  Returns:
    The number of bytes in the input buffer or -1 if no bytes are available.

  Remarks:
	This is to match functionality of the Arduino Client class peek method
  ***************************************************************************/
int ChipKITClientPeek(TCP_SOCKET hTCP)
{
	unsigned int cb = 0;

	ChipKITPeriodicTasks();

	cb = TCPIsGetReady(hTCP);

	// follow the Arduino convension or return -1 on empty
	if(cb == 0)
	{
		return(-1);
	}
	else
	{
		return( (int) ((unsigned int) TCPPeek(hTCP, 0)));
 	}
}