source: trunk/FACT++/dim/src/examples/test_server.c

Last change on this file was 18920, checked in by tbretz, 7 years ago
Updated to v20r20 - This also includes some minor fixes, I requested.
File size: 4.5 KB
Line 
1#include <string.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include <dis.h>
5
6char str[10][80];
7
8typedef struct {
9 int i;
10 int j;
11 int k;
12 double d;
13 short s;
14 char c;
15 short t;
16 float f;
17 char str[20];
18}TT;
19
20TT t;
21
22
23int big_buff[1024];
24
25
26void cmnd_rout(int *tag, TT *buf, int *size)
27{
28
29 if(tag){}
30 dim_print_date_time();
31 printf("Command received, size = %d, TT size = %d:\n", *size,
32 (int)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(int *tag)
38{
39 char name[84];
40
41 if(dis_get_client(name))
42 printf("Client %s (%d) exited\n", name, *tag);
43 else
44 printf("Client %d exited\n", *tag);
45}
46
47void exit_cmnd(int *code)
48{
49 printf("Exit_cmnd %d\n", *code);
50 exit(*code);
51}
52
53int NewData;
54int NewIds[11];
55
56int more_ids[1024];
57int curr_more_index = 0;
58char more_str[1024][80];
59
60/*
61int atlas_ids[210];
62float atlas_arr[10];
63*/
64int main(int argc, char **argv)
65{
66 int i, id/*, big_ids[20]*/;
67 char aux[80];
68 char name[84]/*, name1[132]*/;
69 char srvname[64];
70/*
71 int on = 0;
72*/
73 dim_long dnsid = 0;
74 char extra_dns[128];
75 int new_dns = 0;
76 int index = 0;
77/*
78 dim_set_write_timeout(1);
79*/
80/*
81 int buf_sz, buf_sz1;
82*/
83/*
84dis_set_debug_on();
85*/
86/*
87 int status;
88 regex_t re;
89
90 if(regcomp(&re, "abc*",REG_EXTENDED|REG_NOSUB) != 0)
91 printf("regcomp error\n");
92 status = regexec(&re,"abcdef", (size_t)0, NULL, 0);
93 regfree(&re);
94 printf("result = %d\n", status);
95*/
96 dim_print_date_time();
97 printf("Dim Server Starting up...\n");
98 fflush(stdout);
99 if(argc){}
100 new_dns = dim_get_env_var("EXTRA_DNS_NODE", extra_dns, sizeof(extra_dns));
101 if(new_dns)
102 dnsid = dis_add_dns(extra_dns,0);
103 if(dnsid){}
104/*
105 buf_sz = dim_get_write_buffer_size();
106 dim_set_write_buffer_size(10000000);
107 buf_sz1 = dim_get_write_buffer_size();
108printf("socket buffer size = %d, after = %d\n",buf_sz, buf_sz1);
109*/
110 dis_add_exit_handler(exit_cmnd);
111 dis_add_client_exit_handler(client_exited);
112
113 strcpy(srvname, argv[1]);
114 if(!strcmp(srvname,"xx1"))
115 strcpy(srvname,"xx");
116 for(i = 0; i< 10; i++)
117 {
118 sprintf(str[i],"%s/Service_%03d",srvname,i);
119 dis_add_service( str[i], "C", str[i], (int)strlen(str[i])+1,
120 (void *)0, 0 );
121 }
122 t.i = 123;
123 t.j = 456;
124 t.k = 789;
125 t.d = 56.78;
126 t.s = 12;
127 t.t = 12;
128 t.c = 'a';
129 t.f = (float)4.56;
130 strcpy(t.str,"hello world");
131
132 sprintf(aux,"%s/TEST_SWAP",srvname);
133 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
134 (void *)0, 0 );
135 if(!strcmp(argv[1],"xx1"))
136 {
137 sprintf(aux,"%s/TEST_SWAP1",srvname);
138 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
139 (void *)0, 0 );
140 }
141 if(id){}
142 sprintf(aux,"%s/TEST_CMD",srvname);
143 dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0);
144
145/*
146 big_buff[0] = 1;
147 for(i = 0; i < 20; i++)
148 {
149 sprintf(aux,"%s/TestMem_%d",argv[1], i);
150 big_ids[i] = dis_add_service( aux, "I", big_buff, 1024*sizeof(int),
151 (void *)0, 0 );
152 }
153*/
154
155/*
156 for(i = 1; i <= 200; i++)
157 {
158 sprintf(aux,"%s/ATLAS_Service%d",argv[1],i);
159 atlas_ids[i] = dis_add_service( aux, "F", atlas_arr, 10*sizeof(float),
160 (void *)0, 0 );
161 }
162*/
163 dis_start_serving( argv[1] );
164
165 if(dis_get_client(name))
166 {
167 printf("client %s\n",name);
168 }
169/*
170 for(i = 0; i < 5; i++)
171 {
172 sleep(10);
173
174 }
175 dis_stop_serving();
176 sleep(59);
177*/
178 while(1)
179 {
180 index++;
181/*
182 for(i = 0; i < 20; i++)
183 {
184 index++;
185 big_buff[0] = index;
186 dis_update_service(big_ids[i]);
187 }
188 sleep(1);
189*/
190/*
191 pause();
192 */
193 sleep(10);
194/*
195 dis_update_service(id);
196*/
197/*
198 for(i = 1; i <= 200; i++)
199 {
200 dis_update_service(atlas_ids[i]);
201 }
202*/
203/*
204 if(curr_more_index < 1000)
205 {
206 for(i = 1; i <= 10; i++)
207 {
208 sprintf(more_str[curr_more_index],"%s/More_Service_%03d",argv[1],curr_more_index);
209 more_ids[curr_more_index] = dis_add_service( more_str[curr_more_index], "C",
210 more_str[curr_more_index], (int)strlen(more_str[curr_more_index])+1,
211 (void *)0, 0 );
212printf("Adding service %s\n",more_str[curr_more_index]);
213 curr_more_index++;
214 dis_start_serving(argv[1]);
215 dis_start_serving(argv[1]);
216 }
217 }
218*/
219 /*
220 if(new_dns)
221 {
222 if(!on)
223 {
224printf("Connecting New DNS \n");
225 for(i = 0; i < 10; i++)
226 {
227 sprintf(name1,"NewService%d",i);
228 NewIds[i] = dis_add_service_dns(dnsid, name1, "i", &NewData, sizeof(NewData),
229 (void *)0, 0 );
230 }
231 NewIds[10] = 0;
232 dis_start_serving_dns(dnsid, "xx_new");
233 on = 1;
234 }
235 else
236 {
237printf("DisConnecting New DNS \n");
238 for(i = 0; i < 10; i++)
239 {
240 dis_remove_service(NewIds[i]);
241 }
242 on = 0;
243 }
244 }
245 */
246 }
247 return 1;
248}
249
Note: See TracBrowser for help on using the repository browser.