public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
From: Jon TURNEY <jon.turney@dronecode.org.uk>
To: cygwin-xfree@cygwin.com, cygwin@cygwin.com
Subject: /dev/windows and select() [was Re: Slow response to keypresses in xorg-server-1.8.0-1]
Date: Sun, 29 Aug 2010 14:17:00 -0000	[thread overview]
Message-ID: <4C7A62FD.10506@dronecode.org.uk> (raw)
In-Reply-To: <AANLkTin6e74L1_Z7KzoOVmynQ+eW6a8tkTK_A21-mpg+@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1046 bytes --]

On 08/08/2010 12:04, Andy Koppe wrote:
> On 7 August 2010 23:07, Jon TURNEY wrote:
>> Hmmm, looking again at the implementation of select(), I don't immediately
>> see that when waiting on /dev/windows, it checks that the message queue has
>> old messages on it before waiting.  The MSDN documentation for
>> MsgWaitForMultipleObjects() seems to says that messages which had arrived
>> before the last PeekMessage() etc. aren't considered new and so don't end
>> the wait?
>
> I think you're right, a call to PeekMessage is needed for proper
> select() semantics: it shouldn't block if data is available for
> reading.

Attached is a small test-case which seems to demonstrate this problem.

Run ./dev-windows-select-test and observe select() blocks for the full 
timeout, despite the fact that the /dev/windows fd is ready for reading (and 
it reported as such as the end of the timeout)

If you run './dev-windows-select-test -skip' to skip the PeekMessage(), 
select() returns immediately, indicating the /dev/windows fd is ready for reading.

[-- Attachment #2: dev-windows-select-test.c --]
[-- Type: text/plain, Size: 818 bytes --]


#include <stdio.h>
#include <fcntl.h>
#include <sys/select.h>
#include <errno.h>
#include <windows.h>

// gcc -o dev-windows-select-test.exe dev-windows-select-test.c -Wall -mwindows

int main(int argc, char *argv[])
{
  int fd = open("/dev/windows", O_RDONLY);

  if (PostMessage(NULL, WM_USER, 0, 0) != 0)
    printf("PostMessage succeeded\n");
  else
    printf("PostMessage failed\n");

  if (argc <= 1)
    {
      MSG msg;
      if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
        printf("PeekMessage reports a message available\n");
    }

  struct timeval timeout;
  timeout.tv_sec = 5;
  timeout.tv_usec = 0;

  fd_set readfds;
  FD_ZERO(&readfds);
  FD_SET(fd, &readfds);

  int rc = select(fd+1, &readfds, NULL, NULL, &timeout);
  printf("select returned %d %s\n", rc, strerror(errno));

  return 0;
}

[-- Attachment #3: Type: text/plain, Size: 223 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/

  reply	other threads:[~2010-08-29 13:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-01 13:49 Slow response to keypresses in xorg-server-1.8.0-1 Ken Brown
2010-05-02 20:52 ` Ken Brown
2010-05-18 18:52   ` Ryan Johnson
2010-06-30 17:40   ` Jon TURNEY
2010-07-01  2:02     ` Ken Brown
2010-07-01 21:07     ` Marco Atzeri
2010-07-19 14:11     ` Simon Marlow
2010-08-03 16:43     ` Ryan Johnson
2010-08-05 18:53     ` Laurent Montaron
2010-08-07 15:39       ` Reini Urban
2010-08-07 22:07         ` Jon TURNEY
2010-08-08 11:05           ` Andy Koppe
2010-08-29 14:17             ` Jon TURNEY [this message]
2010-08-29 14:41               ` /dev/windows and select() [was Re: Slow response to keypresses in xorg-server-1.8.0-1] Corinna Vinschen
2010-08-29 14:50                 ` Corinna Vinschen
2010-08-29 15:09                   ` Corinna Vinschen
2010-08-30 11:23                     ` Trollope, David
2010-08-30 12:05               ` Corinna Vinschen
2010-08-30 12:33                 ` Jon TURNEY

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=4C7A62FD.10506@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-xfree@cygwin.com \
    --cc=cygwin@cygwin.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).