From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.bugs Subject: Re: windows sockets vs. file descriptors bugs in Guile Date: Fri, 02 Oct 2009 23:33:57 +0100 Message-ID: <87iqexbf3e.fsf@ossau.uklinux.net> References: <4AC42CD2.2060507@coverity.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1254522995 4662 80.91.229.12 (2 Oct 2009 22:36:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 2 Oct 2009 22:36:35 +0000 (UTC) Cc: bug-guile@gnu.org To: Scott McPeak Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Oct 03 00:36:27 2009 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mtqjj-0000y9-0W for guile-bugs@m.gmane.org; Sat, 03 Oct 2009 00:36:27 +0200 Original-Received: from localhost ([127.0.0.1]:42561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mtqji-0000Ym-E7 for guile-bugs@m.gmane.org; Fri, 02 Oct 2009 18:36:26 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MtqhQ-0006Zs-HJ for bug-guile@gnu.org; Fri, 02 Oct 2009 18:34:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MtqhL-0006UN-OD for bug-guile@gnu.org; Fri, 02 Oct 2009 18:34:03 -0400 Original-Received: from [199.232.76.173] (port=34418 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtqhL-0006Tx-GR for bug-guile@gnu.org; Fri, 02 Oct 2009 18:33:59 -0400 Original-Received: from mail3.uklinux.net ([80.84.72.33]:39027) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MtqhK-0003HM-V0 for bug-guile@gnu.org; Fri, 02 Oct 2009 18:33:59 -0400 Original-Received: from arudy (host86-145-159-48.range86-145.btcentralplus.com [86.145.159.48]) by mail3.uklinux.net (Postfix) with ESMTP id 04CA51F662E; Fri, 2 Oct 2009 23:33:58 +0100 (BST) Original-Received: from arudy (arudy [127.0.0.1]) by arudy (Postfix) with ESMTP id 84A7C38021; Fri, 2 Oct 2009 23:33:57 +0100 (BST) In-Reply-To: <4AC42CD2.2060507@coverity.com> (Scott McPeak's message of "Wed, 30 Sep 2009 21:15:14 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:4339 Archived-At: --=-=-= Scott McPeak writes: > Hi, > > Guile-1.8.7 appears to have socket support and Windows support, but > they don't seem to work together, despite the existence of things like > win32-socket.c. I hit this too about two years ago, but never checked in my patches. Sorry! > (I'm building Guile for Windows using the mingw cross > compiler on linux. I was building on Windows with MSVC at the time - which I believe is quite similar to mingw cross compiling. > Maybe it's different with Cygwin?) Yes, Cygwin has a thicker emulation layer underneath what Guile thinks is the C library API. > Specifically, Guile assumes the POSIX rule that a socket is just a > file descriptor, but on Windows that does not work; socket functions > only accept sockets, and file functions only accept file descriptors. > Several Guile functions are affected; I don't think this is an > exhaustive list, but it's what I ran into while trying to get a simple > client and server working (see testcase below): > > * fport_fill_input: Passes a socket to 'read'. > > * write_all: Passes a socket to 'write'. > > * fport_close: Passes a socket to 'close'. The EBADF error message is > then silently discarded (...), but the bug still manifests, e.g., as a > server that never closes its connections. I've attached my patch for these. It's a bit simpler than yours, and also avoids needing copyright assignment from you. Can you take a look, see if you notice any disadvantages compared with your version, and if possible try it out? > * scm_std_select: Passes a pipe file descriptor to 'select'. I have no record of hitting this one; I suspect my code at the time just didn't use `sleep'. I'm wondering if we still need scm_std_select in Guile now anyway. I'll write again about that. Regards, Neil --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Use-socket-specific-operations-for-socket-ports-on-W.patch >From ea9af46454f044bf01094ea15b3eb0a58717bf58 Mon Sep 17 00:00:00 2001 From: Neil Jerram Date: Fri, 2 Oct 2009 23:13:05 +0100 Subject: [PATCH] Use socket-specific operations for socket ports on Windows * libguile/socket.c (sym_socket): Made global, for use in identifying socket ports in other files. * libguile/fports.c (fport_fill_input): If port is a socket, and #ifdef __MINGW32__, use recv to read from it instead of read. (write_all, fport_flush): Similarly, use send instead of write. (fport_close): Similarly, use closesocket instead of close. --- libguile/fports.c | 34 ++++++++++++++++++++++++++++++---- libguile/socket.c | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/libguile/fports.c b/libguile/fports.c index 5d37495..4bc5075 100644 --- a/libguile/fports.c +++ b/libguile/fports.c @@ -58,6 +58,7 @@ #ifdef __MINGW32__ # include # include +extern SCM sym_socket; #endif /* __MINGW32__ */ #include @@ -604,7 +605,14 @@ fport_fill_input (SCM port) #ifndef __MINGW32__ fport_wait_for_input (port); #endif /* !__MINGW32__ */ - SCM_SYSCALL (count = read (fp->fdes, pt->read_buf, pt->read_buf_size)); + +#ifdef __MINGW32__ + if (scm_is_eq (SCM_FILENAME (port), sym_socket)) + SCM_SYSCALL (count = recv (fp->fdes, pt->read_buf, pt->read_buf_size, 0)); + else +#endif + SCM_SYSCALL (count = read (fp->fdes, pt->read_buf, pt->read_buf_size)); + if (count == -1) scm_syserror ("fport_fill_input"); if (count == 0) @@ -689,7 +697,12 @@ static void write_all (SCM port, const void *data, size_t remaining) { size_t done; - SCM_SYSCALL (done = write (fdes, data, remaining)); +#ifdef __MINGW32__ + if (scm_is_eq (SCM_FILENAME (port), sym_socket)) + SCM_SYSCALL (done = send (fdes, data, remaining, 0)); + else +#endif + SCM_SYSCALL (done = write (fdes, data, remaining)); if (done == -1) SCM_SYSERROR; @@ -774,7 +787,13 @@ fport_flush (SCM port) { long count; - SCM_SYSCALL (count = write (fp->fdes, ptr, remaining)); +#ifdef __MINGW32__ + if (scm_is_eq (SCM_FILENAME (port), sym_socket)) + SCM_SYSCALL (count = send (fp->fdes, ptr, remaining, 0)); + else +#endif + SCM_SYSCALL (count = write (fp->fdes, ptr, remaining)); + if (count < 0) { /* error. assume nothing was written this call, but @@ -846,7 +865,14 @@ fport_close (SCM port) int rv; fport_flush (port); - SCM_SYSCALL (rv = close (fp->fdes)); + +#ifdef __MINGW32__ + if (scm_is_eq (SCM_FILENAME (port), sym_socket)) + SCM_SYSCALL (rv = closesocket (fp->fdes)); + else +#endif + SCM_SYSCALL (rv = close (fp->fdes)); + if (rv == -1 && errno != EBADF) { if (scm_gc_running_p) diff --git a/libguile/socket.c b/libguile/socket.c index ea2ba5c..2cbb7ce 100644 --- a/libguile/socket.c +++ b/libguile/socket.c @@ -439,7 +439,7 @@ SCM_DEFINE (scm_inet_ntop, "inet-ntop", 2, 0, 0, #endif /* HAVE_IPV6 */ -SCM_SYMBOL (sym_socket, "socket"); +SCM_GLOBAL_SYMBOL (sym_socket, "socket"); #define SCM_SOCK_FD_TO_PORT(fd) scm_fdes_to_port (fd, "r+0", sym_socket) -- 1.5.6.5 --=-=-=--