Sender test program

This commit is contained in:
Tony Garnock-Jones 2011-01-02 13:32:53 -05:00
parent f98f0c9876
commit 114d8191df
2 changed files with 68 additions and 1 deletions

View File

@ -57,7 +57,7 @@ int main(int argc, char *argv[]) {
double delta;
gettimeofday(&now, NULL);
delta = (now.tv_sec - start_time.tv_sec) + (now.tv_usec - start_time.tv_usec) / 1000000.0;
printf("So far %ld bytes in %g seconds = %g bytes/sec and %g msgs/sec\n",
printf("So far received %ld bytes in %g seconds = %g bytes/sec and %g msgs/sec\n",
bytecount,
delta,
bytecount / delta,

67
test3.c Normal file
View File

@ -0,0 +1,67 @@
/* Copyright (C) 2010 Tony Garnock-Jones. All rights reserved. */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <time.h>
#include <sys/time.h>
#include <assert.h>
int main(int argc, char *argv[]) {
int fd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in s;
FILE *f;
struct timeval start_time;
long bytecount = 0;
char const *msg = "(4:post2:q1(4:post0:6:XXXXXX0:)0:)";
size_t msglen = strlen(msg);
int i;
s.sin_family = AF_INET;
s.sin_addr.s_addr = htonl(0x7f000001);
s.sin_port = htons(5671);
if (connect(fd, (struct sockaddr *) &s, sizeof(s)) < 0) return 1;
f = fdopen(fd, "a+");
fprintf(f, "(9:subscribe5:test30:0:5:test35:login)");
fflush(f);
gettimeofday(&start_time, NULL);
for (i = 0; i < 10000000; i++) {
fwrite(msg, msglen, 1, f);
bytecount += msglen;
if ((bytecount % 100000) < msglen) {
struct timeval now;
double delta;
gettimeofday(&now, NULL);
delta = (now.tv_sec - start_time.tv_sec) + (now.tv_usec - start_time.tv_usec) / 1000000.0;
printf("So far sent %ld bytes in %g seconds = %g bytes/sec and %g msgs/sec\n",
bytecount,
delta,
bytecount / delta,
bytecount / (delta * msglen));
fflush(stdout);
}
}
fprintf(f, "(11:unsubscribe5:test3)");
fflush(f);
fclose(f);
return 0;
}