unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Scott McPeak <smcpeak@coverity.com>
To: Neil Jerram <neil@ossau.uklinux.net>
Cc: bug-guile@gnu.org
Subject: Re: windows sockets vs. file descriptors bugs in Guile
Date: Fri, 02 Oct 2009 17:03:02 -0700	[thread overview]
Message-ID: <4AC694B6.2030900@coverity.com> (raw)
In-Reply-To: <87iqexbf3e.fsf@ossau.uklinux.net>

> 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?

Except for the modifications to 'scm_std_select', the two patches are
nearly equivalent.  The differences are:

* I exported 'scm_is_socket_port()' rather than proliferate the hack
of checking for equality with 'sym_socket'.  That seemed like a good
idea because I know the hack is buggy: it is defeated by
'set-port-filename!'.

* I avoided calling socket functions from fports.c, since translation
units that use socket functions typically have to do a lot of
gyrations at the beginning to pull in the right headers on the right
systems.  See the top of socket.c.  Since fports.c does not have all
that, there is a strong chance that it wouldn't compile on some
systems, if it were not for the next point.

* I made changes that affect all systems, rather than using #ifdefs
to make it Windows-only.  As indicated in the comments, there are two
reasons for this:

   a. Syntax: Code is far less readable when sprinkled with #ifdefs.
   I've had the displeasure of reading and maintaining code with heavy
   #ifdefs, and it's not fun.  Guile is currently relatively free of such
   hacks, because it does a good job of factoring system-specific
   functionality so it's only exposed to a limited set of modules, and I
   was trying to keep it that way.

   b. Semantics: Whenever a program explicitly does something different
   depending on the platform, that's an invitation to a platform-specific
   bug.  If indeed it is correct to call to 'recv(_,_,_,0)' on a socket
   instead of 'read(_,_,_)' (an equivalence POSIX guarantees) on Windows,
   then it should be correct to do so on every platform.  And if it's
   wrong or inefficient on some platform, we'd like to know ASAP, right?

These differences are mainly stylistic and future-proofing.  You're
certainly free to ignore them, I just wanted to elaborate on the
reasons in case they weren't clear.

>> * 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.

As for the change to 'scm_std_select', without that change, the code
does not work.  Using my original testcase (plus a couple of calls to
'flush-all-ports', necessary to see the "listening" message, that I
inadvertently omitted in my original post), Guile-1.8.7 with my
changes removed and yours added instead says:

   > ./guile.exe -e main -s testsockets.scm server 8888
   listening on port 8888
   ERROR: In procedure accept:
   ERROR: Socket operation on non-socket
   (exit code of 1)

The reason for this is that 'scm_accept' calls 'scm_std_select', which
sticks a pipe file descriptor into the set of file descriptors to be
checked for reading ('readfds'), which Windows does not like.  My
program never calls 'sleep'--Guile adds the sleep pipe
unconditionally.

Once I add just my changes to threads.c on top of your changes to
socket.c, the test case works perfectly.

While the changes to 'scm_std_select' are certainly the ugliest of
those I proposed, some sort of change is required in order to get
socket server processes to work in Guile-1.8.7 on Windows, as my test
case shows.

As for copyright on my patch, I'm happy to assign copyright; just let
me know what I need to do.

-Scott




  reply	other threads:[~2009-10-03  0:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-01  4:15 windows sockets vs. file descriptors bugs in Guile Scott McPeak
2009-10-01  7:43 ` Ludovic Courtès
2009-10-02 22:33 ` Neil Jerram
2009-10-03  0:03   ` Scott McPeak [this message]
2010-03-27 22:06     ` Neil Jerram
2010-03-27 22:24       ` Neil Jerram

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=4AC694B6.2030900@coverity.com \
    --to=smcpeak@coverity.com \
    --cc=bug-guile@gnu.org \
    --cc=neil@ossau.uklinux.net \
    /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).