]> andersk Git - moira.git/blame - gdb/gdb_ops.c
added prefix field to subnet table
[moira.git] / gdb / gdb_ops.c
CommitLineData
5580185e 1/*
097e9b93 2 * $Source$
3 * $Header$
5580185e 4 */
5
6#ifndef lint
7static char *rcsid_gdb_ops_c = "$Header$";
8#endif lint
9
10
097e9b93 11/************************************************************************
12 *
13 * gdb_ops.c
14 *
15 * GDB - Asynchronous Operations and Their Synchronous
16 * Counterparts
17 *
18 * Author: Noah Mendelsohn
19 * Copyright: 1986 MIT Project Athena
20 * For copying and distribution information, please see
21 * the file <mit-copyright.h>.
22 *
23 * These routines provide a suite of asynchronous operations
24 * on connections.
25 *
26 ************************************************************************/
5580185e 27
0a5ff702 28#include <mit-copyright.h>
5580185e 29#include <stdio.h>
30#include "gdb.h"
31#include <netinet/in.h>
32#include <sys/ioctl.h>
097e9b93 33#ifdef SOLARIS
34#include <sys/filio.h>
35#endif
5580185e 36#ifdef vax
37extern u_long htonl();
38#endif vax
097e9b93 39
40
41/************************************************************************
42 *
43 * send_object (send_object)
44 *
45 * Synchronous form of start_sending_object. Returns either
46 * OP_CANCELLED, or OP_RESULT(op).
47 *
48 ************************************************************************/
5580185e 49
50int
51send_object(con, objp, type)
52CONNECTION con;
53char *objp;
54int type;
55{
56 register OPERATION op;
57 register int retval;
58
59
60 op = create_operation();
61 start_sending_object(op, con, objp, type);
62 (void) complete_operation(op);
63 if (OP_STATUS(op) == OP_COMPLETE)
64 retval = OP_RESULT(op);
65 else
66 retval = OP_STATUS(op);
67 delete_operation(op);
68 return retval;
69}
097e9b93 70
71
5580185e 72/************************************************************************/
73/*
74/* start_send_object (g_snobj)
75/*
76/* Start the asynchronous transmission of a gdb object.
77/* Note that this routine must be passed the address of the object,
78/* not the object itself.
79/*
80/* The following three routines work together, and may be considered
81/* as a single entity implementing the operation. The first merely
82/* saves away its arguments and queues the operation on the designated
83/* connection. These stay there until they percolate to the head of
84/* the queue. The second is the initialization routine, which is
85/* called by the connection maintenance logic when the operation
86/* first reaches the head of the queue. This routine encodes
87/* the supplied data for transmission, and then sends it. If the
88/* transmission executes synchronously, then the third routine is
89/* called immediately to clean up. If not, the third routine is
90/* marked as the 'continuation' routine, which will cause its
91/* invocation when the transmission completes.
92/*
93/* The data is preceded by its length expressed as a long in
94/* network byte order.
95/*
96/************************************************************************/
97
98struct obj_data {
99 char *objp; /* address of the object to */
100 /* be sent */
101 int type; /* type code for the object */
102 /* to be sent*/
103 char *flattened; /* address of first byte */
104 /* of flattened data */
105 int len; /* length of the flattened */
106 /* data */
107};
108
109int g_isnobj();
110int g_csnobj();
111
112int
113start_sending_object(op, con, objp, type)
114OPERATION op;
115CONNECTION con;
116char *objp;
117int type;
118{
119 struct obj_data *arg;
120
121 /*
122 * Make sure the supplied connection is a legal one
123 */
124 GDB_CHECK_CON(con, "start_sending_object")
125 GDB_CHECK_OP(op, "start_sending_object")
126
127 arg = (struct obj_data *)db_alloc(sizeof(struct obj_data));
128
129 arg->objp = objp;
130 arg->type = type;
131 initialize_operation(op, g_isnobj, (char *)arg, (int (*)())NULL);
132 (void) queue_operation(con, CON_OUTPUT, op);
133}
134
135 /*----------------------------------------------------------*/
136 /*
137 /* g_isnobj
138 /*
139 /* Init routine for sending an object. This routine is
140 /* called by the connection management logic when the send
141 /* request percolates to the top of the queue. This routine
142 /* reformats the data into an appropriate form for transmission.
143 /* The format used is a length, represented as a long in
144 /* network byte order, followed by the data itself. The
145 /* continuation routine below is called, either synchronously
146 /* or asynchronously, once the transmission is complete.
147 /*
148 /*----------------------------------------------------------*/
149
150int
151g_isnobj(op, hcon, arg)
152OPERATION op;
153HALF_CONNECTION hcon;
154struct obj_data *arg;
155{
156 /*
157 * Find out the encoded length of the data
158 */
159 arg->len = FCN_PROPERTY(arg->type, CODED_LENGTH_PROPERTY)
160 (arg->objp, hcon);
161
162 /*
163 * Allocate space and flatten (encode) the data
164 */
165 arg->flattened = db_alloc(arg->len+sizeof(long));
166 *(u_long *)arg->flattened = htonl((u_long)arg->len);
167
168 FCN_PROPERTY(arg->type, ENCODE_PROPERTY)
169 (arg->objp, hcon, arg->flattened+sizeof(long));
170
171 /*
172 * Set up continuation routine in case it's needed after the return
173 */
174 op->fcn.cont = g_csnobj;
175
176 /*
177 * Start sending the data, maybe even complete
178 */
179 if (gdb_send_data(hcon, arg->flattened, arg->len + sizeof(long)) ==
180 OP_COMPLETE) {
181 return g_csnobj(op, hcon, arg) ;/* this return is a little */
182 /* subtle. As continuation */
183 /* routines call each other */
184 /* synchronously, the last */
185 /* one determines whether we */
186 /* completed or are still */
187 /* running. That status */
188 /* percolates back through */
189 /* the entire call chain. */
190 } else {
191 return OP_RUNNING;
192 }
193}
194
195
196
197
198
199
200 /*----------------------------------------------------------*/
201 /*
202 /* g_csnobj
203 /*
204 /* Continuation routine for sending an object. Since there is
205 /* only one transmission, started by the init routine, this is
206 /* called when that transmission is done, and it does all the
207 /* associated clean up.
208 /*
209 /*----------------------------------------------------------*/
210
24582af9 211/*ARGSUSED*/
5580185e 212int
213g_csnobj(op, hcon, arg)
214OPERATION op;
215HALF_CONNECTION hcon;
216struct obj_data *arg;
217{
218 op->result = OP_SUCCESS;
219 db_free((char *)arg->flattened, arg->len + sizeof(long));
220 /* free the sent data */
221 db_free((char *)arg, sizeof(struct obj_data)); /* free the state structure */
222 return OP_COMPLETE;
223}
224
097e9b93 225
5580185e 226/************************************************************************/
227/*
228/* receive_object (receive_object)
229/*
230/* Synchronous form of start_receiving_object. Returns either
231/* OP_CANCELLED, or OP_RESULT(op).
232/*
233/************************************************************************/
234
235int
236receive_object(con, objp, type)
237CONNECTION con;
238char *objp;
239int type;
240{
241 register OPERATION op;
242 register int retval;
243
244 op = create_operation();
245 start_receiving_object(op, con, objp, type);
246 (void) complete_operation(op);
247 if (OP_STATUS(op) == OP_COMPLETE)
248 retval = OP_RESULT(op);
249 else
250 retval = OP_STATUS(op);
251 delete_operation(op);
252 return retval;
253}
097e9b93 254
255
5580185e 256/************************************************************************/
257/*
258/* start_receiving_object (g_rcobj)
259/*
260/* Start the asynchronous receipt of a gdb object. Note that this
261/* routine must be passed the address of the object, not the object
262/* itself. In the case of structured objects, this routine may
263/* allocate the necessary storage. The work to build the object is
264/* done by the object's decode routine.
265/*
266/* The following three routines work together, and may be considered
267/* as a single entity implementing the operation. The first merely
268/* saves away its arguments and queues the operation on the designated
269/* connection. These stay there until they percolate to the head of
270/* the queue. The second is the initialization routine, which is
271/* called by the connection maintenance logic when the operation
272/* first reaches the head of the queue. This routine initiates a read
273/* for the length of the object, and sets up a continuation routine
274/* to read the object itself. When the object itself has been read, it
275/* is decoded and the operation completes.
276/*
277/* The data is preceded by its length expressed as a long in
278/* network byte order.
279/*
280/* preempt_and_start_receiving_object (g_prcobj)
281/*
282/* Similar to above, but may be called only from an active operation
283/* (i.e. an init or continue routine) on an inbound half connection.
284/* The receive effectively pre-empts the old operation, which wil
285/* continue after the receive is done.
286/*
287/*
288/************************************************************************/
289
290struct robj_data {
291 char *objp; /* address of the object to */
292 /* be received */
293 int type; /* type code for the object */
294 /* to be received */
295 char *flattened; /* address of first byte */
296 /* of flattened data */
297 int len; /* length of the flattened */
298 /* data */
299};
300
301int g_ircobj();
302int g_c1rcobj();
303int g_c2rcobj();
304
305 /*----------------------------------------------------------*/
306 /*
307 /* start_receiving_object
308 /*
309 /*----------------------------------------------------------*/
310
311int
312start_receiving_object(op, con, objp, type)
313OPERATION op;
314CONNECTION con;
315char *objp;
316int type;
317{
318 struct robj_data *arg;
319
320 /*
321 * Make sure the supplied connection is a legal one
322 */
323 GDB_CHECK_CON(con, "start_receiving_object")
324 GDB_CHECK_OP(op, "start_receiving_object")
325
326 arg = (struct robj_data *)db_alloc(sizeof(struct robj_data));
327
328 arg->objp = objp;
329 arg->type = type;
330 initialize_operation(op, g_ircobj, (char *)arg, (int (*)())NULL);
331 (void) queue_operation(con, CON_INPUT, op);
332}
333
334 /*----------------------------------------------------------*/
335 /*
336 /* preempt_and_start_receiving_object
337 /*
338 /*----------------------------------------------------------*/
339
340int
341preempt_and_start_receiving_object(op, oldop, objp, type)
342OPERATION op;
343OPERATION oldop;
344char *objp;
345int type;
346{
347 struct robj_data *arg;
348
349 /*
350 * Make sure the supplied connection is a legal one
351 */
352 GDB_CHECK_OP(op, "preempt_and_start_receiving_object")
353 GDB_CHECK_OP(oldop, "preempt_and_start_receiving_object")
354
355 arg = (struct robj_data *)db_alloc(sizeof(struct robj_data));
356
357 arg->objp = objp;
358 arg->type = type;
359 initialize_operation(op, g_ircobj, (char *)arg, (int (*)())NULL);
360 (void) g_preempt_me(oldop, op);
361}
362
363 /*----------------------------------------------------------*/
364 /*
365 /* g_ircobj
366 /*
367 /* Initialization routine for receiving an object.
368 /* Called when the receive operation percolates to the
369 /* top of the queue. First, we must receive the single
370 /* 'long' which carries the length of the rest of the data.
371 /* We do that now, either synchronously or asynchronously.
372 /*
373 /*----------------------------------------------------------*/
374
375int
376g_ircobj(op, hcon, arg)
377OPERATION op;
378HALF_CONNECTION hcon;
379struct robj_data *arg;
380{
381 op->fcn.cont = g_c1rcobj;
382 if(gdb_receive_data(hcon, (char *)&(arg->len), sizeof(long)) == OP_COMPLETE) {
383 return g_c1rcobj(op, hcon, arg);/* this return is a little */
384 /* subtle. As continuation */
385 /* routines call each other */
386 /* synchronously, the last */
387 /* one determines whether we */
388 /* completed or are still */
389 /* running. That status */
390 /* percolates back through */
391 /* the entire call chain. */
392 } else {
393 return OP_RUNNING;
394 }
395}
396
397 /*----------------------------------------------------------*/
398 /*
399 /* g_c1rcobj
400 /*
401 /* At this point, we have received the length. Now, allocate
402 /* the space for the rest of the data, and start receiving
403 /* it.
404 /*
405 /*----------------------------------------------------------*/
406
407int
408g_c1rcobj(op, hcon, arg)
409OPERATION op;
410HALF_CONNECTION hcon;
411struct robj_data *arg;
412{
413#ifdef vax
414 extern u_long ntohl();
415#endif vax
416
417 /*
418 * Now we know the length of the encoded data, convert the length
419 * to local byte order, and allocate the space for the receive.
420 */
421 arg->len = (int) ntohl((u_long)arg->len);
b1fb7b0c 422 if (arg->len > 65536)
423 return OP_CANCELLED;
5580185e 424
425 arg->flattened = db_alloc(arg->len);
b1fb7b0c 426 if (arg->flattened == NULL)
427 return OP_CANCELLED;
5580185e 428 /*
429 * Now start receiving the encoded object itself. If it all comes in
430 * synchronously, then just go on to the c2 routine to decode it and
431 * finish up. Else return OP_RUNNING, so the rest of the system
432 * can get some work done while we wait.
433 */
434 op->fcn.cont = g_c2rcobj;
435 if(gdb_receive_data(hcon, arg->flattened, arg->len ) == OP_COMPLETE) {
436 return g_c2rcobj(op, hcon, arg);
437 } else {
438 return OP_RUNNING;
439 }
440}
441
442 /*----------------------------------------------------------*/
443 /*
444 /* g_c2rcobj
445 /*
446 /* At this point, all the data has been received. Decode
447 /* it into the place provided by the caller, free all
448 /* temporarily allocated memory, and return.
449 /*
450 /*----------------------------------------------------------*/
451
452int
453g_c2rcobj(op, hcon, arg)
454OPERATION op;
455HALF_CONNECTION hcon;
456struct robj_data *arg;
457{
458 /*
459 * Decode the received data into local representation.
460 */
461 FCN_PROPERTY(arg->type, DECODE_PROPERTY)
462 (arg->objp, hcon, arg->flattened);
463 op->result = OP_SUCCESS;
464 db_free(arg->flattened, arg->len); /* free the received data */
465 db_free((char *)arg, sizeof(struct robj_data)); /* free the state structure */
466 return OP_COMPLETE;
467}
097e9b93 468
469
5580185e 470/************************************************************************/
471/*
472/* complete_operation(complete_operation)
473/*
474/* Wait for a given operation to complete, allowing everything
475/* to progress in the meantime. Returns the last known status
476/* of the operation, which in general will be OP_COMPLETE unless
477/* errors were encountered (and this version of the code doesn't
478/* do error handing right anyway!)
479/*
480/* We do this by (1) calling gdb_progress to assure that all
481/* possible progress has been made, which is always a good thing
482/* to do when we get the chance and (2) looping on calls to
483/* con_select, which will make all possible future progress,
484/* but without burning cycles unnecessarily in the process.
485/*
486/************************************************************************/
487
488int
489complete_operation(op)
490OPERATION op;
491{
492 (void) gdb_progress();
493
494 while(op->status != OP_COMPLETE && op->status != OP_CANCELLED)
495 (void) con_select(0, (fd_set *)NULL, (fd_set *)NULL,
496 (fd_set *)NULL, (struct timeval *)NULL);
497
498 return op->status;
499
500}
501
097e9b93 502
5580185e 503/************************************************************************/
504/*
505/* cancel_operation(cancel_operation)
506/*
507/* Attempts to cancel an operation.
508/*
509/************************************************************************/
510
511int
512cancel_operation(op)
513OPERATION op;
514{
515 register HALF_CONNECTION hcon = op->halfcon;
516
517 if (op->status != OP_RUNNING && op->status != OP_QUEUED)
518 return op->status;
519
520 if (hcon == NULL)
521 GDB_GIVEUP("cancel_operation: operation is queued but half connection is unknown")
522
523 /*
524 * If we're at the head of the queue and running, then we have to
525 * call the cancelation routine for this particular operation so
526 * it can clean up.
527 */
528 if (op->prev == (OPERATION)hcon) {
529 if (op->status == OP_RUNNING && op->cancel != NULL)
530 (*op->cancel)(op->halfcon, op->arg);
531 }
532
533 /*
534 * Looks safe, now cancel it.
535 */
536 op->next->prev = op->prev; /* de-q it */
537 op->prev->next = op->next; /* " " " */
538 op->status = OP_CANCELLED;
539 op->halfcon = NULL;
540
541 return OP_CANCELLED;
542}
097e9b93 543
544
5580185e 545/************************************************************************/
546/*
547/* start_listening
548/*
549/* Start the asynchronous acquisition of a connection. This
550/* results in the queuing of a GDB "OPERATION" to do the
551/* requested listening.
552/*
553/************************************************************************/
554
555struct lis_data {
556 char *otherside; /* data returned from an */
557 /* accept */
558 int *otherlen; /* length of the otherside */
559 /* field */
560 int *fdp; /* ptr to the fd of the */
561 /* newly accepted */
562 /* connection */
563};
564
565int g_ilis();
566int g_clis();
567
b1fb7b0c 568void
5580185e 569gdb_start_listening(op, con, otherside, lenp, fdp)
570OPERATION op;
571CONNECTION con;
572char *otherside;
573int *lenp;
574int *fdp;
575{
576 struct lis_data *arg;
577
578 GDB_INIT_CHECK
579
580 /*
581 * Make sure the supplied connection is a legal one
582 */
583 GDB_CHECK_CON(con, "start_listening")
584 GDB_CHECK_OP(op, "start_listening")
585
586 arg = (struct lis_data *)db_alloc(sizeof(struct lis_data));
587
588 arg->otherside = otherside;
589 arg->otherlen = lenp;
590 arg->fdp = fdp;
591 initialize_operation(op, g_ilis, (char *)arg, (int (*)())NULL);
592 (void) queue_operation(con, CON_INPUT, op);
593}
594
595 /*----------------------------------------------------------*/
596 /*
597 /* g_ilis
598 /*
599 /* Init routine for doing a listen.
600 /*
601 /*----------------------------------------------------------*/
602
603int
604g_ilis(op, hcon, arg)
605OPERATION op;
606HALF_CONNECTION hcon;
607struct lis_data *arg;
608{
609 int rc;
610
611 /*
612 * Set up continuation routine in case it's needed after the return
613 */
614 op->fcn.cont = g_clis;
615
616 /*
617 * Try doing the listen now, and then decide whether to go
618 * right on to the continuation routine or to let things hang
619 * for the moment.
620 */
621 rc = gdb_start_a_listen(hcon, arg->otherside, arg->otherlen, arg->fdp);
622 if (rc==OP_COMPLETE) {
623 return g_clis(op, hcon, arg); /* this return is a little */
624 /* subtle. As continuation */
625 /* routines call each other */
626 /* synchronously, the last */
627 /* one determines whether we */
628 /* completed or are still */
629 /* running. That status */
630 /* percolates back through */
631 /* the entire call chain. */
632 } else {
633 return OP_RUNNING;
634 }
635}
636
637
638
639 /*----------------------------------------------------------*/
640 /*
641 /* g_clis
642 /*
643 /* Continuation routine for accepting a connection.
644 /*
645 /* At this point, the fd has been accepted and all
646 /* the necessary information given back to the caller.
647 /*
648 /*----------------------------------------------------------*/
649
24582af9 650/*ARGSUSED*/
5580185e 651int
652g_clis(op, hcon, arg)
653OPERATION op;
654HALF_CONNECTION hcon;
655struct lis_data *arg;
656{
657 op->result = OP_SUCCESS;
658 db_free((char *)arg, sizeof(struct lis_data));
659 /* free the state structure */
660 return OP_COMPLETE;
661}
662
097e9b93 663
5580185e 664/************************************************************************/
665/*
666/* start_accepting_client
667/*
668/* Start the asynchronous acquisition of a client. This queueable
669/* operation first tries to accept a connection. On this connection,
670/* it reads a startup string from the client, and then completes.
671/*
672/* The return values from this are not quite what you might expect.
673/* In general, the operation will show complete, rather than cancelled,
674/* if it gets as far as creating the new connection at all. If
675/* subsequent activities result in errors from system calls, then
676/* this operation will complete with a status of OP_COMPLETE and a
677/* result of OP_CANCELLED. In this case, the applications IS given
678/* a connection descriptor for the new connection, and that descriptor
679/* has an errno value indicating why the failure occurred. The
680/* caller must then sever this connection to free the descriptor.
681/*
682/************************************************************************/
683
684struct acc_data {
685 char *otherside; /* data returned from an */
686 /* accept */
687 int *otherlen; /* length of the otherside */
688 /* field */
689 OPERATION listenop; /* used to listen for */
690 /* the fd */
691 OPERATION receiveop; /* used when receiving */
692 /* tuple from the client */
693 CONNECTION con; /* the connection we're */
694 /* trying to create */
695 CONNECTION *conp; /* this is where the caller */
696 /* wants the connection */
697 /* returned */
698 TUPLE *tuplep; /* pointer to tuple we */
699 /* are going to receive */
700 /* from new client */
701};
702
703int g_iacc();
704int g_i2acc();
705
b1fb7b0c 706void
5580185e 707start_accepting_client(listencon, op, conp, otherside, lenp, tuplep)
708CONNECTION listencon;
709OPERATION op;
710CONNECTION *conp;
711char *otherside;
712int *lenp;
713TUPLE *tuplep;
714{
715 struct acc_data *arg;
716
717 GDB_INIT_CHECK
718
719 /*
720 * Make sure the supplied connection and operation are legal
721 */
722 GDB_CHECK_CON(listencon, "start_accepting_client")
723 GDB_CHECK_OP(op, "start_accepting_client")
724
725 arg = (struct acc_data *)db_alloc(sizeof(struct acc_data));
726
727 arg->otherside = otherside;
728 arg->otherlen = lenp;
729 arg->conp = conp;
730 *conp = NULL; /* in case we fail */
731 arg->listenop = create_operation();
732 arg->receiveop = create_operation();
733 arg->con = g_make_con();
734 arg->tuplep = tuplep;
735 *tuplep = NULL; /* in case we fail */
736
737 /*
738 * Queue an operation ahead of us which will accept an fd and
739 * put it in arg->con->in. As a byproduct, pick up the from
740 * information that we return to the caller.
741 */
742 gdb_start_listening(arg->listenop, listencon,
743 arg->otherside,
744 arg->otherlen, &(arg->con->in.fd));
745
746 /*
747 * Now queue us behind it. By the time we run our init routine,
748 * a connection should have been acquired.
749 */
750 initialize_operation(op, g_iacc, (char *)arg, (int (*)())NULL);
751 (void) queue_operation(listencon, CON_INPUT, op);
752}
753
754 /*----------------------------------------------------------*/
755 /*
756 /* g_iacc
757 /*
758 /* Init routine for accepting a connection. By the
759 /* time this runs, the listen has been done, the
760 /* 'from' data put in position for the caller, and
761 /* the fd plugged into the connection descriptor.
762 /* If all went well, fill out the connection descriptor
763 /* and then requeue us on that to do the receive of
764 /* the requested tuple.
765 /*
766 /*----------------------------------------------------------*/
767
24582af9 768/*ARGSUSED*/
5580185e 769int
770g_iacc(op, hcon, arg)
771OPERATION op;
772HALF_CONNECTION hcon;
773struct acc_data *arg;
774{
775 register CONNECTION con = arg->con;
776
777 /*
778 * Set up 2nd init routine for after we re-queue ourselves
779 */
780 op->fcn.cont = g_i2acc;
781 /*
782 * See whether we successfully accepted a connection. If
783 * not, we just cancel ourselves. If so, fill out the
784 * connection descriptor and related data structures properly,
785 * then requeue ourselves on the new connection.
786 */
787 if (OP_STATUS(arg->listenop) != OP_COMPLETE ||
788 OP_RESULT(arg->listenop) != OP_SUCCESS ||
789 con->in.fd <=0) {
790 (void) sever_connection(con);
791 g_clnup_accept(arg);
792 op->result = OP_CANCELLED;
793 return OP_CANCELLED;
794 }
795
796 /*
797 * OK, we got an fd, but the connection and related structures
798 * aren't really set up straight, and the fd must be put
799 * into non-blocking mode. There really should be a common
800 * routine for this, since some of the logic exists in 2
801 * or 3 places.
802 */
803 con->status = CON_STARTING;
804 con->out.fd = con->in.fd;
805 g_ver_iprotocol(con); /* make sure we're at */
806 /* same level of protocol */
807 if (con->status == CON_UP) {
808 /*
809 * We've successfully started the connection, now mark
810 * it for non-blocking I/O. Also, update the high water
811 * mark of fd's controlled by our system.
812 */
813 int nb = 1;
814 if(ioctl(con->in.fd, FIONBIO, (char *)&nb)== (-1)) {
815 g_stop_with_errno(con);
816 *arg->conp = con; /* give failed con to */
817 /* caller so he can find */
818 /* errno */
819 gdb_perror("gdb: ioctl for non-block failed");
820 g_clnup_accept(arg);
821 op->result = OP_CANCELLED; /* we didn't really, but */
822 /* we want caller to look */
823 /* at the connection so he */
824 /* can find errno*/
825 return OP_COMPLETE;
826 }
827 if (con->in.fd +1 > gdb_mfd)
828 gdb_mfd = con->in.fd + 1;
829 /*
830 * Allocate a buffer, if necessary, and reset buffer pointers
831 * so first request will result in a long read into the buffer
832 */
833 g_allocate_connection_buffers(con);
834
835 } else {
836 *arg->conp = con; /* give failed con to */
837 /* caller so he can find */
838 /* errno */
839 g_clnup_accept(arg);
840 op->result = OP_CANCELLED;
841 return OP_COMPLETE;
842 }
843
844 /*
845 * Before we requeue ourselves on the new connection, queue
846 * up a receive for the expected tuple. Then we'll be
847 * sure that it's there by the time we run.
848 */
849 start_receiving_object(arg->receiveop, con, (char *)(arg->tuplep),
850 TUPLE_T);
851 /*
852 * Requeue ourselves behind the receive operation.
853 */
854
855 (void) requeue_operation(con, CON_INPUT, op);
856 return OP_REQUEUED;
857}
858
859
860
861 /*----------------------------------------------------------*/
862 /*
863 /* g_i2acc
864 /*
865 /* Second init routine for accepting a connection.
866 /* This one is run after the operation is requeued on
867 /* the new connection. By the time we run here, the
868 /* attempt to receive the tuple has already been made.
869 /* We just check on status and clean-up.
870 /*
871 /*----------------------------------------------------------*/
872
24582af9 873/*ARGSUSED*/
5580185e 874int
875g_i2acc(op, hcon, arg)
876OPERATION op;
877HALF_CONNECTION hcon;
878struct acc_data *arg;
879{
880 int rc;
881
882 rc = OP_STATUS(arg->receiveop); /* if it completes, then */
883 /* so do we! */
884 *arg->conp = arg->con; /* give caller the new con */
885 if (rc != OP_COMPLETE)
886 (void) g_stop_connection(arg->con);
887 /*
888 * Release all transient data structures.
889 */
890 g_clnup_accept(arg);
891
892 return OP_COMPLETE;
893}
894
895 /*----------------------------------------------------------*/
896 /*
897 /* g_clnup_accept
898 /*
899 /* Free all data structures used by start_accepting_client.
900 /*
901 /*----------------------------------------------------------*/
902
903int
904g_clnup_accept(arg)
905struct acc_data *arg;
906{
907 delete_operation(arg->listenop);
908 delete_operation(arg->receiveop);
909 db_free((char *)arg, sizeof(struct acc_data));
910}
This page took 0.196071 seconds and 5 git commands to generate.