main.c

changeset 1
cfb60868c745
parent 0
2f2165f8c8ea
equal deleted inserted replaced
0:2f2165f8c8ea 1:cfb60868c745
1 #include <string.h> 1 #include <string.h>
2 #include <math.h>
2 #include <stdlib.h> 3 #include <stdlib.h>
3 #include <time.h> 4 #include <time.h>
4 5
5 #include <strophe.h> 6 #include <strophe.h>
6 7
7 8
8 xmpp_conn_t *conn1, *conn2; 9 xmpp_conn_t *conn1, *conn2;
9 10
10 unsigned long mincount, maxcount, count; 11 unsigned long mincount, maxcount;
12 unsigned long count = 0;
11 13
12 long samples; /* Current number of samples taken */ 14 unsigned long sum_squares = 0;
13 long max_samples; /* The number of samples to do, if specified by user */ 15 unsigned long samples = 0; /* Current number of samples taken */
16 unsigned long max_samples = 15; /* The number of samples to do, if specified by user */
14 17
15 time_t lasttime; /* Time of the last sample we took */ 18 time_t lasttime; /* Time of the last sample we took */
16 19
17 char* jid1 = "test1@getjabber.ath.cx"; 20 char* jid1 = "test1@getjabber.ath.cx";
18 char* jid2 = "test2@getjabber.ath.cx"; 21 char* jid2 = "test2@getjabber.ath.cx";
31 if(conn == conn2) 34 if(conn == conn2)
32 { 35 {
33 count++; 36 count++;
34 if(time(NULL) != lasttime) 37 if(time(NULL) != lasttime)
35 { 38 {
36 printf("%d stanzas/sec\n", count); 39
37 if(count > maxcount) 40 if(lasttime > 0)
38 { 41 {
39 printf("%d beats old maximum of %d\n", count, maxcount); 42 //printf("%d stanzas/sec\n", count);
40 maxcount = count; 43 if(count > maxcount && lasttime > 0)
44 {
45 //printf("%d beats old maximum of %d\n", count, maxcount);
46 maxcount = count;
47 }
48 sum_squares += count*count;
49 samples++;
50 if(samples >= max_samples)
51 {
52 printf("%Lf\n", sqrtl(sum_squares/samples));
53 exit(0);
54 }
41 } 55 }
42 count = 0; 56 count = 0;
43 lasttime = time(NULL); 57 lasttime = time(NULL);
44 } 58 }
45 xmpp_send(conn1, bstanza); 59 xmpp_send(conn1, bstanza);
55 { 69 {
56 xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; 70 xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
57 71
58 if (status == XMPP_CONN_CONNECT) { 72 if (status == XMPP_CONN_CONNECT) {
59 xmpp_stanza_t* pres; 73 xmpp_stanza_t* pres;
60 fprintf(stderr, "DEBUG: connected\n"); 74 //fprintf(stderr, "DEBUG: connected\n");
61 xmpp_handler_add(conn,message_handler, NULL, "message", NULL, ctx); 75 xmpp_handler_add(conn,message_handler, NULL, "message", NULL, ctx);
62 76
63 /* Send initial <presence/> so that we appear online to contacts */ 77 /* Send initial <presence/> so that we appear online to contacts */
64 pres = xmpp_stanza_new(ctx); 78 pres = xmpp_stanza_new(ctx);
65 xmpp_stanza_set_name(pres, "presence"); 79 xmpp_stanza_set_name(pres, "presence");
67 xmpp_stanza_release(pres); 81 xmpp_stanza_release(pres);
68 82
69 if(conn == conn2) 83 if(conn == conn2)
70 { 84 {
71 count = 0; 85 count = 0;
72 lasttime = time(NULL); 86 lasttime = 0;
73 87
74 xmpp_send(conn1, bstanza); 88 xmpp_send(conn1, bstanza);
75 } 89 }
76 } 90 }
77 else { 91 else {
78 fprintf(stderr, "DEBUG: disconnected\n"); 92 //fprintf(stderr, "DEBUG: disconnected\n");
79 xmpp_stop(ctx); 93 xmpp_stop(ctx);
80 } 94 }
81 } 95 }
82 96
83 int main(int argc, char *argv[]) 97 int main(int argc, char *argv[])
84 { 98 {
85 xmpp_ctx_t *ctx; 99 xmpp_ctx_t *ctx;
86 xmpp_log_t *log = NULL; 100 xmpp_log_t *log = NULL;
87 xmpp_stanza_t *body, *text; 101 xmpp_stanza_t *body, *text;
88 102
89 printf("Loading...\n"); 103 //printf("Loading...\n");
90 /* init library */ 104 /* init library */
91 xmpp_initialize(); 105 xmpp_initialize();
92 106
93 /* create a context */ 107 /* create a context */
94 #ifdef LOGGING 108 #ifdef LOGGING
126 140
127 /* initiate connection */ 141 /* initiate connection */
128 xmpp_connect_client(conn1, "localhost", 5222, conn_handler, ctx); 142 xmpp_connect_client(conn1, "localhost", 5222, conn_handler, ctx);
129 xmpp_connect_client(conn2, "localhost", 5222, conn_handler, ctx); 143 xmpp_connect_client(conn2, "localhost", 5222, conn_handler, ctx);
130 144
131 printf("Connecting...\n"); 145 //printf("Connecting...\n");
132 /* enter the event loop - 146 /* enter the event loop -
133 our connect handler will trigger an exit */ 147 our connect handler will trigger an exit */
134 xmpp_run(ctx); 148 xmpp_run(ctx);
135 149
136 /* release our connection and context */ 150 /* release our connection and context */

mercurial