1 /* fhandler_windows.cc: code to access windows message queues.
3 Written by Sergey S. Okhapkin (sos@prospect.com.ru).
4 Feedback and testing by Andy Piper (andyp@parallax.co.uk).
6 This file is part of Cygwin.
8 This software is a copyrighted work licensed under the terms of the
9 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
21 The following unix-style calls are supported:
23 open ("/dev/windows", flags, mode=0)
24 - create a unix fd for message queue.
27 - return next message from queue. buf must point to MSG
28 structure, len must be >= sizeof (MSG). If read is set to
29 non-blocking and the queue is empty, read call returns -1
30 immediately with errno set to EAGAIN, otherwise it blocks
31 untill the message will be received.
34 - send a message pointed by buf. len argument ignored.
36 ioctl (fd, command, *param)
37 - control read()/write() behavior.
38 ioctl (fd, WINDOWS_POST, NULL): write() will PostMessage();
39 ioctl (fd, WINDOWS_SEND, NULL): write() will SendMessage();
40 ioctl (fd, WINDOWS_HWND, &hWnd): read() messages for
43 select () call marks read fd when any message posted to queue.
46 fhandler_windows::fhandler_windows ()
47 : fhandler_base (), hWnd_ (NULL
), method_ (WINDOWS_POST
)
52 fhandler_windows::open (int flags
, mode_t mode
)
54 return fhandler_base::open ((flags
& ~O_TEXT
) | O_BINARY
, mode
);
58 fhandler_windows::write (const void *buf
, size_t)
60 MSG
*ptr
= (MSG
*) buf
;
62 if (method_
== WINDOWS_POST
)
64 if (!PostMessageW (ptr
->hwnd
, ptr
->message
, ptr
->wParam
, ptr
->lParam
))
70 else if (!SendNotifyMessageW (ptr
->hwnd
, ptr
->message
, ptr
->wParam
,
80 fhandler_windows::read (void *buf
, size_t& len
)
82 MSG
*ptr
= (MSG
*) buf
;
84 if (len
< sizeof (MSG
))
92 wait_signal_arrived
here (w4
[0]);
94 if ((w4
[1] = pthread::get_cancel_event ()) != NULL
)
98 switch (MsgWaitForMultipleObjectsEx (cnt
, w4
,
99 is_nonblocking () ? 0 : INFINITE
,
100 QS_ALLINPUT
| QS_ALLPOSTMESSAGE
,
101 MWMO_INPUTAVAILABLE
))
104 if (_my_tls
.call_signal_handler ())
109 case WAIT_OBJECT_0
+ 1:
110 if (cnt
> 1) /* WAIT_OBJECT_0 + 1 is the cancel event object. */
112 pthread::static_cancel_self ();
116 case WAIT_OBJECT_0
+ 2:
117 if (!PeekMessageW (ptr
, hWnd_
, 0, 0, PM_REMOVE
))
122 else if (ptr
->message
== WM_QUIT
)
141 fhandler_windows::ioctl (unsigned int cmd
, void *val
)
155 hWnd_
= * ((HWND
*) val
);
158 return fhandler_base::ioctl (cmd
, val
);