HP3000-L Archives

January 1995, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mike Belshe <[log in to unmask]>
Reply To:
Mike Belshe <[log in to unmask]>
Date:
Fri, 6 Jan 1995 16:23:49 GMT
Content-Type:
text/plain
Parts/Attachments:
text/plain (67 lines)
Jeff Kell ([log in to unmask]) wrote:
: 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.
 
Looks like you are right.  I wrote a little program with the following:
 
   int sock;    /* socket descriptor */
   FILE *fp;    /* file pointer to use with socket */
 
   .
   .
   .
 
   fp = fdopen(sock, "rw");
 
   write(sock,"write works\n",12);
   send(fileno(fp),"send to fileno(fp) works\n",25, 0);
   send(sock,"send to sock works\n",19, 0);
   fprintf(fp,"if this works I will be amazed\n");
   fwrite("fwrite works\n",  sizeof(char), 13, fp);
 
Output:
hpcsyn22-ttyp2(/users/mbelshe) % telnet romeo 8000
Trying...
Connected to romeo.cup.hp.com.
Escape character is '^]'.
write works
send to fileno(fp) works
send to sock works
Connection closed by foreign host.
 
So I'd guess you are right.  The sockets calls are not accessible via
the buffered IO calls (fwrite, fprintf, etc).
 
File an SR!
 
Mike
 
---
Mike Belshe
[log in to unmask]
HP CSY Networking Lab

ATOM RSS1 RSS2