lrs_get_last_received_buffer

Buffer Functions

Gets the last buffer received and its size.

int lrs_get_last_received_buffer( char *s_desc, char **data, int *size );
Input  
s_desc A descriptor identifying a socket.
Output  
data A pointer to the buffer containing the data.
size A pointer to the size (in bytes) of the data.

The lrs_get_last_received_buffer function gets the last received buffer on the socket and its size. Note that function returns the length of the binary representation of data. The data buffer is not NULL terminated.

Note that memory is automatically allocated for the buffer, but you must manually free the memory after using this function with lrs_free_buffer.

This function is not recorded during a WinSock session—you manually insert it into your script. In addition, you must declare variables to store the buffer and its size, before calling lrs_get_last_received_buffer. Declare a character pointer for the data parameter, and an integer for the size parameter.

lrs_get_last_received_buffer and lrs_get_last_received_buffer_size should always follow one of the set of "receive" functions which write received data to a winsocket buffer. The "receive" functions are lrs_receive, lrs_receive_ex and lrs_length_receive.

Return Values

Windows Sockets Return Values

Parameterization

You cannot use standard parameterization for any arguments in this function.

Example

In the following example, the lrs_get_last_received_buffer function gets the last buffer and its size that were received on socket2.

char *ActualBuffer;
int NumberOfBytes;
lrs_receive("socket2", "buf20", LrsLastArg); 
/* Get the last received buffer and its size. */
lrs_get_last_received_buffer("socket2", &ActualBuffer, &NumberOfBytes);
lr_output_message("The last buffer's size is:%d/n, NumberOfBytes);
The contents of the buffer, as shown in the data file data.ws are:
Recv buf3 9
    "\xff\xfb\x01abc\n"
The output generated by the above code, as seen in the VuGen Execution log is:
Message from run.c(32): The buffer size is: 7 bytes
The ActualBuffer variable is a pointer to binary data; therefore you should not use string functions to manipulate it. To save the content of the buffer to a parameter for later use:
lrs_save_param_ex("socket2", "user", ActualBuffer, 3, 3, "ascii", "new_parameter");
lrs_free_buffer(ActualBuffer);
lr_output_message("new_parameter = \"%s\"\n", lr_eval_string("< new_parameter >"));
The output generated by the above code, as seen in the VuGen Execution log is:
Message from run.c(52): new_parameter = "abc"