Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Unsubscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-ID: <37BB7AE0.8A7D1E98@hiwaay.net> Date: Wed, 18 Aug 1999 22:32:48 -0500 From: Bob Crispen Organization: http://home.hiwaay.net/~crispen/ X-Mailer: Mozilla 4.08 [en] (Win95; U) MIME-Version: 1.0 To: cygwin AT sourceware DOT cygnus DOT com Subject: fdopen() and winsock Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 AT sourceware DOT cygnus DOT com