Listing 2: Test your application by sending randomly selected lengths of multiple AL messages from a buffer.
int send_msg (fd, bp) int fd; char *bp; { static char stream_buffer [MAX_MSG_LEN * MAX_MSGS]; static msg_count = 0; char * cp; int stream_len = 0; int count, saved_count, sent; if (msg_count == 0) stream_buffer [0] = 0x0; strcat (stream_buffer, bp); msg_count++; if (msg_count < MAX_MSGS) if ((random () * MAX_MSGS) > msg_count) return (0); stream_len = strlen (stream_buffer); cp = stream_buffer; while (stream_len > 0)/ { count = random () * stream_len; if (count == 0) count = 1; saved_count = count; sent = 0; while (sent != count) { sent = send (fd, cp, count, 0); if (sent < 1) return (-1); if (sent < count) { cp = &cp [sent]; count = count - sent; } } cp = &cp [count]; stream_len = stream_len - saved_count; count = random () * 5; sleep (count); } msg_count = 0; return (1); }