public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Bob Crispen <crispen@hiwaay.net>
To: cygwin@sourceware.cygnus.com
Subject: fdopen() and winsock
Date: Tue, 31 Aug 1999 23:49:00 -0000	[thread overview]
Message-ID: <37BB7AE0.8A7D1E98@hiwaay.net> (raw)
Message-ID: <19990831234900.alAC-TOcVGhOXLqieuux0SRUbsJTLc0aWuP7Pm84_t8@z> (raw)

This has come up several times in the archives, but the only
reply I've seen so far is "you can't do that" so I thought
I'd try again, just in case.

When I compile with Cygwin 2.95 and don't set the -mno-cygwin
flag, then the following works just fine:

    /*
    * Convert the socket to a stream
    */
    if (0 > (sf = fdopen(s, "r+"))) {
	fprintf(stderr, "fdopen failed: %s\n", strerror(errno));
	close(s);
	exit (EXIT_FAILURE);
    }

    /*
    * Get news server acknowledgement of logon
    */
    bzero(reply, sizeof(reply));
    if (2 > (fscanf(sf, "%d %[^\r\n]", &status, reply))) {
	fprintf(stderr, "Logon ack read failed: %s\n", strerror(errno));
	close(s);
	exit (EXIT_FAILURE);
    }

[I defined bzero as a macro.  I just got lazy and didn't want
to change it everywhere in the code.]

When I compile with -mno-cygwin and use winsock.h and -lwsock32,
(and use WSAStartup to start up winsock) then the fscanf fails
with a "bad file descriptor" error, even though the file descriptor
inside the FILE is in fact the same value as the socket.  The only
thing that works is

    bzero(reply, sizeof(reply));
    bzero(sockbuf, sizeof(sockbuf));
    if (recv(s, sockbuf, sizeof(sockbuf), 0) < 0) {
	fprintf(stderr, "Logon ack read failed: %s\n", strerror(errno));
	close(s);
	exit (EXIT_FAILURE);
    }
    if (2 > (sscanf(sockbuf, "%d %[^\r\n]", &status, reply))) {
	fprintf(stderr, "Logon ack convert failed: %s\n", strerror(errno));
	close(s);
	exit (EXIT_FAILURE);
    }

Has anyone solved the problem of using fdopen to convert a socket
to a read-write stream?
--
Bob Crispen
crispen at hiwaay dot net
What we're looking for: destinations.
What we end up getting: journeys.

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

             reply	other threads:[~1999-08-31 23:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-18 20:33 Bob Crispen [this message]
1999-08-18 21:07 ` Mumit Khan
1999-08-31 23:49   ` Mumit Khan
1999-08-31 23:49 ` Bob Crispen
1999-08-22  8:53 Emanuele Aliberti
1999-08-23  0:31 ` John R Hanson
1999-08-23  8:10   ` Mumit Khan
1999-08-31 23:49     ` Mumit Khan
1999-08-31 23:49   ` John R Hanson
1999-08-31 23:49 ` Emanuele Aliberti
     [not found] <935478058.7766.ezmlm@sourceware.cygnus.com>
1999-08-24  4:28 ` Bob Crispen
1999-08-31 23:49   ` Bob Crispen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=37BB7AE0.8A7D1E98@hiwaay.net \
    --to=crispen@hiwaay.net \
    --cc=cygwin@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).