Debian Codegraph @

xpa/xpaio.c

raw symbols SCIP
1 /*
2 * Copyright (c) 1999-2003 Smithsonian Astrophysical Observatory
3 */
4
5 #include <xpap.h>
6
7 /*
8 *----------------------------------------------------------------------------
9 *
10 *
11 * Private Routines and Data
12 *
13 *
14 *----------------------------------------------------------------------------
15 */
16
17 static int ioerr=0;
18 static int doxpa=XPA_IOCALLSXPA;
19 static int _doxpa=1;
20 static int level=0;
21 static char _xpalevelspaces[SZ_LINE];
22
23 #if HAVE_MINGW32==0
24
25 static struct sigaction act1, oact1;
26
27 /*
28 *----------------------------------------------------------------------------
29 *
30 * Routine: XPAInterruptFunc
31 *
32 * Purpose: function to call when interrupted
33 *
34 * Returns: none
35 *
36 *----------------------------------------------------------------------------
37 */
38 #ifdef ANSI_FUNC
39 static void
40 XPAInterruptFunc (int signo)
41 #else
42 static void XPAInterruptFunc(signo)
43 int signo;
44 #endif
45 {
46 ioerr = 1;
47 }
48
49 /*
50 *----------------------------------------------------------------------------
51 *
52 * Routine: XPAInterruptSetup
53 *
54 * Purpose: set up the InterruptSetup handler
55 *
56 * Returns: 0 for success, -1 for failure
57 *
58 *----------------------------------------------------------------------------
59 */
60 #ifdef ANSI_FUNC
61 static int
62 XPAInterruptSetup (Sigfunc *func1)
63 #else
64 static int XPAInterruptSetup(func1)
65 Sigfunc *func1;
66 #endif
67 {
68 ioerr = 0;
69
70 if( XPASigusr1() ){
71 act1.sa_handler = func1;
72 sigemptyset(&act1.sa_mask);
73 act1.sa_flags = 0;
74 #ifdef SA_INTERRUPT
75 act1.sa_flags |= SA_INTERRUPT;
76 #endif
77 if( sigaction(SIGUSR1, &act1, &oact1) < 0 )
78 return(-1);
79 }
80 return(0);
81 }
82
83 /*
84 *----------------------------------------------------------------------------
85 *
86 * Routine: XPAInterruptStart
87 *
88 * Purpose: set up sigaction for interrupt
89 *
90 * Returns: 0 for success, -1 for failure
91 *
92 *----------------------------------------------------------------------------
93 */
94 #ifdef ANSI_FUNC
95 static void
96 XPAInterruptStart (void)
97 #else
98 static void XPAInterruptStart()
99 #endif
100 {
101 /* Disable SIGPIPE so we do not die if the client dies.
102 Rather, we will get an EOF on reading or writing. */
103 xsignal_sigpipe();
104
105 /* set up the signal callbacks */
106 XPAInterruptSetup(XPAInterruptFunc);
107 }
108
109 /*
110 *----------------------------------------------------------------------------
111 *
112 * Routine: XPAInterruptEnd
113 *
114 * Purpose: stop the interrupt handling
115 *
116 * Returns: none
117 *
118 *----------------------------------------------------------------------------
119 */
120 #ifdef ANSI_FUNC
121 static void
122 XPAInterruptEnd (void)
123 #else
124 static void XPAInterruptEnd()
125 #endif
126 {
127 /* restore old sigaction, if necessary */
128 if( XPASigusr1() )
129 XPAInterruptSetup(oact1.sa_handler);
130 }
131
132 #else
133
134 /* Windows does not support SIGUSR1 */
135 #define XPAInterruptStart() ioerr=0
136 #define XPAInterruptEnd()
137
138 #endif
139
140 /*
141 *----------------------------------------------------------------------------
142 *
143 * Routine: XPAIOErrorCheck
144 *
145 * Purpose: check to see if there was an error
146 *
147 * Returns: none
148 *
149 *----------------------------------------------------------------------------
150 */
151 #ifdef ANSI_FUNC
152 static int
153 XPAIOErrorCheck (void)
154 #else
155 static int XPAIOErrorCheck()
156 #endif
157 {
158 return(ioerr);
159 }
160
161 /*
162 *----------------------------------------------------------------------------
163 *
164 *
165 * Public Routines and Data
166 *
167 *
168 *----------------------------------------------------------------------------
169 */
170
171 /*
172 *----------------------------------------------------------------------------
173 *
174 * Routine: XPAGets
175 *
176 * Purpose: read characters up a new-line -- sockets only
177 *
178 * Returns: number of characters read
179 *
180 *----------------------------------------------------------------------------
181 */
182 #ifdef ANSI_FUNC
183 int
184 XPAGets (XPA xpa, int fd, char *buf, int len, int timeout)
185 #else
186 int XPAGets(xpa, fd, buf, len, timeout)
187 XPA xpa;
188 int fd;
189 char *buf;
190 int len;
191 int timeout;
192 #endif
193 {
194 int cur;
195 int got;
196 int flags;
197 int active;
198 int firsttime;
199 int done1, done2;
200 int swidth = FD_SETSIZE;
201 struct timeval tv;
202 struct timeval *tvp;
203 fd_set readfds;
204 fd_set writefds;
205
206 /* do we allow xpa processing within this routine? */
207 _doxpa = 1;
208
209 /* start out pessimistically */
210 *buf = '\0';
211
212 /* make sure we have a valid channel */
213 if( fd < 0 ) return(-1);
214
215 /* make sure we have a valid len */
216 if( len <= 0 ) return(-1);
217
218 FPRINTF((stderr, "%sXPAGets: %d entering to read %d bytes\n", _sp, fd, len));
219
220 /* start the interrupt handler */
221 XPAInterruptStart();
222
223 /* turn this xpa off */
224 active = XPAActive(xpa, xpa_comm(xpa), 0);
225
226 /* put socket into non-blocking mode */
227 xfcntl_nonblock(fd,flags);
228
229 /* grab characters up to a new-line or max len */
230 cur = 0;
231 done1 = (cur >= (len-1));
232 firsttime = 1;
233 while( !done1 ){
234 /* first time through we try the primary IO before selecting */
235 if( !firsttime ){
236 /* set up timer, if necessary */
237 if( timeout >= 0 ){
238 tv.tv_sec = timeout;
239 tv.tv_usec = 0;
240 tvp = &tv;
241 }
242 else{
243 tvp = NULL;
244 }
245 /* select this socket and all XPA server sockets */
246 FD_ZERO(&readfds);
247 FD_SET(fd, &readfds);
248 FD_ZERO(&writefds);
249 if( doxpa && _doxpa ){
250 XPAClientAddSelect(NULL, &readfds, &writefds);
251 XPAAddSelect(NULL, &readfds);
252 }
253 /* wait for the IO ready */
254 FPRINTF((stderr, "%sXPAGets: select on fd %d ...", _sp, fd));
255 got = xselect(swidth, &readfds, &writefds, NULL, tvp);
256 FPRINTF((stderr, " returned %d\n", got));
257 /* check for user interrupt or error or timeout */
258 if( XPAIOErrorCheck() || (got <=0) ){
259 cur = -1;
260 done1 = 1;
261 continue;
262 }
263 /* if socket is not ready, process XPA's and try again */
264 if( !FD_ISSET(fd, &readfds) ){
265 if( doxpa && _doxpa ){
266 XPALevelSet(1);
267 XPAClientProcessSelect(NULL, &readfds, &writefds, 0);
268 XPAProcessSelect(&readfds, 0);
269 XPALevelSet(-1);
270 }
271 continue;
272 }
273 }
274 else{
275 firsttime = 0;
276 }
277 done2 = 0;
278 while( !done1 && !done2 ){
279 /* get data */
280 got = recv(fd, &(buf[cur]), 1, 0);
281 /* check for user interrupt */
282 if( XPAIOErrorCheck() ){
283 cur = -1;
284 done1 = 1;
285 continue;
286 }
287 /* process result code */
288 switch(got){
289 case -1:
290 /* socket would block */
291 if((xerrno == EINPROGRESS) ||
292 (xerrno == EWOULDBLOCK) ||
293 (xerrno == EAGAIN) ){
294 FPRINTF((stderr, "%sXPAGets: recoverable recv fd=%d errno=%d\n",
295 _sp, fd, xerrno));
296 done2 = 1;
297 }
298 /* error of some sort */
299 else{
300 FPRINTF((stderr, "%sXPAGets: error recv fd=%d errno=%d\n",
301 _sp, fd, xerrno));
302 PERROR(("XPAGets recv"));
303 cur = -1;
304 done1 = 1;
305 }
306 break;
307 case 0:
308 /* EOF */
309 done1 = 1;
310 break;
311 default:
312 /* got a valid byte -- check for EOL */
313 if( buf[cur++] == '\n' ){
314 /* change \r\n to \n */
315 if( (cur >= 2) && (buf[cur-2] == '\r') ){
316 cur--;
317 buf[cur-1] = '\n';
318 }
319 done1 = 1;
320 }
321 else{
322 done1 = cur >= (len-1);
323 }
324 break;
325 }
326 }
327 }
328
329 /* restore socket mode */
330 xfcntl_restore(fd,flags);
331
332 /* restore active flag */
333 XPAActive(xpa, xpa_comm(xpa), active);
334
335 /* stop the interrupt handler */
336 XPAInterruptEnd();
337
338 if( cur >= 0 ){
339 buf[cur] = '\0';
340 }
341 else{
342 buf[0] = '\0';
343 }
344 FPRINTF((stderr, "%sXPAGets: %d read %d bytes:\n%.80s", _sp, fd, cur, buf));
345
346 /* return error code or length */
347 return(cur);
348 }
349
350 /*
351 *----------------------------------------------------------------------------
352 *
353 * Routine: XPAPuts
354 *
355 * Purpose: write a line of characters up to a newline -- sockets only
356 *
357 * Returns: number of characters written
358 *
359 *----------------------------------------------------------------------------
360 */
361 #ifdef ANSI_FUNC
362 int
363 XPAPuts (XPA xpa, int fd, char *buf, int timeout)
364 #else
365 int XPAPuts(xpa, fd, buf, timeout)
366 XPA xpa;
367 int fd;
368 char *buf;
369 int timeout;
370 #endif
371 {
372 int n;
373 int total;
374 int cur;
375 int got;
376 int flags;
377 int active;
378 int firsttime;
379 int done1, done2;
380 int swidth = FD_SETSIZE;
381 struct timeval tv;
382 struct timeval *tvp;
383 fd_set readfds, writefds;
384
385 /* do we allow xpa processing within this routine? */
386 _doxpa = 1;
387
388 /* make sure we have a valid channel */
389 if( fd < 0 ) return(-1);
390
391 /* determine how many characters to send */
392 got = strlen(buf);
393 for(total=0; total<got; total++){
394 if( buf[total] == '\n' ){
395 total++;
396 break;
397 }
398 }
399 FPRINTF((stderr, "%sXPAPuts: %d entering to write %d bytes\n",
400 _sp, fd, total));
401
402 /* start the interrupt handler */
403 XPAInterruptStart();
404
405 /* turn this xpa off */
406 active = XPAActive(xpa, xpa_comm(xpa), 0);
407
408 /* put socket into non-blocking mode */
409 xfcntl_nonblock(fd,flags);
410
411 /* send characters up to a new-line */
412 cur = 0;
413 done1 = (cur >= total);
414 firsttime = 1;
415 while( !done1 ){
416 /* first time through we try the primary IO before selecting */
417 if( !firsttime ){
418 /* set up timer, if necessary */
419 if( timeout >= 0 ){
420 tv.tv_sec = timeout;
421 tv.tv_usec = 0;
422 tvp = &tv;
423 }
424 else{
425 tvp = NULL;
426 }
427 /* select this socket and all XPA server sockets */
428 FD_ZERO(&readfds);
429 FD_ZERO(&writefds);
430 FD_SET(fd, &writefds);
431 if( doxpa && _doxpa ){
432 XPAClientAddSelect(NULL, &readfds, &writefds);
433 XPAAddSelect(NULL, &readfds);
434 }
435 /* wait for the IO ready */
436 FPRINTF((stderr, "%sXPAPuts: select on fd %d ...", _sp, fd));
437 got = xselect(swidth, &readfds, &writefds, NULL, tvp);
438 FPRINTF((stderr, " returned %d\n", got));
439 /* check for user interrupt or error or timeout */
440 if( XPAIOErrorCheck() || (got <=0) ){
441 cur = -1;
442 done1 = 1;
443 continue;
444 }
445 /* if socket is not ready, process XPA's and try again */
446 if( !FD_ISSET(fd, &writefds) ){
447 FD_CLR(fd, &readfds);
448 if( doxpa && _doxpa ){
449 XPALevelSet(1);
450 XPAClientProcessSelect(NULL, &readfds, &writefds, 0);
451 XPAProcessSelect(&readfds, 0);
452 XPALevelSet(-1);
453 }
454 continue;
455 }
456 }
457 else{
458 firsttime = 0;
459 }
460 done2 = 0;
461 while( !done1 && !done2 ){
462 /* calculate size of next chunk */
463 if( (n = MIN(total-cur, XPA_IOSIZE)) <=0 ){
464 done1 = 1;
465 continue;
466 }
467 /* write the data */
468 FPRINTF((stderr, "%sXPAPuts: send %d on fd %d ...", _sp, n, fd));
469 got=send(fd, &buf[cur], n, 0);
470 FPRINTF((stderr, " returned %d\n", got));
471 /* check for user interrupt */
472 if( XPAIOErrorCheck() ){
473 cur = -1;
474 done1 = 1;
475 continue;
476 }
477 /* process return code */
478 switch(got){
479 case -1:
480 /* socket would block */
481 if((xerrno == EINPROGRESS) ||
482 (xerrno == EWOULDBLOCK) ||
483 (xerrno == EAGAIN) ){
484 done2 = 1;
485 }
486 /* error of some sort */
487 else{
488 cur = -1;
489 done1 = 1;
490 }
491 break;
492 case 0:
493 /* shouldn't happen */
494 done1 = (cur >= total);
495 break;
496 default:
497 /* sent some data */
498 cur += got;
499 done1 = (cur >= total);
500 break;
501 }
502 }
503 }
504
505 /* restore socket mode */
506 xfcntl_restore(fd,flags);
507
508 /* restore active flag */
509 XPAActive(xpa, xpa_comm(xpa), active);
510
511 /* stop the interrupt handler */
512 XPAInterruptEnd();
513 FPRINTF((stderr, "%sXPAPuts: %d wrote %d bytes: %.50s",
514 _sp, fd, total, buf));
515 /* return error code or length */
516 return(cur);
517 }
518
519 /*
520 *----------------------------------------------------------------------------
521 *
522 * Routine: XPAGetBuf
523 *
524 * Purpose: read data from the xpa data socket until EOF -- sockets only
525 *
526 * Results: 0 on success, -1 on failure
527 * also allocates memory for buf and returns len
528 *
529 *----------------------------------------------------------------------------
530 */
531 #ifdef ANSI_FUNC
532 int
533 XPAGetBuf (XPA xpa, int fd, char **buf, size_t *len, int timeout)
534 #else
535 int XPAGetBuf(xpa, fd, buf, len, timeout)
536 XPA xpa;
537 int fd;
538 char **buf;
539 size_t *len;
540 int timeout;
541 #endif
542 {
543 int n;
544 int cur;
545 int flags;
546 int active;
547 int firsttime;
548 int done1, done2;
549 int swidth = FD_SETSIZE;
550 int got;
551 size_t total;
552 size_t slen;
553 char *s=NULL;
554 struct timeval tv;
555 struct timeval *tvp;
556 fd_set readfds;
557 fd_set writefds;
558
559 /* do we allow xpa processing within this routine? */
560 _doxpa = 1;
561
562 /* make sure we have a valid data channel */
563 if( fd < 0 ) return(-1);
564
565 /* make sure we have a valid buf ptr and len ptr */
566 if( (len == NULL) || (buf == NULL) ) return(-1);
567
568 FPRINTF((stderr, "%sXPAGetBuf: entering fd %d\n", _sp, fd));
569
570 /* allocate the first buffer, if necessary */
571 if( (*len != 0) && (*buf != NULL) ){
572 slen = *len;
573 total = *len;
574 s = *buf;
575 }
576 else{
577 slen = XPA_IOSIZE;
578 total = 0;
579 if( (s=(char *)xmalloc(slen)) == NULL )
580 return(-1);
581 }
582 n = XPA_IOSIZE;
583
584 /* start the interrupt handler */
585 XPAInterruptStart();
586
587 /* turn this xpa off */
588 active = XPAActive(xpa, xpa_comm(xpa), 0);
589
590 /* put socket into non-blocking mode */
591 xfcntl_nonblock(fd,flags);
592
593 /* grab bytes to EOF */
594 done1 = 0;
595 firsttime = 1;
596 while( !done1 ){
597 /* first time through we try the primary IO before selecting */
598 if( !firsttime ){
599 /* set up timer, if necessary */
600 if( timeout >= 0 ){
601 tv.tv_sec = timeout;
602 tv.tv_usec = 0;
603 tvp = &tv;
604 }
605 else{
606 tvp = NULL;
607 }
608 /* select this socket and all XPA server sockets */
609 FD_ZERO(&readfds);
610 FD_SET(fd, &readfds);
611 FD_ZERO(&writefds);
612 if( doxpa && _doxpa ){
613 XPAClientAddSelect(NULL, &readfds, &writefds);
614 XPAAddSelect(NULL, &readfds);
615 }
616 /* wait for the IO ready */
617 FPRINTF((stderr, "%sXPAGetBuf: select on fd %d ...", _sp, fd));
618 got = xselect(swidth, &readfds, &writefds, NULL, tvp);
619 FPRINTF((stderr, " returned %lu\n", (unsigned long)got));
620 /* check for user interrupt or error or timeout */
621 if( XPAIOErrorCheck() || (got <=0) ){
622 cur = -1;
623 done1 = 1;
624 continue;
625 }
626 /* if socket is not ready, process XPA's and try again */
627 if( !FD_ISSET(fd, &readfds) ){
628 if( doxpa && _doxpa ){
629 XPALevelSet(1);
630 XPAClientProcessSelect(NULL, &readfds, &writefds, 0);
631 XPAProcessSelect(&readfds, 0);
632 XPALevelSet(-1);
633 }
634 continue;
635 }
636 }
637 else{
638 firsttime = 0;
639 }
640 done2 = 0;
641 while( !done1 && !done2 ){
642 /* make sure we have enough room */
643 while( (total + n) > slen ){
644 slen += (n*10);
645 if( (s = (char *)xrealloc(s, slen)) == NULL ){
646 return(-1);
647 }
648 }
649 /* get data */
650 got = recv(fd, &(s[total]), n, 0);
651 FPRINTF((stderr, "%sXPAGetBuf: %d got %d bytes (tried %d at %lu)\n",
652 _sp, fd, got, n, (unsigned long)total));
653 /* check for user interrupt */
654 if( XPAIOErrorCheck() ){
655 cur = -1;
656 done1 = 1;
657 continue;
658 }
659 /* process return code */
660 switch(got){
661 case -1:
662 /* socket would block */
663 if((xerrno == EINPROGRESS) ||
664 (xerrno == EWOULDBLOCK) ||
665 (xerrno == EAGAIN) ){
666 done2 = 1;
667 }
668 /* error of some sort */
669 else{
670 cur = -1;
671 done1 = 1;
672 }
673 break;
674 case 0:
675 /* EOF */
676 cur = 0;
677 done1 = 1;
678 break;
679 default:
680 /* got data */
681 total += got;
682 break;
683 }
684 }
685 }
686
687 /* restore socket mode */
688 xfcntl_restore(fd,flags);
689
690 /* restore active flag */
691 XPAActive(xpa, xpa_comm(xpa), active);
692
693 /* stop the interrupt handler */
694 XPAInterruptEnd();
695
696 /* null terminate after last byte as a courtesy */
697 if( cur == 0 ){
698 s = (char *)xrealloc(s, total+1);
699 s[total] = '\0';
700 *buf = s;
701 *len = total;
702 }
703 else{
704 if( s ) xfree(s);
705 *buf = NULL;
706 *len = 0;
707 }
708
709 FPRINTF((stderr, "%sXPAGetBuf: leaving fd %d with %lu bytes\n",
710 _sp, fd, (unsigned long)*len));
711
712 /* return error code or length */
713 return(cur);
714 }
715
716 /*
717 *----------------------------------------------------------------------------
718 *
719 * Routine: XPAPutBuf
720 *
721 * Purpose: write data to the xpa data socket -- sockets only
722 *
723 * Results: 0 on success, -1 for failure
724 *
725 *----------------------------------------------------------------------------
726 */
727 #ifdef ANSI_FUNC
728 int
729 XPAPutBuf (XPA xpa, int fd, char *buf, size_t len, int timeout)
730 #else
731 int XPAPutBuf(xpa, fd, buf, len, timeout)
732 XPA xpa;
733 int fd;
734 char *buf;
735 size_t len;
736 int timeout;
737 #endif
738 {
739 int n;
740 int cur;
741 int got;
742 int flags;
743 int active;
744 int firsttime;
745 int done1, done2;
746 int swidth = FD_SETSIZE;
747 size_t total;
748 struct timeval tv;
749 struct timeval *tvp;
750 fd_set readfds, writefds;
751
752 /* do we allow xpa processing within this routine? */
753 _doxpa = 1;
754
755 /* make sure we have a valid data channel */
756 if( fd < 0 ) return(-1);
757
758 /* make sure we have a valid buf ptr and len ptr */
759 if( (len == 0) || (buf == NULL) ) return(-1);
760
761 FPRINTF((stderr, "%sXPAPutBuf: writing %lu bytes to %d\n",
762 _sp, (unsigned long)len, fd));
763
764 /* start the interrupt handler */
765 XPAInterruptStart();
766
767 /* turn this xpa off */
768 active = XPAActive(xpa, xpa_comm(xpa), 0);
769
770 /* put socket into non-blocking mode */
771 xfcntl_nonblock(fd,flags);
772
773 cur = 0;
774 total = len;
775 /* write in batches until done */
776 done1 = (cur >= total);
777 firsttime = 1;
778 while( !done1 ){
779 /* first time through we try the primary IO before selecting */
780 if( !firsttime ){
781 /* set up timer, if necessary */
782 if( timeout >= 0 ){
783 tv.tv_sec = timeout;
784 tv.tv_usec = 0;
785 tvp = &tv;
786 }
787 else{
788 tvp = NULL;
789 }
790 /* select this socket and all XPA server sockets */
791 FD_ZERO(&readfds);
792 FD_ZERO(&writefds);
793 FD_SET(fd, &writefds);
794 if( doxpa && _doxpa ){
795 XPAClientAddSelect(NULL, &readfds, &writefds);
796 XPAAddSelect(NULL, &readfds);
797 }
798 /* wait for the IO ready */
799 FPRINTF((stderr, "%sXPAPutBuf: select on fd %d ...", _sp, fd));
800 got = xselect(swidth, &readfds, &writefds, NULL, tvp);
801 FPRINTF((stderr, " returned %d\n", got));
802 /* check for user interrupt or error or timeout */
803 if( XPAIOErrorCheck() || (got <=0) ){
804 cur = -1;
805 done1 = 1;
806 continue;
807 }
808 /* if socket is not ready, process XPA's and try again */
809 if( !FD_ISSET(fd, &writefds) ){
810 if( doxpa && _doxpa ){
811 XPALevelSet(1);
812 XPAClientProcessSelect(NULL, &readfds, &writefds, 0);
813 XPAProcessSelect(&readfds, 0);
814 XPALevelSet(-1);
815 }
816 continue;
817 }
818 }
819 else{
820 firsttime = 0;
821 }
822 done2 = 0;
823 while( !done1 && !done2 ){
824 /* calculate size of next chunk */
825 if( (n = MIN(total-cur, XPA_IOSIZE)) <=0 ){
826 done1 = 1;
827 continue;
828 }
829 /* write the data */
830 got=send(fd, &buf[cur], n, 0);
831 FPRINTF((stderr, "%sXPAPutBuf: %d sent %lu bytes (tried %d at %d)\n",
832 _sp, fd, (unsigned long)got, n, cur));
833 /* check for user interrupt */
834 if( XPAIOErrorCheck() ){
835 cur = -1;
836 done1 = 1;
837 continue;
838 }
839 /* process result code */
840 switch(got){
841 case -1:
842 PERROR(("XPAPutBuf send"));
843 /* socket would block */
844 if((xerrno == EINPROGRESS) ||
845 (xerrno == EWOULDBLOCK) ||
846 (xerrno == EAGAIN) ){
847 done2 = 1;
848 }
849 /* error of some sort */
850 else{
851 cur = -1;
852 done1 = 1;
853 }
854 break;
855 case 0:
856 /* EOF */
857 done1 = 1;
858 break;
859 default:
860 /* got some data */
861 cur += got;
862 done1 = (cur >= total);
863 break;
864 }
865 }
866 }
867
868 /* restore socket mode */
869 xfcntl_restore(fd,flags);
870
871 /* restore active flag */
872 XPAActive(xpa, xpa_comm(xpa), active);
873
874 /* stop the interrupt handler */
875 XPAInterruptEnd();
876
877 /* return error code or length */
878 return(cur);
879 }
880
881 /*
882 *----------------------------------------------------------------------------
883 *
884 * Routine: XPAIOCallsXPA
885 *
886 * Purpose: function to flag whether IO calls also call XPA
887 *
888 * Returns: old value
889 *
890 *----------------------------------------------------------------------------
891 */
892 #ifdef ANSI_FUNC
893 int
894 XPAIOCallsXPA (int flag)
895 #else
896 int XPAIOCallsXPA(flag)
897 int flag;
898 #endif
899 {
900 int old_doxpa;
901
902 old_doxpa=doxpa;
903 doxpa = flag;
904 return old_doxpa;
905 }
906
907 /*
908 *----------------------------------------------------------------------------
909 *
910 * Routine: XPALevelSpaces
911 *
912 * Purpose: return string containing spaces for debugging process level
913 *
914 * Returns: string
915 *
916 *----------------------------------------------------------------------------
917 */
918 #ifdef ANSI_FUNC
919 char *XPALevelSpaces (void)
920 #else
921 char *XPALevelSpaces()
922 #endif
923 {
924 return(_xpalevelspaces);
925 }
926
927 /*
928 *----------------------------------------------------------------------------
929 *
930 * Routine: XPALevelSet
931 *
932 * Purpose: set processing level and update level string for debugging
933 *
934 * Returns: none
935 *
936 *----------------------------------------------------------------------------
937 */
938 #ifdef ANSI_FUNC
939 void
940 XPALevelSet (int lev)
941 #else
942 void XPALevelSet(lev)
943 #endif
944 {
945 #ifdef XPA_DEBUG
946 int i;
947 int spaces;
948 int maxspaces;
949 char tbuf[SZ_LINE];
950 #endif
951
952 level += lev;
953 _xpalevelspaces[0] = '\0';
954 #ifdef XPA_DEBUG
955 sprintf(tbuf, "#%d:", level);
956 maxspaces = SZ_LINE - strlen(tbuf);
957 if( level < maxspaces )
958 spaces = level;
959 else
960 spaces = maxspaces-1;
961 for(i=0; i<spaces; i++){
962 _xpalevelspaces[i] = ' ';
963 _xpalevelspaces[i+1] = '\0';
964 }
965 strncat(_xpalevelspaces, tbuf, SZ_LINE);
966 #endif
967 }
968
969 /*
970 *----------------------------------------------------------------------------
971 *
972 * Routine: XPALevelGet
973 *
974 * Purpose: get processing level
975 *
976 * Returns: none
977 *
978 *----------------------------------------------------------------------------
979 */
980 #ifdef ANSI_FUNC
981 int
982 XPALevelGet (void)
983 #else
984 int XPALevelGet()
985 #endif
986 {
987 return level;
988 }
989