Agilent Technologies E4406A VSA Series Programmer's Manual page 148

Transmitter tester
Hide thumbs Also See for E4406A VSA Series:
Table of Contents

Advertisement

Programming Examples
Using C Programming Over Socket LAN
********************************************************/
count = recv(sock, tmp_buf, 1, 0); /* read 1 char */
ch = tmp_buf[0];
if ((count < 1) || (ch == EOF)
{
*result = '\0';
return 0;
}
/* use a do-while so we can break out */
do
{
if (ch == '#')
{
/* binary data encountered - figure out what it is */
long numDigits;
long numBytes = 0;
/* char length[10]; */
count = recv(sock, tmp_buf, 1, 0); /* read 1 char */
ch = tmp_buf[0];
if ((count < 1) || (ch == EOF)) break; /* End of file */
if (ch < '0' || ch > '9') break;
numDigits = ch - '0';
if (numDigits)
{
/* read numDigits bytes into result string. */
count = recv(sock, result, (int)numDigits, 0);
result[count] = 0;
numBytes = atol(result);
}
if (numBytes)
{
resultBytes = 0;
/* Loop until we get all the bytes we requested. */
/* Each call seems to return up to 1457 bytes, on HP-UX 9.05 */
do {
int rcount;
rcount = recv(sock, result, (int)numBytes, 0);
resultBytes += rcount;
result
} while ( resultBytes < numBytes );
/************************************************************
* For LAN dumps, there is always an extra trailing newline
* Since there is no EOI line.
* great but for binary dumps, it is not needed.
***********************************************************/
if (resultBytes == numBytes)
148
|| (ch == '\n'))
/* null terminate result for ascii */
/* null terminate */
+= rcount;
/* unexpected char */
/* Advance pointer */
For ASCII dumps this is
Chapter 3

Advertisement

Table of Contents
loading

Table of Contents