FACT++  1.0
test_server.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dis.h>
5 
6 char str[10][80];
7 
8 typedef 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 
20 TT t;
21 
22 
23 int big_buff[1024];
24 
25 
26 void cmnd_rout(int *tag, TT *buf, int *size)
27 {
28 
29  if(tag){}
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 
37 void 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 
47 void exit_cmnd(int *code)
48 {
49  printf("Exit_cmnd %d\n", *code);
50  exit(*code);
51 }
52 
53 int NewData;
54 int NewIds[11];
55 
56 int more_ids[1024];
58 char more_str[1024][80];
59 
60 /*
61 int atlas_ids[210];
62 float atlas_arr[10];
63 */
64 int 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 /*
83 dis_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();
104 printf("socket buffer size = %d, after = %d\n",buf_sz, buf_sz1);
105 */
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 );
199 printf("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  {
211 printf("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  {
224 printf("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 
void cmnd_rout(int *tag, TT *buf, int *size)
Definition: test_server.c:26
TT t
Definition: test_server.c:20
char str[20]
Definition: test_client.c:23
float f
Definition: test_client.c:22
char str[10][80]
Definition: test_server.c:6
int NewIds[11]
Definition: test_server.c:54
dim_long dis_add_dns(char *node_name, int port_number)
Definition: open_dns.c:237
int i
Definition: db_dim_client.c:21
dim_get_env_var("EXTRA_DNS_NODE", extra_dns, sizeof(extra_dns))
Definition: test_client.c:14
void exit_cmnd(int *code)
Definition: test_server.c:47
int NewData
Definition: test_server.c:53
short s
Definition: test_client.c:19
#define dis_add_cmnd
Definition: dis.h:13
void client_exited(int *tag)
Definition: test_server.c:37
int big_buff[1024]
Definition: test_server.c:23
#define dis_start_serving
Definition: dis.h:8
long dim_long
Definition: dim_common.h:57
char c
Definition: test_client.c:20
int i
Definition: test_client.c:15
short t
Definition: test_client.c:21
int j
Definition: test_client.c:16
#define dis_get_client
Definition: dis.h:11
int size
Definition: db_dim_server.c:17
char more_str[1024][80]
Definition: test_server.c:58
char extra_dns[128]
Definition: README_v19.txt:369
int k
Definition: test_client.c:17
int curr_more_index
Definition: test_server.c:57
double d
Definition: test_client.c:18
#define dis_add_service
Definition: dis.h:12
void dim_print_date_time()
Definition: utilities.c:134
#define dis_add_exit_handler
Definition: dis.h:15
#define dis_add_client_exit_handler
Definition: dis.h:14
int more_ids[1024]
Definition: test_server.c:56
dnsid
Definition: README_v19.txt:372
sprintf(name1,"NewService%d", i)
int main(int argc, char **argv)
Definition: test_server.c:64