source: branches/FACT++_part_filenames/dim/src/examples/test_server.c@ 19365

Last change on this file since 19365 was 15282, checked in by tbretz, 12 years ago
Updated to v20r7.
File size: 4.2 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/*
70 int on = 0;
71*/
72 dim_long dnsid = 0;
73 char extra_dns[128];
74 int new_dns = 0;
75 int index = 0;
76/*
77 dim_set_write_timeout(1);
78*/
79/*
80 int buf_sz, buf_sz1;
81*/
82/*
83dis_set_debug_on();
84*/
85/*
86 int status;
87 regex_t re;
88
89 if(regcomp(&re, "abc*",REG_EXTENDED|REG_NOSUB) != 0)
90 printf("regcomp error\n");
91 status = regexec(&re,"abcdef", (size_t)0, NULL, 0);
92 regfree(&re);
93 printf("result = %d\n", status);
94*/
95 if(argc){}
96 new_dns = dim_get_env_var("EXTRA_DNS_NODE", extra_dns, sizeof(extra_dns));
97 if(new_dns)
98 dnsid = dis_add_dns(extra_dns,0);
99 if(dnsid){}
100/*
101 buf_sz = dim_get_write_buffer_size();
102 dim_set_write_buffer_size(10000000);
103 buf_sz1 = dim_get_write_buffer_size();
104printf("socket buffer size = %d, after = %d\n",buf_sz, buf_sz1);
105*/
106 dis_add_exit_handler(exit_cmnd);
107 dis_add_client_exit_handler(client_exited);
108
109 for(i = 0; i< 10; i++)
110 {
111 sprintf(str[i],"%s/Service_%03d",argv[1],i);
112 dis_add_service( str[i], "C", str[i], (int)strlen(str[i])+1,
113 (void *)0, 0 );
114 }
115 t.i = 123;
116 t.j = 456;
117 t.k = 789;
118 t.d = 56.78;
119 t.s = 12;
120 t.t = 12;
121 t.c = 'a';
122 t.f = (float)4.56;
123 strcpy(t.str,"hello world");
124
125 sprintf(aux,"%s/TEST_SWAP",argv[1]);
126 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t),
127 (void *)0, 0 );
128 if(id){}
129 sprintf(aux,"%s/TEST_CMD",argv[1]);
130 dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0);
131
132/*
133 big_buff[0] = 1;
134 for(i = 0; i < 20; i++)
135 {
136 sprintf(aux,"%s/TestMem_%d",argv[1], i);
137 big_ids[i] = dis_add_service( aux, "I", big_buff, 1024*sizeof(int),
138 (void *)0, 0 );
139 }
140*/
141
142/*
143 for(i = 1; i <= 200; i++)
144 {
145 sprintf(aux,"%s/ATLAS_Service%d",argv[1],i);
146 atlas_ids[i] = dis_add_service( aux, "F", atlas_arr, 10*sizeof(float),
147 (void *)0, 0 );
148 }
149*/
150 dis_start_serving( argv[1] );
151
152 if(dis_get_client(name))
153 {
154 printf("client %s\n",name);
155 }
156/*
157 for(i = 0; i < 5; i++)
158 {
159 sleep(10);
160
161 }
162 dis_stop_serving();
163 sleep(59);
164*/
165 while(1)
166 {
167 index++;
168/*
169 for(i = 0; i < 20; i++)
170 {
171 index++;
172 big_buff[0] = index;
173 dis_update_service(big_ids[i]);
174 }
175 sleep(1);
176*/
177/*
178 pause();
179 */
180 sleep(10);
181/*
182 dis_update_service(id);
183*/
184/*
185 for(i = 1; i <= 200; i++)
186 {
187 dis_update_service(atlas_ids[i]);
188 }
189*/
190/*
191 if(curr_more_index < 1000)
192 {
193 for(i = 1; i <= 10; i++)
194 {
195 sprintf(more_str[curr_more_index],"%s/More_Service_%03d",argv[1],curr_more_index);
196 more_ids[curr_more_index] = dis_add_service( more_str[curr_more_index], "C",
197 more_str[curr_more_index], (int)strlen(more_str[curr_more_index])+1,
198 (void *)0, 0 );
199printf("Adding service %s\n",more_str[curr_more_index]);
200 curr_more_index++;
201 dis_start_serving(argv[1]);
202 dis_start_serving(argv[1]);
203 }
204 }
205*/
206 /*
207 if(new_dns)
208 {
209 if(!on)
210 {
211printf("Connecting New DNS \n");
212 for(i = 0; i < 10; i++)
213 {
214 sprintf(name1,"NewService%d",i);
215 NewIds[i] = dis_add_service_dns(dnsid, name1, "i", &NewData, sizeof(NewData),
216 (void *)0, 0 );
217 }
218 NewIds[10] = 0;
219 dis_start_serving_dns(dnsid, "xx_new");
220 on = 1;
221 }
222 else
223 {
224printf("DisConnecting New DNS \n");
225 for(i = 0; i < 10; i++)
226 {
227 dis_remove_service(NewIds[i]);
228 }
229 on = 0;
230 }
231 }
232 */
233 }
234 return 1;
235}
236
Note: See TracBrowser for help on using the repository browser.