1 |
|
---|
2 | /*
|
---|
3 | * DIC (Delphi Information Client) Package implements a library of
|
---|
4 | * routines to be used by clients.
|
---|
5 | *
|
---|
6 | * Started on : 10-11-91
|
---|
7 | * Last modification : 10-08-94
|
---|
8 | * Written by : C. Gaspar
|
---|
9 | * Adjusted by : G.C. Ballintijn
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifdef VMS
|
---|
14 | # include <cfortran.h>
|
---|
15 | # include <assert.h>
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | #define DIMLIB
|
---|
19 | #include <dim.h>
|
---|
20 | #include <dic.h>
|
---|
21 |
|
---|
22 | /*
|
---|
23 | #define DEBUG
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifdef VMS
|
---|
27 | #define TMP_ENABLE_AST long int ast_enable = sys$setast(1);
|
---|
28 | #define TMP_DISABLE_AST if (ast_enable != SS$_WASSET) sys$setast(0);
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #define BAD_CONN_TIMEOUT 2
|
---|
32 |
|
---|
33 |
|
---|
34 | typedef struct bad_conn {
|
---|
35 | struct bad_conn *next;
|
---|
36 | struct bad_conn *prev;
|
---|
37 | DIC_CONNECTION conn;
|
---|
38 | int n_retries;
|
---|
39 | int retrying;
|
---|
40 | } DIC_BAD_CONNECTION;
|
---|
41 |
|
---|
42 | static DIC_SERVICE *Service_pend_head = 0;
|
---|
43 | static DIC_SERVICE *Cmnd_head = 0;
|
---|
44 | static DIC_SERVICE *Current_server = 0;
|
---|
45 | static DIC_BAD_CONNECTION *Bad_connection_head = 0;
|
---|
46 | static int Dic_timer_q = 0;
|
---|
47 | static int Dns_dic_conn_id = 0;
|
---|
48 | static TIMR_ENT *Dns_dic_timr = NULL;
|
---|
49 | static int Tmout_max = 0;
|
---|
50 | static int Tmout_min = 0;
|
---|
51 | static int Threads_off = 0;
|
---|
52 |
|
---|
53 | static void (*Error_user_routine)() = 0;
|
---|
54 | static int Error_conn_id = 0;
|
---|
55 | static int Curr_conn_id = 0;
|
---|
56 |
|
---|
57 | #ifdef DEBUG
|
---|
58 | static int Debug_on = 1;
|
---|
59 | #else
|
---|
60 | static int Debug_on = 0;
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | _DIM_PROTO( unsigned request_service, (char *service_name, int req_type,
|
---|
64 | int req_timeout, void *service_address,
|
---|
65 | int service_size, void (*usr_routine)(void*,void*,int*),
|
---|
66 | dim_long tag, void *fill_addr, int fill_size, int stamped) );
|
---|
67 | _DIM_PROTO( int request_command, (char *service_name, void *service_address,
|
---|
68 | int service_size, void (*usr_routine)(void*,int*),
|
---|
69 | dim_long tag, int stamped) );
|
---|
70 | _DIM_PROTO( DIC_SERVICE *insert_service, (int type, int timeout, char *name,
|
---|
71 | int *address, int size, void (*routine)(),
|
---|
72 | dim_long tag, int *fill_addr, int fill_size,
|
---|
73 | int pending, int stamped ) );
|
---|
74 | _DIM_PROTO( void modify_service, (DIC_SERVICE *servp, int timeout,
|
---|
75 | int *address, int size, void (*routine)(),
|
---|
76 | dim_long tag, int *fill_addr, int fill_size, int stamped) );
|
---|
77 | _DIM_PROTO( DIC_SERVICE *locate_command, (char *serv_name) );
|
---|
78 | _DIM_PROTO( DIC_SERVICE *locate_pending, (char *serv_name) );
|
---|
79 | _DIM_PROTO( DIC_BAD_CONNECTION *locate_bad, (char *node, char *task, int port) );
|
---|
80 | _DIM_PROTO( void service_tmout, (int serv_id) );
|
---|
81 | _DIM_PROTO( static void request_dns_info, (int retry) );
|
---|
82 | _DIM_PROTO( static int handle_dns_info, (DNS_DIC_PACKET *) );
|
---|
83 | _DIM_PROTO( void close_dns_conn, (void) );
|
---|
84 | _DIM_PROTO( static void release_conn, (int conn_id) );
|
---|
85 | _DIM_PROTO( static void get_format_data, (int format, FORMAT_STR *format_data,
|
---|
86 | char *def) );
|
---|
87 | _DIM_PROTO( static void execute_service, (DIS_PACKET *packet,
|
---|
88 | DIC_SERVICE *servp, int size) );
|
---|
89 |
|
---|
90 | void print_packet(DIS_PACKET *packet)
|
---|
91 | {
|
---|
92 | dim_print_date_time();
|
---|
93 | printf("Bad ID received from server -> Packet received:\n");
|
---|
94 | printf("\tpacket->size = %d\n",vtohl(packet->size));
|
---|
95 | printf("\tpacket->service_id = %d\n",vtohl(packet->service_id));
|
---|
96 | }
|
---|
97 |
|
---|
98 | void dic_set_debug_on()
|
---|
99 | {
|
---|
100 | Debug_on = 1;
|
---|
101 | }
|
---|
102 |
|
---|
103 | void dic_set_debug_off()
|
---|
104 | {
|
---|
105 | Debug_on = 0;
|
---|
106 | }
|
---|
107 |
|
---|
108 | void dic_no_threads()
|
---|
109 | {
|
---|
110 | Threads_off = 1;
|
---|
111 | }
|
---|
112 |
|
---|
113 | void dic_add_error_handler( void (*user_routine)())
|
---|
114 | {
|
---|
115 |
|
---|
116 | DISABLE_AST
|
---|
117 | Error_user_routine = user_routine;
|
---|
118 | ENABLE_AST
|
---|
119 | }
|
---|
120 |
|
---|
121 | static void error_handler(int conn_id, int severity, int errcode, char *reason)
|
---|
122 | {
|
---|
123 | int last_conn_id;
|
---|
124 |
|
---|
125 | if(Error_user_routine)
|
---|
126 | {
|
---|
127 | Error_conn_id = conn_id;
|
---|
128 | last_conn_id = Curr_conn_id;
|
---|
129 | (Error_user_routine)(severity, errcode, reason);
|
---|
130 | Error_conn_id = 0;
|
---|
131 | Curr_conn_id = last_conn_id;
|
---|
132 | }
|
---|
133 | else
|
---|
134 | {
|
---|
135 | dim_print_msg(reason, severity);
|
---|
136 | if(severity == 3)
|
---|
137 | {
|
---|
138 | printf("Exiting!\n");
|
---|
139 | exit(2);
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | static void recv_rout( int conn_id, DIS_PACKET *packet, int size, int status )
|
---|
145 | {
|
---|
146 | register DIC_SERVICE *servp, *auxp;
|
---|
147 | register DIC_CONNECTION *dic_connp;
|
---|
148 | int service_id, once_only, found = 0;
|
---|
149 | char node[MAX_NODE_NAME], task[MAX_TASK_NAME];
|
---|
150 | void move_to_notok_service();
|
---|
151 | void do_cmnd_callback();
|
---|
152 | void dim_panic(char *);
|
---|
153 |
|
---|
154 | dic_connp = &Dic_conns[conn_id] ;
|
---|
155 | switch( status )
|
---|
156 | {
|
---|
157 | case STA_DISC:
|
---|
158 | if(Debug_on)
|
---|
159 | {
|
---|
160 | dna_get_node_task(conn_id, node, task);
|
---|
161 | dim_print_date_time();
|
---|
162 | printf("Conn %d: Server %s on node %s Disconnected\n",
|
---|
163 | conn_id, task, node);
|
---|
164 | fflush(stdout);
|
---|
165 | }
|
---|
166 | if( !(servp = (DIC_SERVICE *) dic_connp->service_head) )
|
---|
167 | {
|
---|
168 | release_conn( conn_id );
|
---|
169 | break;
|
---|
170 | }
|
---|
171 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
172 | (DLL *) dic_connp->service_head,
|
---|
173 | (DLL *) servp)) )
|
---|
174 | {
|
---|
175 | #ifdef DEBUG
|
---|
176 | printf("\t %s was in the service list\n",servp->serv_name);
|
---|
177 | fflush(stdout);
|
---|
178 | #endif
|
---|
179 | /*
|
---|
180 | Will be done later by the DNS answer
|
---|
181 | service_tmout( servp->serv_id );
|
---|
182 | */
|
---|
183 | if(!strcmp(dic_connp->task_name,"DIS_DNS"))
|
---|
184 | {
|
---|
185 | service_tmout( servp->serv_id );
|
---|
186 | }
|
---|
187 | else if(Dns_dic_conn_id <= 0)
|
---|
188 | {
|
---|
189 | service_tmout( servp->serv_id );
|
---|
190 | }
|
---|
191 | /*
|
---|
192 | servp->pending = WAITING_DNS_UP;
|
---|
193 | servp->conn_id = 0;
|
---|
194 | */
|
---|
195 | auxp = servp->prev;
|
---|
196 | move_to_notok_service( servp );
|
---|
197 | servp = auxp;
|
---|
198 | }
|
---|
199 | if( (servp = (DIC_SERVICE *) Cmnd_head) )
|
---|
200 | {
|
---|
201 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
202 | (DLL *) Cmnd_head,
|
---|
203 | (DLL *) servp)) )
|
---|
204 | {
|
---|
205 | if( servp->conn_id == conn_id )
|
---|
206 | {
|
---|
207 | #ifdef DEBUG
|
---|
208 | printf("\t%s was in the Command list\n", servp->serv_name);
|
---|
209 | printf("servp = %x, type = %d, pending = %d\n",servp, servp->type, servp->pending);
|
---|
210 | fflush(stdout);
|
---|
211 | #endif
|
---|
212 | auxp = servp->prev;
|
---|
213 | if( (servp->type == ONCE_ONLY ) &&
|
---|
214 | (servp->pending == WAITING_SERVER_UP))
|
---|
215 | {
|
---|
216 | service_tmout( servp->serv_id );
|
---|
217 | }
|
---|
218 | else if( (servp->type == COMMAND ) &&
|
---|
219 | (servp->pending == WAITING_CMND_ANSWER))
|
---|
220 | {
|
---|
221 | service_tmout( servp->serv_id );
|
---|
222 | }
|
---|
223 | else
|
---|
224 | {
|
---|
225 | servp->pending = WAITING_DNS_UP;
|
---|
226 | dic_release_service( servp->serv_id );
|
---|
227 | }
|
---|
228 | servp = auxp;
|
---|
229 | }
|
---|
230 | }
|
---|
231 | }
|
---|
232 | release_conn( conn_id );
|
---|
233 | request_dns_info(0);
|
---|
234 | break;
|
---|
235 | case STA_DATA:
|
---|
236 | if( !(DIC_SERVICE *) dic_connp->service_head )
|
---|
237 | break;
|
---|
238 | service_id = vtohl(packet->service_id);
|
---|
239 | if(service_id & 0x80000000) /* Service removed by server */
|
---|
240 | {
|
---|
241 | service_id &= 0x7fffffff;
|
---|
242 | if( (servp = (DIC_SERVICE *) id_get_ptr(service_id, SRC_DIC)))
|
---|
243 | {
|
---|
244 | if( servp->type != COMMAND )
|
---|
245 | {
|
---|
246 | service_tmout( servp->serv_id );
|
---|
247 | /*
|
---|
248 | servp->pending = WAITING_DNS_UP;
|
---|
249 | servp->conn_id = 0;
|
---|
250 | */
|
---|
251 | move_to_notok_service( servp );
|
---|
252 | }
|
---|
253 | else
|
---|
254 | {
|
---|
255 | service_tmout( servp->serv_id );
|
---|
256 | break;
|
---|
257 | }
|
---|
258 | }
|
---|
259 | else
|
---|
260 | {
|
---|
261 | /*
|
---|
262 | print_packet(packet);
|
---|
263 | */
|
---|
264 | if( (servp = (DIC_SERVICE *) Cmnd_head) )
|
---|
265 | {
|
---|
266 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
267 | (DLL *) Cmnd_head,
|
---|
268 | (DLL *) servp)) )
|
---|
269 | {
|
---|
270 | if( servp->conn_id == conn_id )
|
---|
271 | {
|
---|
272 | #ifdef DEBUG
|
---|
273 | printf("\t%s was in the Command list\n", servp->serv_name);
|
---|
274 | fflush(stdout);
|
---|
275 | #endif
|
---|
276 | auxp = servp->prev;
|
---|
277 | if( (servp->type == ONCE_ONLY ) &&
|
---|
278 | (servp->pending == WAITING_SERVER_UP))
|
---|
279 | {
|
---|
280 | service_tmout( servp->serv_id );
|
---|
281 | }
|
---|
282 | else if( (servp->type == COMMAND ) &&
|
---|
283 | (servp->pending == WAITING_CMND_ANSWER))
|
---|
284 | {
|
---|
285 | service_tmout( servp->serv_id );
|
---|
286 | }
|
---|
287 | else
|
---|
288 | {
|
---|
289 | servp->pending = WAITING_DNS_UP;
|
---|
290 | dic_release_service( servp->serv_id );
|
---|
291 | }
|
---|
292 | servp = auxp;
|
---|
293 | }
|
---|
294 | }
|
---|
295 | }
|
---|
296 | }
|
---|
297 | if( dll_empty((DLL *)dic_connp->service_head) ) {
|
---|
298 | if( (servp = (DIC_SERVICE *) Cmnd_head) ) {
|
---|
299 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
300 | (DLL *) Cmnd_head,
|
---|
301 | (DLL *) servp)) )
|
---|
302 | {
|
---|
303 | if( servp->conn_id == conn_id)
|
---|
304 | found = 1;
|
---|
305 | }
|
---|
306 | }
|
---|
307 | if( !found)
|
---|
308 | {
|
---|
309 | release_conn( conn_id );
|
---|
310 | }
|
---|
311 | }
|
---|
312 | request_dns_info(0);
|
---|
313 | break;
|
---|
314 | }
|
---|
315 | if( (servp = (DIC_SERVICE *) id_get_ptr(service_id, SRC_DIC)))
|
---|
316 | {
|
---|
317 | if(servp->serv_id == service_id)
|
---|
318 | {
|
---|
319 | once_only = 0;
|
---|
320 | if(servp->type == ONCE_ONLY)
|
---|
321 | once_only = 1;
|
---|
322 | else
|
---|
323 | {
|
---|
324 | if( servp->timeout > 0 )
|
---|
325 | {
|
---|
326 | if(servp->timer_ent)
|
---|
327 | dtq_clear_entry( servp->timer_ent );
|
---|
328 | }
|
---|
329 | }
|
---|
330 | Curr_conn_id = conn_id;
|
---|
331 | execute_service(packet, servp, size);
|
---|
332 | Curr_conn_id = 0;
|
---|
333 | if( once_only )
|
---|
334 | {
|
---|
335 | auxp = locate_command(servp->serv_name);
|
---|
336 | if((auxp) && (auxp != servp))
|
---|
337 | {
|
---|
338 | servp->pending = WAITING_DNS_UP;
|
---|
339 | dic_release_service( servp->serv_id );
|
---|
340 | }
|
---|
341 | else
|
---|
342 | {
|
---|
343 | servp->pending = NOT_PENDING;
|
---|
344 | servp->tmout_done = 0;
|
---|
345 | if( servp->timer_ent )
|
---|
346 | {
|
---|
347 | dtq_rem_entry( Dic_timer_q, servp->timer_ent );
|
---|
348 | servp->timer_ent = 0;
|
---|
349 | }
|
---|
350 | }
|
---|
351 | }
|
---|
352 | }
|
---|
353 | }
|
---|
354 | /*
|
---|
355 | else
|
---|
356 | {
|
---|
357 | print_packet(packet);
|
---|
358 | if(Error_user_routine)
|
---|
359 | (Error_user_routine)( packet->buffer );
|
---|
360 | }
|
---|
361 | */
|
---|
362 | break;
|
---|
363 | case STA_CONN:
|
---|
364 | if(Debug_on)
|
---|
365 | {
|
---|
366 | dna_get_node_task(conn_id, node, task);
|
---|
367 | dim_print_date_time();
|
---|
368 | printf("Conn %d: Server %s on node %s Connected\n",
|
---|
369 | conn_id, task, node);
|
---|
370 | fflush(stdout);
|
---|
371 | }
|
---|
372 | break;
|
---|
373 | default: dim_panic( "recv_rout(): Bad switch" );
|
---|
374 | }
|
---|
375 | }
|
---|
376 |
|
---|
377 | static void execute_service(DIS_PACKET *packet, DIC_SERVICE *servp, int size)
|
---|
378 | {
|
---|
379 | int format;
|
---|
380 | FORMAT_STR format_data_cp[MAX_NAME/4], *formatp;
|
---|
381 | static int *buffer;
|
---|
382 | static int buffer_size = 0;
|
---|
383 | int add_size;
|
---|
384 | int *pkt_buffer, header_size;
|
---|
385 |
|
---|
386 | Current_server = servp;
|
---|
387 | format = servp->format;
|
---|
388 | memcpy(format_data_cp, servp->format_data, sizeof(format_data_cp));
|
---|
389 | if((format & 0xF) == ((MY_FORMAT) & 0xF))
|
---|
390 | {
|
---|
391 | for(formatp = format_data_cp; formatp->par_bytes; formatp++)
|
---|
392 | formatp->flags &= 0xFFF0; /* NOSWAP */
|
---|
393 | }
|
---|
394 | if( servp->stamped)
|
---|
395 | {
|
---|
396 | pkt_buffer = ((DIS_STAMPED_PACKET *)packet)->buffer;
|
---|
397 | header_size = DIS_STAMPED_HEADER;
|
---|
398 | servp->time_stamp[0] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[0]);
|
---|
399 | if((servp->time_stamp[0] & 0xFFFF0000) == 0xc0de0000)
|
---|
400 | {
|
---|
401 | /*
|
---|
402 | servp->time_stamp[0] &= 0x0000FFFF;
|
---|
403 | */
|
---|
404 | servp->time_stamp[1] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[1]);
|
---|
405 | servp->quality = vtohl(((DIS_STAMPED_PACKET *)packet)->quality);
|
---|
406 | }
|
---|
407 | else if((vtohl(((DIS_STAMPED_PACKET *)packet)->reserved[0])) == (int)0xc0dec0de)
|
---|
408 | {
|
---|
409 | /*
|
---|
410 | servp->time_stamp[0] &= 0x0000FFFF;
|
---|
411 | */
|
---|
412 | servp->time_stamp[1] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[1]);
|
---|
413 | servp->quality = vtohl(((DIS_STAMPED_PACKET *)packet)->quality);
|
---|
414 | }
|
---|
415 | else
|
---|
416 | {
|
---|
417 | pkt_buffer = ((DIS_PACKET *)packet)->buffer;
|
---|
418 | header_size = DIS_HEADER;
|
---|
419 | }
|
---|
420 | }
|
---|
421 | else
|
---|
422 | {
|
---|
423 | pkt_buffer = ((DIS_PACKET *)packet)->buffer;
|
---|
424 | header_size = DIS_HEADER;
|
---|
425 | }
|
---|
426 | size -= header_size;
|
---|
427 | if( servp->serv_address )
|
---|
428 | {
|
---|
429 | if( size > servp->serv_size )
|
---|
430 | size = servp->serv_size;
|
---|
431 | add_size = copy_swap_buffer_in(format_data_cp,
|
---|
432 | servp->serv_address,
|
---|
433 | pkt_buffer, size);
|
---|
434 | if( servp->user_routine )
|
---|
435 | (servp->user_routine)(&servp->tag, servp->serv_address, &add_size );
|
---|
436 | }
|
---|
437 | else
|
---|
438 | {
|
---|
439 | if( servp->user_routine )
|
---|
440 | {
|
---|
441 | add_size = size + (size/2);
|
---|
442 | if(!buffer_size)
|
---|
443 | {
|
---|
444 | buffer = (int *)malloc(add_size);
|
---|
445 | buffer_size = add_size;
|
---|
446 | }
|
---|
447 | else
|
---|
448 | {
|
---|
449 | if( add_size > buffer_size )
|
---|
450 | {
|
---|
451 | free(buffer);
|
---|
452 | buffer = (int *)malloc(add_size);
|
---|
453 | buffer_size = add_size;
|
---|
454 | }
|
---|
455 | }
|
---|
456 | add_size = copy_swap_buffer_in(format_data_cp,
|
---|
457 | buffer,
|
---|
458 | pkt_buffer, size);
|
---|
459 | (servp->user_routine)( &servp->tag, buffer, &add_size );
|
---|
460 | }
|
---|
461 | }
|
---|
462 | Current_server = 0;
|
---|
463 | }
|
---|
464 |
|
---|
465 | static void recv_dns_dic_rout( int conn_id, DNS_DIC_PACKET *packet, int size, int status )
|
---|
466 | {
|
---|
467 | register DIC_SERVICE *servp, *auxp;
|
---|
468 | void dim_panic(char *);
|
---|
469 |
|
---|
470 | if(size){}
|
---|
471 | switch( status )
|
---|
472 | {
|
---|
473 | case STA_DISC: /* connection broken */
|
---|
474 | servp = Service_pend_head;
|
---|
475 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
476 | (DLL *) Service_pend_head,
|
---|
477 | (DLL *) servp)) )
|
---|
478 | {
|
---|
479 | if( (servp->pending == WAITING_DNS_ANSWER) ||
|
---|
480 | (servp->pending == WAITING_SERVER_UP))
|
---|
481 | {
|
---|
482 | if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
|
---|
483 | {
|
---|
484 | auxp = servp->prev;
|
---|
485 | servp->pending = WAITING_DNS_UP;
|
---|
486 | service_tmout( servp->serv_id );
|
---|
487 | servp = auxp;
|
---|
488 | }
|
---|
489 | else
|
---|
490 | {
|
---|
491 | servp->pending = WAITING_DNS_UP;
|
---|
492 | }
|
---|
493 | }
|
---|
494 | }
|
---|
495 | dna_close( Dns_dic_conn_id );
|
---|
496 | Dns_dic_conn_id = 0;
|
---|
497 | request_dns_info(0);
|
---|
498 | break;
|
---|
499 | case STA_CONN: /* connection received */
|
---|
500 | if(Dns_dic_conn_id < 0)
|
---|
501 | {
|
---|
502 | Dns_dic_conn_id = conn_id;
|
---|
503 | request_dns_info(0);
|
---|
504 |
|
---|
505 | }
|
---|
506 | break;
|
---|
507 | case STA_DATA: /* normal packet */
|
---|
508 | if( vtohl(packet->size) == DNS_DIC_HEADER )
|
---|
509 | {
|
---|
510 | handle_dns_info( packet );
|
---|
511 | }
|
---|
512 | break;
|
---|
513 | default: dim_panic( "recv_dns_dic_rout(): Bad switch" );
|
---|
514 | }
|
---|
515 | }
|
---|
516 |
|
---|
517 |
|
---|
518 | void service_tmout( int serv_id )
|
---|
519 | {
|
---|
520 | int once_only, size = 0;
|
---|
521 | register DIC_SERVICE *servp;
|
---|
522 |
|
---|
523 | /*
|
---|
524 | dim_print_date_time();
|
---|
525 | printf("In service tmout\n");
|
---|
526 | */
|
---|
527 | servp=(DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
|
---|
528 | if(!servp)
|
---|
529 | return;
|
---|
530 | if(servp->tmout_done)
|
---|
531 | return;
|
---|
532 | /*
|
---|
533 | dim_print_date_time();
|
---|
534 | printf("In service tmout %s\n", servp->serv_name);
|
---|
535 | */
|
---|
536 | servp->tmout_done = 1;
|
---|
537 | Curr_conn_id = servp->conn_id;
|
---|
538 | /*
|
---|
539 | if( servp->type == UPDATE )
|
---|
540 | return;
|
---|
541 | */
|
---|
542 | if( servp->type == COMMAND )
|
---|
543 | {
|
---|
544 | if( servp->user_routine )
|
---|
545 | {
|
---|
546 | if(servp->pending == WAITING_CMND_ANSWER)
|
---|
547 | size = 1;
|
---|
548 | else
|
---|
549 | size = 0;
|
---|
550 | (servp->user_routine)( &servp->tag, &size );
|
---|
551 | }
|
---|
552 | dic_release_service( servp->serv_id );
|
---|
553 | Curr_conn_id = 0;
|
---|
554 | return;
|
---|
555 | }
|
---|
556 | once_only = 0;
|
---|
557 | if(servp->type == ONCE_ONLY)
|
---|
558 | once_only = 1;
|
---|
559 | /*
|
---|
560 | if( servp->fill_address )
|
---|
561 | */
|
---|
562 | if( servp->fill_size >= 0 )
|
---|
563 | {
|
---|
564 | size = servp->fill_size;
|
---|
565 | if( servp->serv_address )
|
---|
566 | {
|
---|
567 | if( size > servp->serv_size )
|
---|
568 | size = servp->serv_size;
|
---|
569 | memcpy(servp->serv_address, servp->fill_address, size);
|
---|
570 | if( servp->user_routine )
|
---|
571 | (servp->user_routine)( &servp->tag, servp->serv_address, &size);
|
---|
572 | }
|
---|
573 | else
|
---|
574 | {
|
---|
575 | if( servp->user_routine )
|
---|
576 | (servp->user_routine)( &servp->tag, servp->fill_address, &size);
|
---|
577 | }
|
---|
578 | }
|
---|
579 | if( once_only )
|
---|
580 | {
|
---|
581 | dic_release_service( servp->serv_id );
|
---|
582 | }
|
---|
583 | Curr_conn_id = 0;
|
---|
584 | }
|
---|
585 |
|
---|
586 |
|
---|
587 | unsigned dic_info_service( char *serv_name, int req_type, int req_timeout, void *serv_address,
|
---|
588 | int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size )
|
---|
589 | {
|
---|
590 | unsigned ret;
|
---|
591 |
|
---|
592 | ret = request_service( serv_name, req_type, req_timeout,
|
---|
593 | serv_address, serv_size, usr_routine, tag,
|
---|
594 | fill_addr, fill_size, 0 );
|
---|
595 |
|
---|
596 | return(ret);
|
---|
597 | }
|
---|
598 |
|
---|
599 | unsigned dic_info_service_stamped( char *serv_name, int req_type, int req_timeout, void *serv_address,
|
---|
600 | int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size )
|
---|
601 | {
|
---|
602 | unsigned ret;
|
---|
603 |
|
---|
604 | ret = request_service( serv_name, req_type, req_timeout,
|
---|
605 | serv_address, serv_size, usr_routine, tag,
|
---|
606 | fill_addr, fill_size, 1 );
|
---|
607 |
|
---|
608 | return(ret);
|
---|
609 | }
|
---|
610 |
|
---|
611 | unsigned request_service( char *serv_name, int req_type, int req_timeout, void *serv_address,
|
---|
612 | int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size, int stamped )
|
---|
613 | {
|
---|
614 | register DIC_SERVICE *servp;
|
---|
615 | int conn_id;
|
---|
616 | int send_service();
|
---|
617 | int locate_service();
|
---|
618 | void dim_init_threads(void);
|
---|
619 |
|
---|
620 | if(!Threads_off)
|
---|
621 | {
|
---|
622 | dim_init_threads();
|
---|
623 | }
|
---|
624 | {
|
---|
625 | DISABLE_AST
|
---|
626 | /* create a timer queue for timeouts if not yet done */
|
---|
627 | if( !Dic_timer_q ) {
|
---|
628 | conn_arr_create( SRC_DIC );
|
---|
629 | Dic_timer_q = dtq_create();
|
---|
630 | }
|
---|
631 |
|
---|
632 | /* store_service */
|
---|
633 | if(req_timeout < 0)
|
---|
634 | req_timeout = 0;
|
---|
635 | if(req_type == ONCE_ONLY)
|
---|
636 | {
|
---|
637 | if( !Cmnd_head ) {
|
---|
638 | Cmnd_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE) );
|
---|
639 | dll_init( (DLL *) Cmnd_head );
|
---|
640 | Cmnd_head->serv_id = 0;
|
---|
641 | }
|
---|
642 | if( (servp = locate_command(serv_name)) )
|
---|
643 | {
|
---|
644 | if( (conn_id = servp->conn_id) )
|
---|
645 | {
|
---|
646 | if(servp->pending == NOT_PENDING)
|
---|
647 | {
|
---|
648 | modify_service( servp, req_timeout,
|
---|
649 | (int *)serv_address, serv_size, usr_routine, tag,
|
---|
650 | (int *)fill_addr, fill_size, stamped);
|
---|
651 | servp->pending = WAITING_SERVER_UP;
|
---|
652 | if(send_service(conn_id, servp))
|
---|
653 | {
|
---|
654 | ENABLE_AST
|
---|
655 | return(1);
|
---|
656 | }
|
---|
657 | }
|
---|
658 | }
|
---|
659 | }
|
---|
660 | }
|
---|
661 | servp = insert_service( req_type, req_timeout,
|
---|
662 | serv_name, (int *)serv_address, serv_size, usr_routine, tag,
|
---|
663 | (int *)fill_addr, fill_size, WAITING_DNS_UP, stamped );
|
---|
664 |
|
---|
665 | /* get_address of server from name_server */
|
---|
666 |
|
---|
667 | if( locate_service(servp) <= 0)
|
---|
668 | {
|
---|
669 | /*
|
---|
670 | service_tmout( servp->serv_id );
|
---|
671 | */
|
---|
672 | dtq_start_timer( 0, service_tmout, servp->serv_id);
|
---|
673 | }
|
---|
674 | ENABLE_AST
|
---|
675 | }
|
---|
676 | return((unsigned) servp->serv_id);
|
---|
677 | }
|
---|
678 |
|
---|
679 |
|
---|
680 | int dic_cmnd_service( char *serv_name, void *serv_address, int serv_size )
|
---|
681 | {
|
---|
682 | int ret;
|
---|
683 |
|
---|
684 | ret = request_command( serv_name, serv_address, serv_size,
|
---|
685 | 0, 0, 0 );
|
---|
686 |
|
---|
687 | return(ret ? 1 : 0);
|
---|
688 |
|
---|
689 | }
|
---|
690 |
|
---|
691 | int dic_cmnd_service_stamped( char *serv_name, void *serv_address, int serv_size )
|
---|
692 | {
|
---|
693 | int ret;
|
---|
694 |
|
---|
695 | ret = request_command( serv_name, serv_address, serv_size,
|
---|
696 | 0, 0, 1 );
|
---|
697 |
|
---|
698 | return(ret ? 1 : 0);
|
---|
699 |
|
---|
700 | }
|
---|
701 |
|
---|
702 | int dic_cmnd_callback( char *serv_name, void *serv_address, int serv_size,
|
---|
703 | void (*usr_routine)(), dim_long tag )
|
---|
704 | {
|
---|
705 | int ret;
|
---|
706 |
|
---|
707 | ret = request_command( serv_name, serv_address, serv_size,
|
---|
708 | usr_routine, tag, 0 );
|
---|
709 | return(ret ? 1 : 0);
|
---|
710 | }
|
---|
711 |
|
---|
712 | int dic_cmnd_callback_stamped( char *serv_name, void *serv_address, int serv_size,
|
---|
713 | void (*usr_routine)(), dim_long tag )
|
---|
714 | {
|
---|
715 | int ret;
|
---|
716 |
|
---|
717 | ret = request_command( serv_name, serv_address, serv_size,
|
---|
718 | usr_routine, tag, 1 );
|
---|
719 | return(ret ? 1 : 0);
|
---|
720 | }
|
---|
721 |
|
---|
722 | int request_command(char *serv_name, void *serv_address, int serv_size,
|
---|
723 | void (*usr_routine)(), dim_long tag, int stamped)
|
---|
724 | {
|
---|
725 | int conn_id, ret;
|
---|
726 | register DIC_SERVICE *servp, *testp;
|
---|
727 | int *fillp;
|
---|
728 | int send_command();
|
---|
729 | int end_command();
|
---|
730 | void dim_init_threads(void);
|
---|
731 | int locate_service();
|
---|
732 |
|
---|
733 | if(!Threads_off)
|
---|
734 | {
|
---|
735 | dim_init_threads();
|
---|
736 | }
|
---|
737 | {
|
---|
738 | DISABLE_AST
|
---|
739 | /* create a timer queue for timeouts if not yet done */
|
---|
740 | if( !Dic_timer_q ) {
|
---|
741 | conn_arr_create( SRC_DIC );
|
---|
742 | Dic_timer_q = dtq_create();
|
---|
743 | }
|
---|
744 |
|
---|
745 | /* store_service */
|
---|
746 | if( !Cmnd_head ) {
|
---|
747 | Cmnd_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE) );
|
---|
748 | dll_init( (DLL *) Cmnd_head );
|
---|
749 | Cmnd_head->serv_id = 0;
|
---|
750 | }
|
---|
751 | if( (servp = locate_command(serv_name)) )
|
---|
752 | {
|
---|
753 | if(!(testp = locate_pending(serv_name)))
|
---|
754 | {
|
---|
755 | if( (conn_id = servp->conn_id) )
|
---|
756 | {
|
---|
757 | if(servp->fill_size > 0)
|
---|
758 | free( servp->fill_address );
|
---|
759 | fillp = serv_address;
|
---|
760 | if(serv_size > 0)
|
---|
761 | {
|
---|
762 | fillp = (int *)malloc(serv_size);
|
---|
763 | memcpy( (char *)fillp, (char *)serv_address, serv_size );
|
---|
764 | }
|
---|
765 | servp->fill_address = fillp;
|
---|
766 | servp->fill_size = serv_size;
|
---|
767 | /*
|
---|
768 | servp->fill_address = (int *)serv_address;
|
---|
769 | servp->fill_size = serv_size;
|
---|
770 | */
|
---|
771 | servp->user_routine = usr_routine;
|
---|
772 | servp->tag = tag;
|
---|
773 | ret = send_command(conn_id, servp);
|
---|
774 | end_command(servp, ret);
|
---|
775 | ENABLE_AST
|
---|
776 | return(1);
|
---|
777 | }
|
---|
778 | }
|
---|
779 | }
|
---|
780 | servp = insert_service( COMMAND, 0,
|
---|
781 | serv_name, 0, 0, usr_routine, tag,
|
---|
782 | (int *)serv_address, serv_size,
|
---|
783 | WAITING_DNS_UP, stamped );
|
---|
784 | if( locate_service(servp) <= 0)
|
---|
785 | {
|
---|
786 | /*
|
---|
787 | service_tmout( servp->serv_id );
|
---|
788 | */
|
---|
789 | dtq_start_timer( 0, service_tmout, servp->serv_id);
|
---|
790 | }
|
---|
791 | ENABLE_AST
|
---|
792 | }
|
---|
793 | return(-1);
|
---|
794 | }
|
---|
795 |
|
---|
796 | DIC_SERVICE *insert_service( int type, int timeout, char *name, int *address, int size,
|
---|
797 | void (*routine)(), dim_long tag, int *fill_addr, int fill_size,
|
---|
798 | int pending, int stamped)
|
---|
799 | {
|
---|
800 | register DIC_SERVICE *newp;
|
---|
801 | int *fillp;
|
---|
802 | int service_id;
|
---|
803 | int tout;
|
---|
804 | float ftout;
|
---|
805 |
|
---|
806 | DISABLE_AST
|
---|
807 | newp = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE));
|
---|
808 | newp->pending = 0;
|
---|
809 | strncpy( newp->serv_name, name, MAX_NAME );
|
---|
810 | newp->type = type;
|
---|
811 | newp->timeout = timeout;
|
---|
812 | newp->serv_address = address;
|
---|
813 | newp->serv_size = size;
|
---|
814 | newp->user_routine = routine;
|
---|
815 | newp->tag = tag;
|
---|
816 | fillp = fill_addr;
|
---|
817 | if(fill_size > 0)
|
---|
818 | {
|
---|
819 | fillp = (int *)malloc(fill_size);
|
---|
820 | memcpy( (char *) fillp, (char *) fill_addr, fill_size );
|
---|
821 | }
|
---|
822 | newp->fill_address = fillp;
|
---|
823 | newp->fill_size = fill_size;
|
---|
824 | newp->conn_id = 0;
|
---|
825 | newp->format_data[0].par_bytes = 0;
|
---|
826 | newp->next = (DIC_SERVICE *)0;
|
---|
827 | service_id = id_get((void *)newp, SRC_DIC);
|
---|
828 | newp->serv_id = service_id;
|
---|
829 | if( !Service_pend_head )
|
---|
830 | {
|
---|
831 | Service_pend_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE));
|
---|
832 | dll_init( (DLL *) Service_pend_head );
|
---|
833 | Service_pend_head->serv_id = 0;
|
---|
834 | }
|
---|
835 | dll_insert_queue( (DLL *) Service_pend_head, (DLL *)newp );
|
---|
836 | newp->timer_ent = NULL;
|
---|
837 | if(type != MONIT_FIRST)
|
---|
838 | {
|
---|
839 | if( timeout )
|
---|
840 | {
|
---|
841 | tout = timeout;
|
---|
842 | if(type != ONCE_ONLY)
|
---|
843 | {
|
---|
844 | if(tout < 10)
|
---|
845 | tout = 10;
|
---|
846 | ftout = (float)tout * (float)1.5;
|
---|
847 | tout = (int)ftout;
|
---|
848 | }
|
---|
849 | newp->curr_timeout = tout;
|
---|
850 | newp->timer_ent = dtq_add_entry( Dic_timer_q,
|
---|
851 | newp->curr_timeout,
|
---|
852 | service_tmout, newp->serv_id );
|
---|
853 | }
|
---|
854 | }
|
---|
855 | newp->pending = pending;
|
---|
856 | newp->tmout_done = 0;
|
---|
857 | newp->stamped = stamped;
|
---|
858 | newp->time_stamp[0] = 0;
|
---|
859 | newp->time_stamp[1] = 0;
|
---|
860 | newp->quality = 0;
|
---|
861 | newp->def[0] = '\0';
|
---|
862 | #ifdef VxWorks
|
---|
863 | newp->tid = taskIdSelf();
|
---|
864 | #endif
|
---|
865 | ENABLE_AST
|
---|
866 | return(newp);
|
---|
867 | }
|
---|
868 |
|
---|
869 |
|
---|
870 | void modify_service( DIC_SERVICE *servp, int timeout, int *address, int size, void (*routine)(),
|
---|
871 | dim_long tag, int *fill_addr, int fill_size, int stamped)
|
---|
872 | {
|
---|
873 | int *fillp;
|
---|
874 |
|
---|
875 | if( servp->timer_ent )
|
---|
876 | {
|
---|
877 | dtq_rem_entry( Dic_timer_q, servp->timer_ent );
|
---|
878 | servp->timer_ent = 0;
|
---|
879 | }
|
---|
880 | servp->timeout = timeout;
|
---|
881 | servp->serv_address = address;
|
---|
882 | servp->serv_size = size;
|
---|
883 | servp->user_routine = routine;
|
---|
884 | servp->tag = tag;
|
---|
885 | if(servp->fill_size > 0)
|
---|
886 | free( servp->fill_address );
|
---|
887 | fillp = fill_addr;
|
---|
888 | if(fill_size > 0)
|
---|
889 | {
|
---|
890 | fillp = (int *)malloc(fill_size);
|
---|
891 | memcpy( (char *) fillp, (char *) fill_addr, fill_size );
|
---|
892 | }
|
---|
893 | servp->fill_address = fillp;
|
---|
894 | servp->fill_size = fill_size;
|
---|
895 | servp->stamped = stamped;
|
---|
896 | if(timeout)
|
---|
897 | {
|
---|
898 | servp->curr_timeout = timeout;
|
---|
899 | servp->timer_ent = dtq_add_entry( Dic_timer_q,
|
---|
900 | servp->curr_timeout,
|
---|
901 | service_tmout, servp->serv_id );
|
---|
902 | }
|
---|
903 | else
|
---|
904 | servp->timer_ent = NULL;
|
---|
905 | }
|
---|
906 |
|
---|
907 | void dic_change_address( unsigned serv_id, void *serv_address, int serv_size)
|
---|
908 | {
|
---|
909 | register DIC_SERVICE *servp;
|
---|
910 |
|
---|
911 | DISABLE_AST
|
---|
912 | if( serv_id == 0 )
|
---|
913 | {
|
---|
914 | ENABLE_AST
|
---|
915 | return;
|
---|
916 | }
|
---|
917 | servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
|
---|
918 | servp->serv_address = (int *)serv_address;
|
---|
919 | servp->serv_size = serv_size;
|
---|
920 | ENABLE_AST
|
---|
921 | }
|
---|
922 |
|
---|
923 | int dic_get_quality( unsigned serv_id )
|
---|
924 | {
|
---|
925 | register DIC_SERVICE *servp;
|
---|
926 |
|
---|
927 | DISABLE_AST
|
---|
928 | if( serv_id == 0 )
|
---|
929 | {
|
---|
930 | if(Current_server)
|
---|
931 | servp = Current_server;
|
---|
932 | else
|
---|
933 | {
|
---|
934 |
|
---|
935 | ENABLE_AST
|
---|
936 | return(-1);
|
---|
937 | }
|
---|
938 | }
|
---|
939 | else
|
---|
940 | {
|
---|
941 | servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
|
---|
942 | }
|
---|
943 | ENABLE_AST
|
---|
944 | return(servp->quality);
|
---|
945 | }
|
---|
946 |
|
---|
947 | char *dic_get_format( unsigned serv_id )
|
---|
948 | {
|
---|
949 | register DIC_SERVICE *servp;
|
---|
950 |
|
---|
951 | DISABLE_AST
|
---|
952 | if( serv_id == 0 )
|
---|
953 | {
|
---|
954 | if(Current_server)
|
---|
955 | servp = Current_server;
|
---|
956 | else
|
---|
957 | {
|
---|
958 | ENABLE_AST
|
---|
959 | return((char *) 0);
|
---|
960 | }
|
---|
961 | }
|
---|
962 | else
|
---|
963 | {
|
---|
964 | servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
|
---|
965 | }
|
---|
966 | ENABLE_AST
|
---|
967 | return(servp->def);
|
---|
968 | }
|
---|
969 |
|
---|
970 | int dic_get_timestamp( unsigned serv_id, int *secs, int *milisecs )
|
---|
971 | {
|
---|
972 | register DIC_SERVICE *servp;
|
---|
973 |
|
---|
974 | DISABLE_AST
|
---|
975 | *secs = 0;
|
---|
976 | *milisecs = 0;
|
---|
977 | if( serv_id == 0 )
|
---|
978 | {
|
---|
979 | if(Current_server)
|
---|
980 | servp = Current_server;
|
---|
981 | else
|
---|
982 | {
|
---|
983 | ENABLE_AST
|
---|
984 | return(-1);
|
---|
985 | }
|
---|
986 | }
|
---|
987 | else
|
---|
988 | {
|
---|
989 | servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
|
---|
990 | }
|
---|
991 | ENABLE_AST
|
---|
992 | if(servp->time_stamp[1])
|
---|
993 | {
|
---|
994 | *secs = servp->time_stamp[1];
|
---|
995 | if((servp->time_stamp[0] & 0xFFFF0000) == 0xc0de0000)
|
---|
996 | *milisecs = servp->time_stamp[0] & 0x0000FFFF;
|
---|
997 | else
|
---|
998 | *milisecs = servp->time_stamp[0];
|
---|
999 | return(1);
|
---|
1000 | }
|
---|
1001 | else
|
---|
1002 | {
|
---|
1003 | /*
|
---|
1004 | *secs = 0;
|
---|
1005 | *milisecs = 0;
|
---|
1006 | */
|
---|
1007 | return(0);
|
---|
1008 | }
|
---|
1009 | }
|
---|
1010 |
|
---|
1011 | void dic_release_service( unsigned service_id )
|
---|
1012 | {
|
---|
1013 | register DIC_SERVICE *servp;
|
---|
1014 | register int conn_id, pending;
|
---|
1015 | static DIC_PACKET *dic_packet;
|
---|
1016 | static int packet_size = 0;
|
---|
1017 | DIC_DNS_PACKET dic_dns_packet;
|
---|
1018 | register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
|
---|
1019 | SERVICE_REQ *serv_reqp;
|
---|
1020 | int release_service();
|
---|
1021 |
|
---|
1022 | DISABLE_AST
|
---|
1023 | if( !packet_size ) {
|
---|
1024 | dic_packet = (DIC_PACKET *)malloc(DIC_HEADER);
|
---|
1025 | packet_size = DIC_HEADER;
|
---|
1026 | }
|
---|
1027 | if( service_id == 0 )
|
---|
1028 | {
|
---|
1029 | ENABLE_AST
|
---|
1030 | return;
|
---|
1031 | }
|
---|
1032 | servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
|
---|
1033 | if( servp == 0 )
|
---|
1034 | {
|
---|
1035 | ENABLE_AST
|
---|
1036 | return;
|
---|
1037 | }
|
---|
1038 | if(servp->serv_id != (int)service_id)
|
---|
1039 | {
|
---|
1040 | ENABLE_AST
|
---|
1041 | return;
|
---|
1042 | }
|
---|
1043 | pending = servp->pending;
|
---|
1044 | switch( pending )
|
---|
1045 | {
|
---|
1046 | case NOT_PENDING :
|
---|
1047 | conn_id = servp->conn_id;
|
---|
1048 | strncpy(dic_packet->service_name, servp->serv_name, MAX_NAME);
|
---|
1049 | dic_packet->type = htovl(DIM_DELETE);
|
---|
1050 | dic_packet->service_id = htovl(service_id);
|
---|
1051 | dic_packet->size = htovl(DIC_HEADER);
|
---|
1052 | dna_write_nowait( conn_id, dic_packet, DIC_HEADER );
|
---|
1053 | release_service( servp );
|
---|
1054 | break;
|
---|
1055 | case WAITING_SERVER_UP :
|
---|
1056 | if( ( servp->type == COMMAND )||( servp->type == ONCE_ONLY ) )
|
---|
1057 | {
|
---|
1058 | servp->pending = DELETED;
|
---|
1059 | break;
|
---|
1060 | }
|
---|
1061 | if( Dns_dic_conn_id > 0) {
|
---|
1062 | dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
|
---|
1063 | dic_dns_p->src_type = htovl(SRC_DIC);
|
---|
1064 | serv_reqp = &dic_dns_p->service;
|
---|
1065 | strcpy( serv_reqp->service_name, servp->serv_name );
|
---|
1066 | serv_reqp->service_id = htovl(servp->serv_id | 0x80000000);
|
---|
1067 | dna_write( Dns_dic_conn_id, dic_dns_p,
|
---|
1068 | sizeof(DIC_DNS_PACKET) );
|
---|
1069 | }
|
---|
1070 | release_service( servp );
|
---|
1071 | break;
|
---|
1072 | case WAITING_CMND_ANSWER :
|
---|
1073 | case WAITING_DNS_UP :
|
---|
1074 | release_service( servp );
|
---|
1075 | break;
|
---|
1076 | case WAITING_DNS_ANSWER :
|
---|
1077 | servp->pending = DELETED;
|
---|
1078 | break;
|
---|
1079 | }
|
---|
1080 | ENABLE_AST
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 |
|
---|
1084 | int release_service( DIC_SERVICE *servicep )
|
---|
1085 | {
|
---|
1086 | register DIC_SERVICE *servp;
|
---|
1087 | register int conn_id = 0;
|
---|
1088 | register int found = 0;
|
---|
1089 | register DIC_CONNECTION *dic_connp;
|
---|
1090 | char name[MAX_NAME], *ptr;
|
---|
1091 | int id;
|
---|
1092 |
|
---|
1093 | id = servicep->serv_id;
|
---|
1094 | servicep->serv_id = 0;
|
---|
1095 | conn_id = servicep->conn_id;
|
---|
1096 | dic_connp = &Dic_conns[conn_id] ;
|
---|
1097 | dll_remove( (DLL *) servicep );
|
---|
1098 | if( servicep->timer_ent )
|
---|
1099 | {
|
---|
1100 | dtq_rem_entry( Dic_timer_q, servicep->timer_ent );
|
---|
1101 | }
|
---|
1102 | /*
|
---|
1103 | if(servicep->type != COMMAND)
|
---|
1104 | */
|
---|
1105 | if(servicep->fill_size > 0)
|
---|
1106 | free( servicep->fill_address );
|
---|
1107 | if(strstr(servicep->serv_name,"/RpcOut"))
|
---|
1108 | {
|
---|
1109 | strcpy(name, servicep->serv_name);
|
---|
1110 | }
|
---|
1111 | else
|
---|
1112 | name[0] = '\0';
|
---|
1113 | free( servicep );
|
---|
1114 | if( conn_id && dic_connp->service_head )
|
---|
1115 | {
|
---|
1116 | if( dll_empty((DLL *)dic_connp->service_head) )
|
---|
1117 | {
|
---|
1118 | if( (servp = (DIC_SERVICE *) Cmnd_head) )
|
---|
1119 | {
|
---|
1120 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
1121 | (DLL *) Cmnd_head,
|
---|
1122 | (DLL *) servp)) )
|
---|
1123 | {
|
---|
1124 | if( servp->conn_id == conn_id)
|
---|
1125 | found = 1;
|
---|
1126 | }
|
---|
1127 | }
|
---|
1128 | if( !found)
|
---|
1129 | {
|
---|
1130 | if(Debug_on)
|
---|
1131 | {
|
---|
1132 | dim_print_date_time();
|
---|
1133 | printf("Conn %d, Server %s on node %s released\n",
|
---|
1134 | conn_id, dic_connp->task_name, dic_connp->node_name);
|
---|
1135 | fflush(stdout);
|
---|
1136 | }
|
---|
1137 | release_conn( conn_id );
|
---|
1138 | }
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 | if(name[0])
|
---|
1142 | {
|
---|
1143 | ptr = strstr(name,"/RpcOut");
|
---|
1144 | strcpy(ptr + 4, "In");
|
---|
1145 | if( (servp = locate_command(name)) )
|
---|
1146 | release_service(servp);
|
---|
1147 | }
|
---|
1148 | id_free(id, SRC_DIC);
|
---|
1149 | return(1);
|
---|
1150 | }
|
---|
1151 |
|
---|
1152 |
|
---|
1153 | int locate_service( DIC_SERVICE *servp )
|
---|
1154 | {
|
---|
1155 | extern int open_dns(dim_long, void (*)(), void (*)(), int, int, int);
|
---|
1156 |
|
---|
1157 | if(!strcmp(servp->serv_name,"DIS_DNS/SERVER_INFO"))
|
---|
1158 | {
|
---|
1159 | Tmout_min = DID_DNS_TMOUT_MIN;
|
---|
1160 | Tmout_max = DID_DNS_TMOUT_MAX;
|
---|
1161 | }
|
---|
1162 | if(Tmout_min == 0)
|
---|
1163 | {
|
---|
1164 | Tmout_min = DIC_DNS_TMOUT_MIN;
|
---|
1165 | Tmout_max = DIC_DNS_TMOUT_MAX;
|
---|
1166 | }
|
---|
1167 | if( !Dns_dic_conn_id )
|
---|
1168 | {
|
---|
1169 | DISABLE_AST;
|
---|
1170 | Dns_dic_conn_id = open_dns( 0, recv_dns_dic_rout, error_handler,
|
---|
1171 | Tmout_min,
|
---|
1172 | Tmout_max,
|
---|
1173 | SRC_DIC);
|
---|
1174 | if(Dns_dic_conn_id == -2)
|
---|
1175 | error_handler(0, DIM_FATAL, DIMDNSUNDEF, "DIM_DNS_NODE undefined");
|
---|
1176 | ENABLE_AST;
|
---|
1177 | }
|
---|
1178 | if( Dns_dic_conn_id > 0)
|
---|
1179 | {
|
---|
1180 | DISABLE_AST;
|
---|
1181 | request_dns_info(servp->prev->serv_id);
|
---|
1182 | ENABLE_AST;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | return(Dns_dic_conn_id);
|
---|
1186 | }
|
---|
1187 |
|
---|
1188 | DIC_SERVICE *locate_command( char *serv_name )
|
---|
1189 | {
|
---|
1190 | register DIC_SERVICE *servp;
|
---|
1191 |
|
---|
1192 | if(!Cmnd_head)
|
---|
1193 | return((DIC_SERVICE *)0);
|
---|
1194 | if( (servp = (DIC_SERVICE *) dll_search( (DLL *) Cmnd_head, serv_name,
|
---|
1195 | strlen(serv_name)+1)) )
|
---|
1196 | return(servp);
|
---|
1197 | return((DIC_SERVICE *)0);
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 | DIC_SERVICE *locate_pending( char *serv_name )
|
---|
1201 | {
|
---|
1202 | register DIC_SERVICE *servp;
|
---|
1203 |
|
---|
1204 | if(!Service_pend_head)
|
---|
1205 | return((DIC_SERVICE *)0);
|
---|
1206 | if( (servp = (DIC_SERVICE *) dll_search( (DLL *) Service_pend_head, serv_name,
|
---|
1207 | strlen(serv_name)+1)) )
|
---|
1208 | return(servp);
|
---|
1209 | return((DIC_SERVICE *)0);
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 | DIC_BAD_CONNECTION *locate_bad(char *node, char *task, int port)
|
---|
1213 | {
|
---|
1214 | DIC_BAD_CONNECTION *bad_connp;
|
---|
1215 |
|
---|
1216 | if(!Bad_connection_head)
|
---|
1217 | return((DIC_BAD_CONNECTION *)0);
|
---|
1218 | bad_connp = Bad_connection_head;
|
---|
1219 | while( (bad_connp = (DIC_BAD_CONNECTION *) dll_get_next(
|
---|
1220 | (DLL *) Bad_connection_head,
|
---|
1221 | (DLL *) bad_connp)) )
|
---|
1222 | {
|
---|
1223 | if((!strcmp(bad_connp->conn.node_name, node)) &&
|
---|
1224 | (!strcmp(bad_connp->conn.task_name, task)) &&
|
---|
1225 | (bad_connp->conn.port == port) )
|
---|
1226 | return(bad_connp);
|
---|
1227 | }
|
---|
1228 | return((DIC_BAD_CONNECTION *)0);
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | static void request_dns_info(int id)
|
---|
1232 | {
|
---|
1233 | DIC_SERVICE *servp, *ptr;
|
---|
1234 | int n_pend = 0;
|
---|
1235 | int request_dns_single_info();
|
---|
1236 | extern int open_dns();
|
---|
1237 |
|
---|
1238 | DISABLE_AST
|
---|
1239 | if( Dns_dic_conn_id <= 0)
|
---|
1240 | {
|
---|
1241 | Dns_dic_conn_id = open_dns( 0, recv_dns_dic_rout, error_handler,
|
---|
1242 | Tmout_min,
|
---|
1243 | Tmout_max,
|
---|
1244 | SRC_DIC);
|
---|
1245 | if(Dns_dic_conn_id == -2)
|
---|
1246 | error_handler(0, DIM_FATAL, DIMDNSUNDEF, "DIM_DNS_NODE undefined");
|
---|
1247 | }
|
---|
1248 | if( Dns_dic_conn_id > 0)
|
---|
1249 | {
|
---|
1250 | servp = Service_pend_head;
|
---|
1251 | if(id > 0)
|
---|
1252 | {
|
---|
1253 | ptr = (DIC_SERVICE *)id_get_ptr(id, SRC_DIC);
|
---|
1254 | if(ptr)
|
---|
1255 | {
|
---|
1256 | if((ptr->serv_id == id) && (ptr->pending != NOT_PENDING))
|
---|
1257 | servp = ptr;
|
---|
1258 | }
|
---|
1259 | }
|
---|
1260 |
|
---|
1261 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
1262 | (DLL *) Service_pend_head,
|
---|
1263 | (DLL *) servp)) )
|
---|
1264 | {
|
---|
1265 | if( servp->pending == WAITING_DNS_UP)
|
---|
1266 | {
|
---|
1267 | if(!request_dns_single_info( servp ))
|
---|
1268 | {
|
---|
1269 | ENABLE_AST
|
---|
1270 | return;
|
---|
1271 | }
|
---|
1272 | n_pend++;
|
---|
1273 | }
|
---|
1274 | if(n_pend == 1000)
|
---|
1275 | {
|
---|
1276 | dtq_start_timer( 0, request_dns_info, servp->serv_id);
|
---|
1277 | ENABLE_AST
|
---|
1278 | return;
|
---|
1279 | }
|
---|
1280 | }
|
---|
1281 | }
|
---|
1282 | else
|
---|
1283 | {
|
---|
1284 | servp = Service_pend_head;
|
---|
1285 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
1286 | (DLL *) Service_pend_head,
|
---|
1287 | (DLL *) servp)) )
|
---|
1288 | {
|
---|
1289 | if( servp->pending == WAITING_DNS_UP)
|
---|
1290 | {
|
---|
1291 | if(( servp->type != COMMAND )&&( servp->type != ONCE_ONLY ))
|
---|
1292 | service_tmout( servp->serv_id );
|
---|
1293 | }
|
---|
1294 | }
|
---|
1295 | }
|
---|
1296 | ENABLE_AST
|
---|
1297 | }
|
---|
1298 |
|
---|
1299 |
|
---|
1300 | int request_dns_single_info( DIC_SERVICE *servp )
|
---|
1301 | {
|
---|
1302 | static DIC_DNS_PACKET Dic_dns_packet;
|
---|
1303 | static SERVICE_REQ *serv_reqp;
|
---|
1304 | int ret = 1;
|
---|
1305 |
|
---|
1306 | if( Dns_dic_conn_id > 0)
|
---|
1307 | {
|
---|
1308 | if(Debug_on)
|
---|
1309 | {
|
---|
1310 | dim_print_date_time();
|
---|
1311 | printf("Requesting DNS Info for %s, id %d\n",
|
---|
1312 | servp->serv_name, servp->serv_id);
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | Dic_dns_packet.src_type = htovl(SRC_DIC);
|
---|
1316 | serv_reqp = &Dic_dns_packet.service;
|
---|
1317 | strcpy( serv_reqp->service_name, servp->serv_name );
|
---|
1318 | serv_reqp->service_id = htovl(servp->serv_id);
|
---|
1319 | servp->pending = WAITING_DNS_ANSWER;
|
---|
1320 | Dic_dns_packet.size = htovl(sizeof(DIC_DNS_PACKET));
|
---|
1321 | if(!dna_write( Dns_dic_conn_id, &Dic_dns_packet,
|
---|
1322 | sizeof(DIC_DNS_PACKET) ) )
|
---|
1323 | {
|
---|
1324 | ret = 0;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | }
|
---|
1328 | return ret;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 |
|
---|
1332 | static int handle_dns_info( DNS_DIC_PACKET *packet )
|
---|
1333 | {
|
---|
1334 | int conn_id, service_id;
|
---|
1335 | DIC_SERVICE *servp;
|
---|
1336 | char *node_name, *task_name;
|
---|
1337 | char node_info[MAX_NODE_NAME+4];
|
---|
1338 | int i, port, protocol, format, pid;
|
---|
1339 | register DIC_CONNECTION *dic_connp ;
|
---|
1340 | DIC_DNS_PACKET dic_dns_packet;
|
---|
1341 | register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
|
---|
1342 | SERVICE_REQ *serv_reqp;
|
---|
1343 | DIC_BAD_CONNECTION *bad_connp;
|
---|
1344 | int retrying = 0;
|
---|
1345 | int tmout;
|
---|
1346 | int send_service_command();
|
---|
1347 | int find_connection();
|
---|
1348 | void move_to_bad_service();
|
---|
1349 | void retry_bad_connection();
|
---|
1350 |
|
---|
1351 | service_id = vtohl(packet->service_id);
|
---|
1352 |
|
---|
1353 | servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
|
---|
1354 | if(!servp)
|
---|
1355 | return(0);
|
---|
1356 | if(servp->serv_id != service_id)
|
---|
1357 | return(0);
|
---|
1358 | if(Debug_on)
|
---|
1359 | {
|
---|
1360 | dim_print_date_time();
|
---|
1361 | printf("Receiving DNS Info for service %s, id %d\n",servp->serv_name,
|
---|
1362 | vtohl(packet->service_id));
|
---|
1363 | }
|
---|
1364 | node_name = packet->node_name;
|
---|
1365 | if(node_name[0] == -1)
|
---|
1366 | {
|
---|
1367 | error_handler(0, DIM_FATAL, DIMDNSREFUS, "DIM_DNS refuses connection");
|
---|
1368 | return(0);
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | task_name = packet->task_name;
|
---|
1372 | strcpy(node_info,node_name);
|
---|
1373 | for(i = 0; i < 4; i ++)
|
---|
1374 | node_info[strlen(node_name)+i+1] = packet->node_addr[i];
|
---|
1375 | port = vtohl(packet->port);
|
---|
1376 | pid = vtohl(packet->pid);
|
---|
1377 | protocol = vtohl(packet->protocol);
|
---|
1378 | format = vtohl(packet->format);
|
---|
1379 |
|
---|
1380 | if( Dns_dic_timr )
|
---|
1381 | dtq_clear_entry( Dns_dic_timr );
|
---|
1382 | if( servp->pending == DELETED ) {
|
---|
1383 | if( Dns_dic_conn_id > 0) {
|
---|
1384 | dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
|
---|
1385 | dic_dns_p->src_type = htovl(SRC_DIC);
|
---|
1386 | serv_reqp = &dic_dns_p->service;
|
---|
1387 | strcpy( serv_reqp->service_name, servp->serv_name );
|
---|
1388 | serv_reqp->service_id = htovl(servp->serv_id | 0x80000000);
|
---|
1389 | dna_write( Dns_dic_conn_id, dic_dns_p,
|
---|
1390 | sizeof(DIC_DNS_PACKET) );
|
---|
1391 | }
|
---|
1392 | release_service( servp );
|
---|
1393 | return(0);
|
---|
1394 | }
|
---|
1395 | if( !node_name[0] )
|
---|
1396 | {
|
---|
1397 | servp->pending = WAITING_SERVER_UP;
|
---|
1398 | service_tmout( servp->serv_id );
|
---|
1399 | if( servp->pending == DELETED )
|
---|
1400 | {
|
---|
1401 | if( Dns_dic_conn_id > 0)
|
---|
1402 | {
|
---|
1403 | dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
|
---|
1404 | dic_dns_p->src_type = htovl(SRC_DIC);
|
---|
1405 | serv_reqp = &dic_dns_p->service;
|
---|
1406 | strcpy( serv_reqp->service_name, servp->serv_name );
|
---|
1407 | serv_reqp->service_id = htovl(servp->serv_id | 0x80000000);
|
---|
1408 | dna_write( Dns_dic_conn_id, dic_dns_p,
|
---|
1409 | sizeof(DIC_DNS_PACKET) );
|
---|
1410 | }
|
---|
1411 | release_service( servp );
|
---|
1412 | }
|
---|
1413 | return(0);
|
---|
1414 | }
|
---|
1415 | #ifdef OSK
|
---|
1416 | {
|
---|
1417 | register char *ptr;
|
---|
1418 |
|
---|
1419 | if(strncmp(node_name,"fidel",5))
|
---|
1420 | {
|
---|
1421 | for(ptr = node_name; *ptr; ptr++)
|
---|
1422 | {
|
---|
1423 | if(*ptr == '.')
|
---|
1424 | {
|
---|
1425 | *ptr = '\0';
|
---|
1426 | break;
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 | }
|
---|
1430 | }
|
---|
1431 | #endif
|
---|
1432 | if( !(conn_id = find_connection(node_name, task_name, port)) )
|
---|
1433 | {
|
---|
1434 | bad_connp = locate_bad(node_name, task_name, port);
|
---|
1435 | if(bad_connp)
|
---|
1436 | retrying = bad_connp->retrying;
|
---|
1437 | if((!bad_connp) || (retrying))
|
---|
1438 | {
|
---|
1439 | if( (conn_id = dna_open_client(node_info, task_name, port,
|
---|
1440 | protocol, recv_rout, error_handler, SRC_DIC)) )
|
---|
1441 | {
|
---|
1442 | /*
|
---|
1443 | #ifndef VxWorks
|
---|
1444 | if(format & MY_OS9)
|
---|
1445 | {
|
---|
1446 | dna_set_test_write(conn_id, TEST_TIME_OSK);
|
---|
1447 | format &= 0xfffff7ff;
|
---|
1448 | }
|
---|
1449 | else
|
---|
1450 | {
|
---|
1451 | dna_set_test_write(conn_id, TEST_TIME_VMS);
|
---|
1452 | }
|
---|
1453 | #endif
|
---|
1454 | */
|
---|
1455 | dna_set_test_write(conn_id, dim_get_keepalive_timeout());
|
---|
1456 | dic_connp = &Dic_conns[conn_id];
|
---|
1457 | strncpy( dic_connp->node_name, node_name,
|
---|
1458 | MAX_NODE_NAME);
|
---|
1459 | strncpy( dic_connp->task_name, task_name,
|
---|
1460 | MAX_TASK_NAME);
|
---|
1461 | dic_connp->port = port;
|
---|
1462 | dic_connp->pid = pid;
|
---|
1463 | if(Debug_on)
|
---|
1464 | {
|
---|
1465 | dim_print_date_time();
|
---|
1466 | printf("Conn %d, Server %s on node %s Connecting\n",
|
---|
1467 | conn_id, dic_connp->task_name, dic_connp->node_name);
|
---|
1468 | fflush(stdout);
|
---|
1469 | }
|
---|
1470 |
|
---|
1471 | dic_connp->service_head =
|
---|
1472 | malloc(sizeof(DIC_SERVICE));
|
---|
1473 | dll_init( (DLL *) dic_connp->service_head);
|
---|
1474 | ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
|
---|
1475 | if(retrying)
|
---|
1476 | {
|
---|
1477 | dll_remove((DLL *)bad_connp->conn.service_head);
|
---|
1478 | free(bad_connp->conn.service_head);
|
---|
1479 | dll_remove((DLL *)bad_connp);
|
---|
1480 | free(bad_connp);
|
---|
1481 | }
|
---|
1482 | }
|
---|
1483 | else
|
---|
1484 | {
|
---|
1485 | if(!retrying)
|
---|
1486 | {
|
---|
1487 | if( !Bad_connection_head )
|
---|
1488 | {
|
---|
1489 | Bad_connection_head = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
|
---|
1490 | dll_init( (DLL *) Bad_connection_head );
|
---|
1491 | Bad_connection_head->conn.service_head = 0;
|
---|
1492 | }
|
---|
1493 | bad_connp = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
|
---|
1494 | bad_connp->n_retries = 0;
|
---|
1495 | bad_connp->conn.service_head = malloc(sizeof(DIC_SERVICE));
|
---|
1496 | dll_init( (DLL *) bad_connp->conn.service_head);
|
---|
1497 |
|
---|
1498 | dll_insert_queue( (DLL *) Bad_connection_head, (DLL *) bad_connp );
|
---|
1499 | if(Debug_on)
|
---|
1500 | {
|
---|
1501 | dim_print_date_time();
|
---|
1502 | printf("Failed connecting to Server %s on node %s port %d\n",
|
---|
1503 | task_name, node_name, port);
|
---|
1504 | fflush(stdout);
|
---|
1505 | }
|
---|
1506 | service_tmout( servp->serv_id );
|
---|
1507 | }
|
---|
1508 | bad_connp->n_retries++;
|
---|
1509 | bad_connp->retrying = 0;
|
---|
1510 | strncpy( bad_connp->conn.node_name, node_name, MAX_NODE_NAME);
|
---|
1511 | strncpy( bad_connp->conn.task_name, task_name, MAX_TASK_NAME);
|
---|
1512 | bad_connp->conn.port = port;
|
---|
1513 | tmout = BAD_CONN_TIMEOUT * (bad_connp->n_retries - 1);
|
---|
1514 | if(tmout > 120)
|
---|
1515 | tmout = 120;
|
---|
1516 | /* Can not be 0, the callback of dtq_start_timer(0) is not protected */
|
---|
1517 | if(tmout == 0)
|
---|
1518 | tmout = 1;
|
---|
1519 | dtq_start_timer(tmout, retry_bad_connection, (dim_long)bad_connp);
|
---|
1520 | if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
|
---|
1521 | return(0);
|
---|
1522 | move_to_bad_service(servp, bad_connp);
|
---|
1523 | /*
|
---|
1524 | ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
|
---|
1525 |
|
---|
1526 | servp = Service_pend_head;
|
---|
1527 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
1528 | (DLL *) Service_pend_head,
|
---|
1529 | (DLL *) servp)) )
|
---|
1530 | {
|
---|
1531 | if( (servp->pending == WAITING_DNS_ANSWER) ||
|
---|
1532 | (servp->pending == WAITING_SERVER_UP))
|
---|
1533 | servp->pending = WAITING_DNS_UP;
|
---|
1534 | }
|
---|
1535 | dna_close( Dns_dic_conn_id );
|
---|
1536 | Dns_dic_conn_id = 0;
|
---|
1537 | request_dns_info(0);
|
---|
1538 | */
|
---|
1539 | return(0);
|
---|
1540 | }
|
---|
1541 | }
|
---|
1542 | else
|
---|
1543 | {
|
---|
1544 | if(!retrying)
|
---|
1545 | service_tmout( servp->serv_id );
|
---|
1546 | if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
|
---|
1547 | return(0);
|
---|
1548 | move_to_bad_service(servp, bad_connp);
|
---|
1549 | return(0);
|
---|
1550 | }
|
---|
1551 | }
|
---|
1552 | strcpy(servp->def, packet->service_def);
|
---|
1553 | get_format_data(format, servp->format_data, servp->def);
|
---|
1554 | servp->format = format;
|
---|
1555 | servp->conn_id = conn_id;
|
---|
1556 |
|
---|
1557 | send_service_command( servp );
|
---|
1558 | /*
|
---|
1559 | if( ret == 1)
|
---|
1560 | {
|
---|
1561 | if(servp->pending != WAITING_CMND_ANSWER)
|
---|
1562 | servp->pending = NOT_PENDING;
|
---|
1563 | servp->tmout_done = 0;
|
---|
1564 | }
|
---|
1565 | */
|
---|
1566 | return(1);
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | void retry_bad_connection(DIC_BAD_CONNECTION *bad_connp)
|
---|
1570 | {
|
---|
1571 | DIC_SERVICE *servp, *auxp;
|
---|
1572 | int found = 0;
|
---|
1573 | void move_to_notok_service();
|
---|
1574 |
|
---|
1575 | if(!bad_connp)
|
---|
1576 | return;
|
---|
1577 | servp = (DIC_SERVICE *)bad_connp->conn.service_head;
|
---|
1578 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
1579 | (DLL *) bad_connp->conn.service_head,
|
---|
1580 | (DLL *) servp)) )
|
---|
1581 | {
|
---|
1582 | /*
|
---|
1583 | servp->pending = WAITING_DNS_UP;
|
---|
1584 | servp->conn_id = 0;
|
---|
1585 | */
|
---|
1586 | auxp = servp->prev;
|
---|
1587 | move_to_notok_service( servp );
|
---|
1588 | servp = auxp;
|
---|
1589 | found = 1;
|
---|
1590 | }
|
---|
1591 | bad_connp->retrying = 1;
|
---|
1592 | if(found)
|
---|
1593 | request_dns_info(0);
|
---|
1594 | }
|
---|
1595 |
|
---|
1596 | void move_to_ok_service( DIC_SERVICE *servp, int conn_id )
|
---|
1597 | {
|
---|
1598 | if(Dic_conns[conn_id].service_head)
|
---|
1599 | {
|
---|
1600 | DISABLE_AST
|
---|
1601 | /*
|
---|
1602 | printf("move_to_ok %s\n",servp->serv_name);
|
---|
1603 | */
|
---|
1604 | servp->pending = NOT_PENDING;
|
---|
1605 | servp->tmout_done = 0;
|
---|
1606 | dll_remove( (DLL *) servp );
|
---|
1607 | dll_insert_queue( (DLL *) Dic_conns[conn_id].service_head,
|
---|
1608 | (DLL *) servp );
|
---|
1609 | ENABLE_AST
|
---|
1610 | }
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | void move_to_bad_service( DIC_SERVICE *servp, DIC_BAD_CONNECTION *bad_connp)
|
---|
1614 | {
|
---|
1615 | DISABLE_AST
|
---|
1616 | /*
|
---|
1617 | printf("move_to_bad %s\n",servp->serv_name);
|
---|
1618 | */
|
---|
1619 | servp->pending = WAITING_DNS_UP;
|
---|
1620 | dll_remove( (DLL *) servp );
|
---|
1621 | dll_insert_queue( (DLL *) bad_connp->conn.service_head, (DLL *) servp );
|
---|
1622 | ENABLE_AST
|
---|
1623 | }
|
---|
1624 |
|
---|
1625 | void move_to_cmnd_service( DIC_SERVICE *servp )
|
---|
1626 | {
|
---|
1627 | /*
|
---|
1628 | if(servp->pending != WAITING_CMND_ANSWER)
|
---|
1629 | */
|
---|
1630 | DISABLE_AST
|
---|
1631 | /*
|
---|
1632 | printf("move_to_cmnd %s\n",servp->serv_name);
|
---|
1633 | */
|
---|
1634 | servp->pending = NOT_PENDING;
|
---|
1635 | servp->tmout_done = 0;
|
---|
1636 | dll_remove( (DLL *) servp );
|
---|
1637 | dll_insert_queue( (DLL *) Cmnd_head, (DLL *) servp );
|
---|
1638 | ENABLE_AST
|
---|
1639 | }
|
---|
1640 |
|
---|
1641 | void move_to_notok_service(DIC_SERVICE *servp )
|
---|
1642 | {
|
---|
1643 | DISABLE_AST
|
---|
1644 | /*
|
---|
1645 | printf("move_to_notok %s\n",servp->serv_name);
|
---|
1646 | */
|
---|
1647 | servp->pending = WAITING_DNS_UP;
|
---|
1648 | servp->conn_id = 0;
|
---|
1649 | dll_remove( (DLL *) servp );
|
---|
1650 | dll_insert_queue( (DLL *) Service_pend_head, (DLL *) servp );
|
---|
1651 | ENABLE_AST
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | static void get_format_data(int format, FORMAT_STR *format_data, char *def)
|
---|
1655 | {
|
---|
1656 | register FORMAT_STR *formatp = format_data;
|
---|
1657 | register char code, last_code = 0;
|
---|
1658 | int num;
|
---|
1659 | char *ptr = def;
|
---|
1660 |
|
---|
1661 | if(format){}
|
---|
1662 | while(*ptr)
|
---|
1663 | {
|
---|
1664 | switch(*ptr)
|
---|
1665 | {
|
---|
1666 | case 'i':
|
---|
1667 | case 'I':
|
---|
1668 | case 'l':
|
---|
1669 | case 'L':
|
---|
1670 | *ptr = 'I';
|
---|
1671 | break;
|
---|
1672 | case 'x':
|
---|
1673 | case 'X':
|
---|
1674 | *ptr = 'X';
|
---|
1675 | break;
|
---|
1676 | case 's':
|
---|
1677 | case 'S':
|
---|
1678 | *ptr = 'S';
|
---|
1679 | break;
|
---|
1680 | case 'f':
|
---|
1681 | case 'F':
|
---|
1682 | *ptr = 'F';
|
---|
1683 | break;
|
---|
1684 | case 'd':
|
---|
1685 | case 'D':
|
---|
1686 | *ptr = 'D';
|
---|
1687 | break;
|
---|
1688 | case 'c':
|
---|
1689 | case 'C':
|
---|
1690 | *ptr = 'C';
|
---|
1691 | break;
|
---|
1692 | }
|
---|
1693 | ptr++;
|
---|
1694 | }
|
---|
1695 | code = *def;
|
---|
1696 | while(*def)
|
---|
1697 | {
|
---|
1698 | if(code != last_code)
|
---|
1699 | {
|
---|
1700 | formatp->par_num = 0;
|
---|
1701 | formatp->flags = 0;
|
---|
1702 | switch(code)
|
---|
1703 | {
|
---|
1704 | case 'i':
|
---|
1705 | case 'I':
|
---|
1706 | case 'l':
|
---|
1707 | case 'L':
|
---|
1708 | formatp->par_bytes = SIZEOF_LONG;
|
---|
1709 | formatp->flags |= SWAPL;
|
---|
1710 | break;
|
---|
1711 | case 'x':
|
---|
1712 | case 'X':
|
---|
1713 | formatp->par_bytes = SIZEOF_DOUBLE;
|
---|
1714 | formatp->flags |= SWAPD;
|
---|
1715 | break;
|
---|
1716 | case 's':
|
---|
1717 | case 'S':
|
---|
1718 | formatp->par_bytes = SIZEOF_SHORT;
|
---|
1719 | formatp->flags |= SWAPS;
|
---|
1720 | break;
|
---|
1721 | case 'f':
|
---|
1722 | case 'F':
|
---|
1723 | formatp->par_bytes = SIZEOF_LONG;
|
---|
1724 | formatp->flags |= SWAPL;
|
---|
1725 | #ifdef vms
|
---|
1726 | /*
|
---|
1727 | if((format & 0xF0) != (MY_FORMAT & 0xF0))
|
---|
1728 | */
|
---|
1729 | formatp->flags |= (format & 0xF0);
|
---|
1730 | formatp->flags |= IT_IS_FLOAT;
|
---|
1731 | #endif
|
---|
1732 | break;
|
---|
1733 | case 'd':
|
---|
1734 | case 'D':
|
---|
1735 | formatp->par_bytes = SIZEOF_DOUBLE;
|
---|
1736 | formatp->flags |= SWAPD;
|
---|
1737 | #ifdef vms
|
---|
1738 | /*
|
---|
1739 | if((format & 0xF0) != (MY_FORMAT & 0xF0))
|
---|
1740 | */
|
---|
1741 | formatp->flags |= (format & 0xF0);
|
---|
1742 | formatp->flags |= IT_IS_FLOAT;
|
---|
1743 | #endif
|
---|
1744 | break;
|
---|
1745 | case 'c':
|
---|
1746 | case 'C':
|
---|
1747 | case 'b':
|
---|
1748 | case 'B':
|
---|
1749 | case 'v':
|
---|
1750 | case 'V':
|
---|
1751 | formatp->par_bytes = SIZEOF_CHAR;
|
---|
1752 | formatp->flags |= NOSWAP;
|
---|
1753 | break;
|
---|
1754 | }
|
---|
1755 | }
|
---|
1756 | def++;
|
---|
1757 | if(*def != ':')
|
---|
1758 | {
|
---|
1759 | /* tested by the server
|
---|
1760 | if(*def)
|
---|
1761 | {
|
---|
1762 | printf("Bad service definition parsing\n");
|
---|
1763 | fflush(stdout);
|
---|
1764 | }
|
---|
1765 | else
|
---|
1766 | */
|
---|
1767 | formatp->par_num = 0;
|
---|
1768 | }
|
---|
1769 | else
|
---|
1770 | {
|
---|
1771 | def++;
|
---|
1772 | sscanf(def,"%d",&num);
|
---|
1773 | formatp->par_num += num;
|
---|
1774 | while((*def != ';') && (*def != '\0'))
|
---|
1775 | def++;
|
---|
1776 | if(*def)
|
---|
1777 | def++;
|
---|
1778 | }
|
---|
1779 | last_code = code;
|
---|
1780 | code = *def;
|
---|
1781 | if(code != last_code)
|
---|
1782 | formatp++;
|
---|
1783 | }
|
---|
1784 | formatp->par_bytes = 0;
|
---|
1785 | /*
|
---|
1786 | if((format & 0xF) == (MY_FORMAT & 0xF))
|
---|
1787 | {
|
---|
1788 | for(i = 0, formatp = format_data; i<index;i++, formatp++)
|
---|
1789 | formatp->flags &= 0xF0;
|
---|
1790 | }
|
---|
1791 | */
|
---|
1792 | }
|
---|
1793 |
|
---|
1794 | int end_command(DIC_SERVICE *servp, int ret)
|
---|
1795 | {
|
---|
1796 | DIC_SERVICE *aux_servp;
|
---|
1797 | DIC_CONNECTION *dic_connp;
|
---|
1798 |
|
---|
1799 | DISABLE_AST
|
---|
1800 | dic_connp = &Dic_conns[servp->conn_id];
|
---|
1801 | if(servp->pending != WAITING_CMND_ANSWER)
|
---|
1802 | {
|
---|
1803 | if((!ret) || (!dic_connp->service_head))
|
---|
1804 | {
|
---|
1805 | servp->pending = WAITING_DNS_UP;
|
---|
1806 | dic_release_service( servp->serv_id );
|
---|
1807 | }
|
---|
1808 | else
|
---|
1809 | {
|
---|
1810 | aux_servp = locate_command(servp->serv_name);
|
---|
1811 | if( !aux_servp )
|
---|
1812 | {
|
---|
1813 | move_to_cmnd_service( servp );
|
---|
1814 | }
|
---|
1815 | else
|
---|
1816 | {
|
---|
1817 | if(aux_servp != servp)
|
---|
1818 | {
|
---|
1819 | servp->pending = WAITING_DNS_UP;
|
---|
1820 | dic_release_service( servp->serv_id );
|
---|
1821 | }
|
---|
1822 | }
|
---|
1823 | }
|
---|
1824 | }
|
---|
1825 | ENABLE_AST
|
---|
1826 | return(ret);
|
---|
1827 | }
|
---|
1828 |
|
---|
1829 | int send_service_command(DIC_SERVICE *servp)
|
---|
1830 | {
|
---|
1831 | int ret = 1;
|
---|
1832 | int conn_id;
|
---|
1833 | int send_command();
|
---|
1834 | int send_service();
|
---|
1835 |
|
---|
1836 | conn_id = servp->conn_id;
|
---|
1837 | if( servp->type == COMMAND )
|
---|
1838 | {
|
---|
1839 | ret = send_command(conn_id, servp);
|
---|
1840 | end_command(servp, ret);
|
---|
1841 | }
|
---|
1842 | else
|
---|
1843 | {
|
---|
1844 | if( send_service(conn_id, servp))
|
---|
1845 | {
|
---|
1846 | if( servp->type == ONCE_ONLY )
|
---|
1847 | {
|
---|
1848 | if( !locate_command(servp->serv_name) )
|
---|
1849 | {
|
---|
1850 | move_to_cmnd_service( servp );
|
---|
1851 | }
|
---|
1852 | }
|
---|
1853 | else
|
---|
1854 | move_to_ok_service( servp, conn_id );
|
---|
1855 | }
|
---|
1856 | else
|
---|
1857 | {
|
---|
1858 | if( servp->type == ONCE_ONLY )
|
---|
1859 | {
|
---|
1860 | servp->pending = WAITING_DNS_UP;
|
---|
1861 | dic_release_service( servp->serv_id );
|
---|
1862 | }
|
---|
1863 | else
|
---|
1864 | {
|
---|
1865 | servp->pending = WAITING_DNS_UP;
|
---|
1866 | servp->conn_id = 0;
|
---|
1867 | /*
|
---|
1868 | release_conn(conn_id);
|
---|
1869 | */
|
---|
1870 | request_dns_info(0);
|
---|
1871 | }
|
---|
1872 | }
|
---|
1873 | }
|
---|
1874 | return(ret);
|
---|
1875 | }
|
---|
1876 |
|
---|
1877 | int send_service(int conn_id, DIC_SERVICE *servp)
|
---|
1878 | {
|
---|
1879 | static DIC_PACKET *dic_packet;
|
---|
1880 | static int serv_packet_size = 0;
|
---|
1881 | int type, ret;
|
---|
1882 |
|
---|
1883 | if( !serv_packet_size ) {
|
---|
1884 | dic_packet = (DIC_PACKET *)malloc(DIC_HEADER);
|
---|
1885 | serv_packet_size = DIC_HEADER;
|
---|
1886 | }
|
---|
1887 |
|
---|
1888 | strncpy( dic_packet->service_name, servp->serv_name, MAX_NAME );
|
---|
1889 | type = servp->type;
|
---|
1890 | if(servp->stamped)
|
---|
1891 | type |= STAMPED;
|
---|
1892 | dic_packet->type = htovl(type);
|
---|
1893 | dic_packet->timeout = htovl(servp->timeout);
|
---|
1894 | dic_packet->service_id = htovl(servp->serv_id);
|
---|
1895 | dic_packet->format = htovl(MY_FORMAT);
|
---|
1896 | dic_packet->size = htovl(DIC_HEADER);
|
---|
1897 | ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER);
|
---|
1898 | if(!ret)
|
---|
1899 | {
|
---|
1900 | dim_print_date_time();
|
---|
1901 | printf(" Client Sending Service Request: Couldn't write to Conn %3d : Server %s@%s service %s\n",
|
---|
1902 | conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node, servp->serv_name);
|
---|
1903 | fflush(stdout);
|
---|
1904 | }
|
---|
1905 | return(ret);
|
---|
1906 | }
|
---|
1907 |
|
---|
1908 | typedef struct
|
---|
1909 | {
|
---|
1910 | int ret_code;
|
---|
1911 | int serv_id;
|
---|
1912 | } CMNDCB_ITEM;
|
---|
1913 |
|
---|
1914 | void do_cmnd_callback(CMNDCB_ITEM *itemp)
|
---|
1915 | {
|
---|
1916 |
|
---|
1917 | DIC_SERVICE *servp;
|
---|
1918 | int ret, serv_id;
|
---|
1919 | /*
|
---|
1920 | itemp = (CMNDCB_ITEM *)id_get_ptr(id, SRC_DIC);
|
---|
1921 | */
|
---|
1922 | serv_id = itemp->serv_id;
|
---|
1923 | ret = itemp->ret_code;
|
---|
1924 | servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
|
---|
1925 | if(servp)
|
---|
1926 | {
|
---|
1927 | if(servp->serv_id == serv_id)
|
---|
1928 | {
|
---|
1929 | Curr_conn_id = servp->conn_id;
|
---|
1930 | (servp->user_routine)( &servp->tag, &ret );
|
---|
1931 | servp->pending = NOT_PENDING;
|
---|
1932 | end_command(servp, ret);
|
---|
1933 | Curr_conn_id = 0;
|
---|
1934 | }
|
---|
1935 | }
|
---|
1936 | /*
|
---|
1937 | id_free(id, SRC_DIC);
|
---|
1938 | */
|
---|
1939 | free(itemp);
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 | int send_command(int conn_id, DIC_SERVICE *servp)
|
---|
1943 | {
|
---|
1944 | static DIC_PACKET *dic_packet;
|
---|
1945 | static int cmnd_packet_size = 0;
|
---|
1946 | register int size;
|
---|
1947 | int ret;
|
---|
1948 | CMNDCB_ITEM *itemp;
|
---|
1949 |
|
---|
1950 | size = servp->fill_size;
|
---|
1951 |
|
---|
1952 | if(size < 0)
|
---|
1953 | return(1);
|
---|
1954 |
|
---|
1955 | if( !cmnd_packet_size ) {
|
---|
1956 | dic_packet = (DIC_PACKET *)malloc(DIC_HEADER + size);
|
---|
1957 | cmnd_packet_size = DIC_HEADER + size;
|
---|
1958 | }
|
---|
1959 | else
|
---|
1960 | {
|
---|
1961 | if( DIC_HEADER + size > cmnd_packet_size ) {
|
---|
1962 | free( dic_packet );
|
---|
1963 | dic_packet = (DIC_PACKET *)malloc(DIC_HEADER + size);
|
---|
1964 | cmnd_packet_size = DIC_HEADER + size;
|
---|
1965 | }
|
---|
1966 | }
|
---|
1967 |
|
---|
1968 | strncpy(dic_packet->service_name, servp->serv_name, MAX_NAME);
|
---|
1969 | dic_packet->type = htovl(COMMAND);
|
---|
1970 | dic_packet->timeout = htovl(0);
|
---|
1971 | dic_packet->format = htovl(MY_FORMAT);
|
---|
1972 |
|
---|
1973 | dic_packet->service_id = /*id_get((void *)servp)*/servp->serv_id;
|
---|
1974 |
|
---|
1975 | size = copy_swap_buffer_out(servp->format, servp->format_data,
|
---|
1976 | dic_packet->buffer, servp->fill_address,
|
---|
1977 | size);
|
---|
1978 | dic_packet->size = htovl( size + DIC_HEADER);
|
---|
1979 | if( servp->user_routine )
|
---|
1980 | {
|
---|
1981 | servp->pending = WAITING_CMND_ANSWER;
|
---|
1982 | ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
|
---|
1983 | itemp = (CMNDCB_ITEM *)malloc(sizeof(CMNDCB_ITEM));
|
---|
1984 | itemp->serv_id = servp->serv_id;
|
---|
1985 | itemp->ret_code = ret;
|
---|
1986 | /*
|
---|
1987 | id = id_get((void *)itemp, SRC_DIC);
|
---|
1988 | */
|
---|
1989 | dtq_start_timer(0, do_cmnd_callback, (dim_long)itemp);
|
---|
1990 | /*
|
---|
1991 | (servp->user_routine)( &servp->tag, &ret );
|
---|
1992 | */
|
---|
1993 | }
|
---|
1994 | else
|
---|
1995 | {
|
---|
1996 | ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
|
---|
1997 | }
|
---|
1998 | /*
|
---|
1999 | if(!ret)
|
---|
2000 | {
|
---|
2001 | servp->pending = WAITING_DNS_UP;
|
---|
2002 | dic_release_service( servp->serv_id );
|
---|
2003 | }
|
---|
2004 | */
|
---|
2005 | /*
|
---|
2006 | ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
|
---|
2007 | if(!ret)
|
---|
2008 | {
|
---|
2009 | servp->pending = WAITING_DNS_UP;
|
---|
2010 | dic_release_service( servp->serv_id );
|
---|
2011 | }
|
---|
2012 | else
|
---|
2013 | {
|
---|
2014 | dim_usleep(5000);
|
---|
2015 | if( servp->user_routine )
|
---|
2016 | (servp->user_routine)( &servp->tag, &ret );
|
---|
2017 | }
|
---|
2018 | */
|
---|
2019 | if(!ret)
|
---|
2020 | {
|
---|
2021 | dim_print_date_time();
|
---|
2022 | printf(" Client Sending Command: Couldn't write to Conn %3d : Server %s@%s\n",conn_id,
|
---|
2023 | Net_conns[conn_id].task, Net_conns[conn_id].node);
|
---|
2024 | fflush(stdout);
|
---|
2025 | }
|
---|
2026 | return(ret);
|
---|
2027 | }
|
---|
2028 |
|
---|
2029 | int find_connection(char *node, char *task, int port)
|
---|
2030 | {
|
---|
2031 | register int i;
|
---|
2032 | register DIC_CONNECTION *dic_connp;
|
---|
2033 |
|
---|
2034 | if(task){}
|
---|
2035 | for( i=0, dic_connp = Dic_conns; i<Curr_N_Conns; i++, dic_connp++ )
|
---|
2036 | {
|
---|
2037 | /*
|
---|
2038 | if((!strcmp(dic_connp->task_name, task))
|
---|
2039 | &&(!strcmp(dic_connp->node_name, node)))
|
---|
2040 | */
|
---|
2041 | if((!strcmp(dic_connp->node_name, node))
|
---|
2042 | && (dic_connp->port == port))
|
---|
2043 | return(i);
|
---|
2044 | }
|
---|
2045 | return(0);
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 | int dic_get_id(char *name)
|
---|
2049 | {
|
---|
2050 | extern int get_proc_name(char *name);
|
---|
2051 |
|
---|
2052 | get_proc_name(name);
|
---|
2053 | strcat(name,"@");
|
---|
2054 | get_node_name(&name[strlen(name)]);
|
---|
2055 | return(1);
|
---|
2056 | }
|
---|
2057 |
|
---|
2058 | #ifdef VxWorks
|
---|
2059 | void dic_destroy(int tid)
|
---|
2060 | {
|
---|
2061 | register int i;
|
---|
2062 | register DIC_CONNECTION *dic_connp;
|
---|
2063 | register DIC_SERVICE *servp, *auxp;
|
---|
2064 | int found = 0;
|
---|
2065 |
|
---|
2066 | if(!Dic_conns)
|
---|
2067 | return;
|
---|
2068 | for( i=0, dic_connp = Dic_conns; i<Curr_N_Conns; i++, dic_connp++ )
|
---|
2069 | {
|
---|
2070 | if(servp = (DIC_SERVICE *) dic_connp->service_head)
|
---|
2071 | {
|
---|
2072 | while( servp = (DIC_SERVICE *) dll_get_next(
|
---|
2073 | (DLL *) dic_connp->service_head,
|
---|
2074 | (DLL *) servp) )
|
---|
2075 | {
|
---|
2076 | if( servp->tid == tid )
|
---|
2077 | {
|
---|
2078 | auxp = servp->prev;
|
---|
2079 | dic_release_service( servp->serv_id );
|
---|
2080 | servp = auxp;
|
---|
2081 | if(!dic_connp->service_head)
|
---|
2082 | break;
|
---|
2083 | }
|
---|
2084 | else
|
---|
2085 | found = 1;
|
---|
2086 | }
|
---|
2087 | }
|
---|
2088 | }
|
---|
2089 | if(!found)
|
---|
2090 | {
|
---|
2091 | if(Dns_dic_conn_id > 0)
|
---|
2092 | {
|
---|
2093 | dna_close( Dns_dic_conn_id );
|
---|
2094 | Dns_dic_conn_id = 0;
|
---|
2095 | }
|
---|
2096 | }
|
---|
2097 | }
|
---|
2098 |
|
---|
2099 | void DIMDestroy(int tid)
|
---|
2100 | {
|
---|
2101 | dis_destroy(tid);
|
---|
2102 | dic_destroy(tid);
|
---|
2103 | }
|
---|
2104 |
|
---|
2105 | #endif
|
---|
2106 |
|
---|
2107 | static void release_conn(int conn_id)
|
---|
2108 | {
|
---|
2109 | register DIC_CONNECTION *dic_connp = &Dic_conns[conn_id];
|
---|
2110 |
|
---|
2111 | if(Debug_on)
|
---|
2112 | {
|
---|
2113 | dim_print_date_time();
|
---|
2114 | printf("Conn %d, Server %s on node %s completely released\n",
|
---|
2115 | conn_id, dic_connp->task_name, dic_connp->node_name);
|
---|
2116 | fflush(stdout);
|
---|
2117 | }
|
---|
2118 | dic_connp->task_name[0] = '\0';
|
---|
2119 | dic_connp->port = 0;
|
---|
2120 | if(dic_connp->service_head)
|
---|
2121 | {
|
---|
2122 | free((DIC_SERVICE *)dic_connp->service_head);
|
---|
2123 | dic_connp->service_head = (char *)0;
|
---|
2124 | }
|
---|
2125 | dna_close(conn_id);
|
---|
2126 | }
|
---|
2127 |
|
---|
2128 | void dic_close_dns()
|
---|
2129 | {
|
---|
2130 | register DIC_SERVICE *servp, *auxp;
|
---|
2131 |
|
---|
2132 | if(Dns_dic_conn_id > 0)
|
---|
2133 | {
|
---|
2134 | if( (servp = (DIC_SERVICE *) Cmnd_head) )
|
---|
2135 | {
|
---|
2136 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
2137 | (DLL *) Cmnd_head,
|
---|
2138 | (DLL *) servp)) )
|
---|
2139 | {
|
---|
2140 | #ifdef DEBUG
|
---|
2141 | printf("\t%s was in the Command list\n", servp->serv_name);
|
---|
2142 | printf("type = %d, pending = %d\n",servp->type, servp->pending);
|
---|
2143 | fflush(stdout);
|
---|
2144 | #endif
|
---|
2145 | auxp = servp->prev;
|
---|
2146 | if( (servp->type == ONCE_ONLY ) &&
|
---|
2147 | (servp->pending == WAITING_SERVER_UP))
|
---|
2148 | {
|
---|
2149 | service_tmout( servp->serv_id );
|
---|
2150 | }
|
---|
2151 | else if( (servp->type == COMMAND ) &&
|
---|
2152 | (servp->pending == WAITING_CMND_ANSWER))
|
---|
2153 | {
|
---|
2154 | service_tmout( servp->serv_id );
|
---|
2155 | }
|
---|
2156 | else
|
---|
2157 | {
|
---|
2158 | servp->pending = WAITING_DNS_UP;
|
---|
2159 | dic_release_service( servp->serv_id );
|
---|
2160 | }
|
---|
2161 | servp = auxp;
|
---|
2162 | }
|
---|
2163 | }
|
---|
2164 | dna_close( Dns_dic_conn_id );
|
---|
2165 | Dns_dic_conn_id = 0;
|
---|
2166 | }
|
---|
2167 | }
|
---|
2168 | /*
|
---|
2169 | append_service(service_info_buffer, servp)
|
---|
2170 | char *service_info_buffer;
|
---|
2171 | SERVICE *servp;
|
---|
2172 | {
|
---|
2173 | char name[MAX_NAME], *ptr;
|
---|
2174 |
|
---|
2175 | if(strstr(servp->name,"/RpcIn"))
|
---|
2176 | {
|
---|
2177 | strcpy(name,servp->name);
|
---|
2178 | ptr = (char *)strstr(name,"/RpcIn");
|
---|
2179 | *ptr = 0;
|
---|
2180 | strcat(service_info_buffer, name);
|
---|
2181 | strcat(service_info_buffer, "|");
|
---|
2182 | if(servp->def[0])
|
---|
2183 | {
|
---|
2184 | strcat(service_info_buffer, servp->def);
|
---|
2185 | }
|
---|
2186 | strcat(name,"/RpcOut");
|
---|
2187 | if(servp = find_service(name))
|
---|
2188 | {
|
---|
2189 | strcat(service_info_buffer, ",");
|
---|
2190 | if(servp->def[0])
|
---|
2191 | {
|
---|
2192 | strcat(service_info_buffer, servp->def);
|
---|
2193 | }
|
---|
2194 | }
|
---|
2195 | strcat(service_info_buffer, "|RPC");
|
---|
2196 | strcat(service_info_buffer, "\n");
|
---|
2197 | }
|
---|
2198 | else if(strstr(servp->name,"/RpcOut"))
|
---|
2199 | {
|
---|
2200 | }
|
---|
2201 | else
|
---|
2202 | {
|
---|
2203 | strcat(service_info_buffer, servp->name);
|
---|
2204 | strcat(service_info_buffer, "|");
|
---|
2205 | if(servp->def[0])
|
---|
2206 | {
|
---|
2207 | strcat(service_info_buffer, servp->def);
|
---|
2208 | }
|
---|
2209 | strcat(service_info_buffer, "|");
|
---|
2210 | if(servp->type == COMMAND)
|
---|
2211 | {
|
---|
2212 | strcat(service_info_buffer, "CMD");
|
---|
2213 | }
|
---|
2214 | strcat(service_info_buffer, "\n");
|
---|
2215 | }
|
---|
2216 | }
|
---|
2217 | */
|
---|
2218 |
|
---|
2219 | char *dic_get_error_services()
|
---|
2220 | {
|
---|
2221 | return(dic_get_server_services(Error_conn_id));
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | char *dic_get_server_services(int conn_id)
|
---|
2225 | {
|
---|
2226 | DIC_SERVICE *servp;
|
---|
2227 | DIC_CONNECTION *dic_connp;
|
---|
2228 | int n_services = 0;
|
---|
2229 | int max_size;
|
---|
2230 | static int curr_allocated_size = 0;
|
---|
2231 | static char *service_info_buffer;
|
---|
2232 | char *buff_ptr;
|
---|
2233 |
|
---|
2234 |
|
---|
2235 | if(!conn_id)
|
---|
2236 | return((char *)0);
|
---|
2237 | dic_connp = &Dic_conns[conn_id];
|
---|
2238 | if( (servp = (DIC_SERVICE *) dic_connp->service_head) )
|
---|
2239 | {
|
---|
2240 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
2241 | (DLL *) dic_connp->service_head,
|
---|
2242 | (DLL *) servp)) )
|
---|
2243 | {
|
---|
2244 | n_services++;
|
---|
2245 | }
|
---|
2246 | if(!n_services)
|
---|
2247 | return((char *)0);
|
---|
2248 | max_size = n_services * MAX_NAME;
|
---|
2249 | if(!curr_allocated_size)
|
---|
2250 | {
|
---|
2251 | service_info_buffer = (char *)malloc(max_size);
|
---|
2252 | curr_allocated_size = max_size;
|
---|
2253 | }
|
---|
2254 | else if (max_size > curr_allocated_size)
|
---|
2255 | {
|
---|
2256 | free(service_info_buffer);
|
---|
2257 | service_info_buffer = (char *)malloc(max_size);
|
---|
2258 | curr_allocated_size = max_size;
|
---|
2259 | }
|
---|
2260 | service_info_buffer[0] = '\0';
|
---|
2261 | buff_ptr = service_info_buffer;
|
---|
2262 |
|
---|
2263 | servp = (DIC_SERVICE *) dic_connp->service_head;
|
---|
2264 | while( (servp = (DIC_SERVICE *) dll_get_next(
|
---|
2265 | (DLL *) dic_connp->service_head,
|
---|
2266 | (DLL *) servp)) )
|
---|
2267 | {
|
---|
2268 | strcat(buff_ptr, servp->serv_name);
|
---|
2269 | strcat(buff_ptr, "\n");
|
---|
2270 | buff_ptr += strlen(buff_ptr);
|
---|
2271 | }
|
---|
2272 | }
|
---|
2273 | else
|
---|
2274 | {
|
---|
2275 | return((char *)0);
|
---|
2276 | }
|
---|
2277 | /*
|
---|
2278 | dim_print_date_time();
|
---|
2279 | printf("Server %s@%s provides services:\n",
|
---|
2280 | dic_connp->task_name, dic_connp->node_name);
|
---|
2281 | printf("%s\n",service_info_buffer);
|
---|
2282 | */
|
---|
2283 | return(service_info_buffer);
|
---|
2284 | }
|
---|
2285 |
|
---|
2286 | int dic_get_conn_id()
|
---|
2287 | {
|
---|
2288 | return(Curr_conn_id);
|
---|
2289 | }
|
---|
2290 |
|
---|
2291 | int dic_get_server(char *name)
|
---|
2292 | {
|
---|
2293 | int ret = 0;
|
---|
2294 | char node[MAX_NODE_NAME], task[MAX_TASK_NAME];
|
---|
2295 |
|
---|
2296 | DISABLE_AST
|
---|
2297 |
|
---|
2298 | if(Curr_conn_id)
|
---|
2299 | {
|
---|
2300 | dna_get_node_task(Curr_conn_id, node, task);
|
---|
2301 | strcpy(name,task);
|
---|
2302 | strcat(name,"@");
|
---|
2303 | strcat(name,node);
|
---|
2304 | ret = Curr_conn_id;
|
---|
2305 | }
|
---|
2306 | ENABLE_AST
|
---|
2307 | return(ret);
|
---|
2308 | }
|
---|
2309 |
|
---|
2310 | int dic_get_server_pid(int *pid)
|
---|
2311 | {
|
---|
2312 | int ret = 0;
|
---|
2313 |
|
---|
2314 | DISABLE_AST
|
---|
2315 |
|
---|
2316 | *pid = 0;
|
---|
2317 | if(Curr_conn_id)
|
---|
2318 | {
|
---|
2319 | *pid = Dic_conns[Curr_conn_id].pid;
|
---|
2320 | ret = Curr_conn_id;
|
---|
2321 | }
|
---|
2322 | ENABLE_AST
|
---|
2323 | return(ret);
|
---|
2324 | }
|
---|
2325 |
|
---|
2326 | void dic_stop()
|
---|
2327 | {
|
---|
2328 | int dic_find_server_conns();
|
---|
2329 |
|
---|
2330 | dtq_delete(Dic_timer_q);
|
---|
2331 | dic_close_dns();
|
---|
2332 | if(!dic_find_server_conns())
|
---|
2333 | dim_stop();
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | int dic_find_server_conns()
|
---|
2337 | {
|
---|
2338 | int i;
|
---|
2339 | int n = 0;
|
---|
2340 |
|
---|
2341 | for( i = 0; i< Curr_N_Conns; i++ )
|
---|
2342 | {
|
---|
2343 | if(Net_conns[i].channel != 0)
|
---|
2344 | {
|
---|
2345 | if(Dna_conns[i].read_ast == recv_rout)
|
---|
2346 | {
|
---|
2347 | dna_close(i);
|
---|
2348 | }
|
---|
2349 | else
|
---|
2350 | {
|
---|
2351 | n++;
|
---|
2352 | }
|
---|
2353 | }
|
---|
2354 | }
|
---|
2355 | return(n);
|
---|
2356 | }
|
---|
2357 |
|
---|
2358 | #ifdef VMS
|
---|
2359 | /* CFORTRAN WRAPPERS */
|
---|
2360 | FCALLSCFUN9(INT, dic_info_service, DIC_INFO_SERVICE, dic_info_service,
|
---|
2361 | STRING, INT, INT, PVOID, INT, PVOID, INT, PVOID, INT)
|
---|
2362 | FCALLSCFUN9(INT, dic_info_service_stamped, DIC_INFO_SERVICE_STAMPED,
|
---|
2363 | dic_info_service_stamped,
|
---|
2364 | STRING, INT, INT, PVOID, INT, PVOID, INT, PVOID, INT)
|
---|
2365 | FCALLSCFUN3(INT, dic_cmnd_service, DIC_CMND_SERVICE, dic_cmnd_service,
|
---|
2366 | STRING, PVOID, INT)
|
---|
2367 | FCALLSCFUN5(INT, dic_cmnd_callback, DIC_CMND_CALLBACK, dic_cmnd_callback,
|
---|
2368 | STRING, PVOID, INT, PVOID, INT)
|
---|
2369 | FCALLSCFUN3(INT, dic_cmnd_service_stamped, DIC_CMND_SERVICE_STAMPED,
|
---|
2370 | dic_cmnd_service_stamped,
|
---|
2371 | STRING, PVOID, INT)
|
---|
2372 | FCALLSCFUN5(INT, dic_cmnd_callback_stamped, DIC_CMND_CALLBACK_STAMPED,
|
---|
2373 | dic_cmnd_callback_stamped,
|
---|
2374 | STRING, PVOID, INT, PVOID, INT)
|
---|
2375 | FCALLSCSUB3( dic_change_address, DIC_CHANGE_ADDRESS, dic_change_address,
|
---|
2376 | INT, PVOID, INT)
|
---|
2377 | FCALLSCSUB1( dic_release_service, DIC_RELEASE_SERVICE, dic_release_service,
|
---|
2378 | INT)
|
---|
2379 | FCALLSCFUN1(INT, dic_get_quality, DIC_GET_QUALITY, dic_get_quality,
|
---|
2380 | INT)
|
---|
2381 | FCALLSCFUN3(INT, dic_get_timestamp, DIC_GET_TIMESTAMP, dic_get_timestamp,
|
---|
2382 | INT,PINT,PINT)
|
---|
2383 | FCALLSCFUN1(INT, dic_get_id, DIC_GET_ID, dic_get_id,
|
---|
2384 | PSTRING)
|
---|
2385 | FCALLSCFUN1(STRING, dic_get_format, DIC_GET_FORMAT, dic_get_format,
|
---|
2386 | INT)
|
---|
2387 | #endif
|
---|