annotate lib-src/tcp.c @ 5634:2014ff433daf

Support hash COLLECTIONs, #'{all,try}-completion{s,}; add #'test-completion src/ChangeLog addition: 2012-01-01 Aidan Kehoe <kehoea@parhasard.net> Add #'test-completion, API from GNU. Accept hash table COLLECTIONs in it and in the other completion-oriented functions, #'try-completion, #'all-completions, and those Lisp functions implemented in terms of them. * lisp.h: Update the prototype of map_obarray(), making FN compatible with the FUNCTION argument of elisp_maphash(); * abbrev.c (abbrev_match_mapper): * abbrev.c (record_symbol): * doc.c (verify_doc_mapper): * symbols.c (mapatoms_1): * symbols.c (apropos_mapper): Update these mapper functions to reflect the new argument to map_obarray(). * symbols.c (map_obarray): Call FN with two arguments, the string name of the symbol, and the symbol itself, for API (mapper) compatibility with elisp_maphash(). * minibuf.c (map_completion): New. Map a maphash_function_t across a non function COLLECTION, as appropriate for #'try-completion and friends. * minibuf.c (map_completion_list): New. Map a maphash_function_t across a pseudo-alist, as appropriate for the completion functions. * minibuf.c (ignore_completion_p): PRED needs to be called with two args if and only if the collection is a hash table. Implement this. * minibuf.c (try_completion_mapper): New. The loop body of #'try-completion, refactored out. * minibuf.c (Ftry_completion): Use try_completion_mapper(), map_completion(). * minibuf.c (all_completions_mapper): New. The loop body of #'all-completions, refactored out. * minibuf.c (Fall_completions): Use all_completions_mapper(), map_completion(). * minibuf.c (test_completion_mapper): New. The loop body of #'test-completion. * minibuf.c (Ftest_completion): New, API from GNU. * minibuf.c (syms_of_minibuf): Make Ftest_completion available. tests/ChangeLog addition: 2012-01-01 Aidan Kehoe <kehoea@parhasard.net> * automated/completion-tests.el: New. Test #'try-completion, #'all-completion and #'test-completion with list, vector and hash-table COLLECTION arguments.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 01 Jan 2012 15:18:52 +0000
parents b9167d522a9a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /*
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 0
diff changeset
2 * TCP/IP stream emulation for XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 * Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 * Author: Masanobu Umeda
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 * Maintainer: umerin@mse.kyutech.ac.jp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 0
diff changeset
8 This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
10 XEmacs is free software: you can redistribute it and/or modify it
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
11 under the terms of the GNU General Public License as published by the
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
12 Free Software Foundation, either version 3 of the License, or (at your
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
13 option) any later version.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
18 for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
5406
061f4f90f874 Convert lib-src/ to GPLv3.
Mike Sperber <sperber@deinprogramm.de>
parents: 978
diff changeset
21 along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * Yasunari, Itoh at PFU limited contributed for Fujitsu UTS and SX/A.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * Thu Apr 6 13:47:37 JST 1989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 * USG fixes by Sakaeda <saka@mickey.trad.pf.fujitsu.junet>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * For Fujitsu UTS compile with:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 * cc -O -o tcp tcp.c -DFUJITSU_UTS -lu -lsocket
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
978
13e47461d509 [xemacs-hg @ 2002-08-29 19:45:20 by james]
james
parents: 613
diff changeset
33 #ifdef HAVE_CONFIG_H
13e47461d509 [xemacs-hg @ 2002-08-29 19:45:20 by james]
james
parents: 613
diff changeset
34 #include <config.h>
13e47461d509 [xemacs-hg @ 2002-08-29 19:45:20 by james]
james
parents: 613
diff changeset
35 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include <ctype.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #ifdef FUJITSU_UTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #define USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include <sys/ucbtypes.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include <sys/tisp/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include <netdb.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include <sys/tisp/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #include <sys/socket.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include <netdb.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include <netinet/in.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include <sys/stat.h>
978
13e47461d509 [xemacs-hg @ 2002-08-29 19:45:20 by james]
james
parents: 613
diff changeset
55 #include "syssignal.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 int selectable = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 sigout ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 fcntl (fileno (stdin), F_SETFL, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 exit (-1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 main (argc, argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 int argc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 char *argv[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 struct hostent *host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 struct sockaddr_in sockin, sockme;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 struct servent *serv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 char *hostname = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 char *service = "nntp";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 int port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 int readfds;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 int writefds;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 int server; /* NNTP Server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 int emacsIn = fileno (stdin); /* Emacs intput */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 int emacsOut = fileno (stdout); /* Emacs output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 char buffer[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 int nbuffer; /* Number of bytes in buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 int wret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 char *retry; /* retry bufferp */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 int false = 0; /* FALSE flag for setsockopt () */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 if (argc < 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 fprintf (stderr, "Usage: %s HOST [SERVICE]\n", argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if (argc >= 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 hostname = argv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 if (argc >= 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 service = argv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 if ((host = gethostbyname (hostname)) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 perror ("gethostbyname");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 if (isdigit (service[0]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 port = atoi (service);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 serv = getservbyname (service, "tcp");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 if (serv == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 perror ("getservbyname");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 port = serv->s_port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 memset (&sockin, 0, sizeof (sockin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 sockin.sin_family = host->h_addrtype;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 memcpy (&sockin.sin_addr, host->h_addr, host->h_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 sockin.sin_port = port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 if ((server = socket (AF_INET, SOCK_STREAM, 0)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 perror ("socket");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 if (setsockopt (server, SOL_SOCKET, SO_REUSEADDR, &false, sizeof (false)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 perror ("setsockopt");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 memset (&sockme, 0, sizeof (sockme));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 sockme.sin_family = sockin.sin_family;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 sockme.sin_addr.s_addr = INADDR_ANY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 if (bind (server, &sockme, sizeof (sockme)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 perror ("bind");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 if (connect (server, &sockin, sizeof (sockin)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 perror ("connect");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 close (server);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 #ifdef O_NDELAY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 fcntl (server, F_SETFL, O_NDELAY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* USG pipe cannot not select emacsIn */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 struct stat statbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 fstat (emacsIn, &statbuf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 if (statbuf.st_mode & 010000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 selectable = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 if (!selectable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 signal (SIGINT, sigout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 fcntl (emacsIn, F_SETFL, O_NDELAY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 /* Connection established. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 readfds = (1 << server) | (1 << emacsIn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 if (select (32, &readfds, NULL, NULL, (struct timeval *)NULL) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 perror ("select");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 if (readfds & (1 << emacsIn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 /* From Emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 nbuffer = read (emacsIn, buffer, sizeof buffer -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 if (selectable && nbuffer == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 goto finish;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 else if (!(readfds & (1 << server)) && nbuffer == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 sleep (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 if (nbuffer == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 goto finish;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 for (retry = buffer; nbuffer > 0; nbuffer -= wret, retry += wret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 writefds = 1 << server;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 if (select (server+1, NULL, &writefds, NULL, (struct timeval*)NULL) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 perror ("select");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 wret = write (server, retry, nbuffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 if (wret < 0) goto finish;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (readfds & (1 << server))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 /* From NNTP server */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 nbuffer = read (server, buffer, sizeof buffer -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 if (nbuffer == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 goto finish;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 for (retry = buffer; nbuffer > 0; nbuffer -= wret, retry += wret)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 writefds = 1 << emacsOut;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 if (selectable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 if (select (emacsOut+1, NULL, &writefds, NULL, (struct timeval*)NULL) == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 perror ("select");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 wret = write (emacsOut, retry, nbuffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 if (wret < 0) goto finish;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 /* End of communication. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 finish:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 close (server);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 #ifdef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 if (!selectable) fcntl (emacsIn, F_SETFL, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 close (emacsIn);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 close (emacsOut);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 exit (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 }