source: trunk/FACT++/dim/src/examples/test_server_many.c@ 18522

Last change on this file since 18522 was 11071, checked in by tbretz, 14 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 2.7 KB
Line 
1#include <stdio.h>
2#include <dis.h>
3
4char str[10][80];
5
6typedef struct {
7 int i;
8 int j;
9 int k;
10 double d;
11 short s;
12 char c;
13 short t;
14 float f;
15 char str[20];
16}TT;
17
18double ServMany[100000];
19int ServManyIds[100000];
20
21TT t;
22/*
23int big_buff[1024];
24*/
25void cmnd_rout(tag, buf, size)
26int *tag, *size;
27TT *buf;
28{
29int i,*ptr;
30
31 printf("Command received, size = %d, TT size = %d:\n", *size,
32 sizeof(TT));
33 printf("buf->i = %d, buf->d = %2.2f, buf->s = %d, buf->c = %c, buf->f = %2.2f, buf->str = %s\n",
34 buf->i,buf->d,buf->s,buf->c,buf->f,buf->str);
35}
36
37void client_exited(tag)
38int *tag;
39{
40 char name[84];
41 char *ptr;
42
43 if(dis_get_client(name))
44 printf("Client %s (%d) exited\n", name, *tag);
45 else
46 printf("Client %d exited\n", *tag);
47}
48
49void exit_cmnd(code)
50int *code;
51{
52 printf("Exit_cmnd %d\n", *code);
53 exit(*code);
54}
55
56main(argc,argv)
57int argc;
58char **argv;
59{
60 int i, j, id, *ptr;
61 char aux[80];
62 char name[84], *ptrc;
63 int big_ids[20];
64 int index = 0;
65 char straux[128];
66 void update_services();
67
68 dis_add_exit_handler(exit_cmnd);
69 dis_add_client_exit_handler(client_exited);
70 for(i = 0; i< 10; i++)
71 {
72 sprintf(str[i],"%s/Service_%03d",argv[1],i);
73 dis_add_service( str[i], "C", str[i], strlen(str[i])+1,
74 (void *)0, 0 );
75 }
76 t.i = 123;
77 t.j = 123;
78 t.k = 123;
79 t.d = 56.78;
80 t.s = 12;
81 t.t = 12;
82 t.c = 'a';
83 t.f = 4.56;
84 ptr = (int *)&t;
85 strcpy(t.str,"hello world");
86/*
87 sprintf(aux,"%s/TEST_SWAP",argv[1]);
88 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
89 (void *)0, 0 );
90
91 sprintf(aux,"%s/TEST_CMD",argv[1]);
92 dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0);
93*/
94/*
95 big_buff[0] = 1;
96 for(i = 0; i < 20; i++)
97 {
98 sprintf(aux,"%s/TestMem_%d",argv[1], i);
99 big_ids[i] = dis_add_service( aux, "I", big_buff, 1024*sizeof(int),
100 (void *)0, 0 );
101 }
102*/
103 for(i = 0; i< 100000; i++)
104 {
105 ServMany[i] = i;
106 sprintf(straux,"%s/ServiceMany%05d",argv[1],i);
107 ServManyIds[i] = dis_add_service( straux, "D", &ServMany[i], sizeof(double),
108 (void *)0, 0 );
109 }
110 dis_start_serving( argv[1] );
111 if(dis_get_client(name))
112 {
113 printf("client %s\n",name);
114 }
115
116 dtq_start_timer(30, update_services, 0);
117
118 while(1)
119 {
120/*
121 for(i = 0; i < 20; i++)
122 {
123 index++;
124 big_buff[0] = index;
125 dis_update_service(big_ids[i]);
126 }
127 sleep(1);
128*/
129 pause();
130/*
131 sleep(30);
132 update_services();
133*/
134 }
135}
136
137void update_services()
138{
139 int i;
140
141 dtq_start_timer(20, update_services, 0);
142
143 dim_print_date_time();
144printf("Start updating\n");
145 for(i = 0; i< 100000; i++)
146 {
147 ServMany[i] = ServMany[i]+1;
148 dis_update_service(ServManyIds[i]);
149 if(i == 10000)
150 {
151 int aux;
152 aux = ServMany[i];
153 ServMany[i] = 123;
154 dis_update_service(ServManyIds[i]);
155 ServMany[i] = aux;
156 }
157 }
158dim_print_date_time();
159printf("Stop updating\n");
160}
161
Note: See TracBrowser for help on using the repository browser.