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

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