On Wed, 4 Jan 1995 19:06:03 GMT Peggy Bertsch said:
>Jeff Kell ([log in to unmask]) wrote:
>: The client establishes a connection "s" with the server, then does uses
>: two fdopen() calls to open an input and and output path to the socket.
>: Consequently that happens to be where it's blowing up :-)
>
>I don't have a definitive answer, but all I can say is that I don't recall
>fdopen() or associated stream functions being discussed as "supported" in
>the BSD Socket/iX manual (for MPE 5.0). I know that read() and write() are
>now documented as being supported for socket descriptors, as long as the
>application is POSIX -- whereas you used to have to use send[to]() and
>recv[from]() to do socket I/O. That leads me to believe that you can only
>use the I/O functions that are explicitly documented for sockets.
I don't know which "standards" define exactly what behavior, but the
following code snippet is from the FreeBSD distribution whois.c which
does the "questionable" fdopen().
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
perror("whois: connect");
exit(1);
}
sfi = fdopen(s, "r");
sfo = fdopen(s, "w");
if (sfi == NULL || sfo == NULL) {
perror("whois: fdopen");
(void)close(s);
exit(1);
}
while (argc-- > 1)
(void)fprintf(sfo, "%s ", *argv++);
(void)fprintf(sfo, "%s\r\n", *argv);
(void)fflush(sfo);
while ((ch = getc(sfi)) != EOF)
putchar(ch);
exit(0);
In other words, they get to use file I/O on the sockets. In contrast,
the FreeBSD "finger" does an fdopen() then uses read() and write(), and
as you mentioned, this works fine.
>I don't know enough to say why the streams functions blow up. If I get a
>chance (just got back from vacation and I'm still catching up), I'll do some
>digging and try to get you a better explanation.
I suspect they simply don't (yet) allow you to mix and match socket
descriptors. But I'd love to hear differently!
[\] Jeff Kell, [log in to unmask]
|