Crude subscriber test
This commit is contained in:
parent
e52c3df365
commit
449be964e3
|
@ -0,0 +1,71 @@
|
|||
/* 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 = -1;
|
||||
|
||||
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:test10:0:5:test15:login)(4:post7:factory(6:create5:queue(2:q1)5:test11:k)0:)(4:post2:q1(9:subscribe0:5:test18:consumer5:test11:k)0:)\n");
|
||||
fflush(f);
|
||||
|
||||
while (1) {
|
||||
char buf[1024];
|
||||
size_t n = read(fd, buf, sizeof(buf));
|
||||
if (n == 0) break;
|
||||
if (n >= 7) {
|
||||
if (!memcmp(buf, "(4:post", 7)) {
|
||||
if (bytecount == -1) {
|
||||
printf("Starting.\n");
|
||||
bytecount = 0;
|
||||
gettimeofday(&start_time, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bytecount >= 0) {
|
||||
bytecount += n;
|
||||
#define MESSAGESIZE 26
|
||||
if ((bytecount % 100000) < MESSAGESIZE) {
|
||||
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 %ld bytes in %g seconds = %g bytes/sec and %g msgs/sec\n",
|
||||
bytecount,
|
||||
delta,
|
||||
bytecount / delta,
|
||||
bytecount / (delta * MESSAGESIZE));
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue