summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-03-09 14:40:45 +0000
committerCorinna Vinschen <corinna@vinschen.de>2009-03-09 14:40:45 +0000
commit71d13bca551f5629a0c903807028088cc97bfc0e (patch)
tree731494f846997d4bbaec97e63897c59f4ac276c4 /winsup/cygwin
parentc47426aedbb385c8717fdf4e029bcf5c3e70bc53 (diff)
downloadcygnal-71d13bca551f5629a0c903807028088cc97bfc0e.tar.gz
cygnal-71d13bca551f5629a0c903807028088cc97bfc0e.tar.bz2
cygnal-71d13bca551f5629a0c903807028088cc97bfc0e.zip
* fhandler.h (fhandler_socket::wait_for_events): Take additional
parameter "dontwait". * fhandler_socket.cc (fhandler_socket::wait_for_events): Act as if the socket is non-blocking if dontwait is true. (fhandler_socket::recv_internal): Use incoming MSG_DONTWAIT flag to set the wait_for_events dontwait parameter. (fhandler_socket::send_internal): Ditto. Optimize code slightly. * include/cygwin/socket.h (MSG_DONTWAIT): Define. * include/cygwin/version.h: Bump API minor number.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog12
-rw-r--r--winsup/cygwin/fhandler.h2
-rw-r--r--winsup/cygwin/fhandler_socket.cc26
-rw-r--r--winsup/cygwin/include/cygwin/socket.h3
-rw-r--r--winsup/cygwin/include/cygwin/version.h3
5 files changed, 30 insertions, 16 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 98c230286..870be02e3 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,17 @@
2009-03-09 Corinna Vinschen <corinna@vinschen.de>
+ * fhandler.h (fhandler_socket::wait_for_events): Take additional
+ parameter "dontwait".
+ * fhandler_socket.cc (fhandler_socket::wait_for_events): Act as if the
+ socket is non-blocking if dontwait is true.
+ (fhandler_socket::recv_internal): Use incoming MSG_DONTWAIT flag to
+ set the wait_for_events dontwait parameter.
+ (fhandler_socket::send_internal): Ditto. Optimize code slightly.
+ * include/cygwin/socket.h (MSG_DONTWAIT): Define.
+ * include/cygwin/version.h: Bump API minor number.
+
+2009-03-09 Corinna Vinschen <corinna@vinschen.de>
+
* cygwin.din: Export wcsftime.
* posix.sgml: Move wcsftime to SUSv4 list.
* include/cygwin/version.h: Bump API minor number.
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 80ec297a5..0fc075d83 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -420,7 +420,7 @@ class fhandler_socket: public fhandler_base
const HANDLE wsock_event () const { return wsock_evt; }
const LONG serial_number () const { return wsock_events->serial_number; }
private:
- int wait_for_events (const long event_mask);
+ int wait_for_events (const long event_mask, bool dontwait = false);
void release_events ();
pid_t sec_pid;
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 89a162361..7ab1ce8eb 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -580,7 +580,7 @@ fhandler_socket::evaluate_events (const long event_mask, long &events,
}
int
-fhandler_socket::wait_for_events (const long event_mask)
+fhandler_socket::wait_for_events (const long event_mask, bool dontwait)
{
if (async_io ())
return 0;
@@ -590,7 +590,7 @@ fhandler_socket::wait_for_events (const long event_mask)
while (!(ret = evaluate_events (event_mask, events, true)) && !events)
{
- if (is_nonblocking ())
+ if (is_nonblocking () || dontwait)
{
WSASetLastError (WSAEWOULDBLOCK);
return SOCKET_ERROR;
@@ -1312,7 +1312,8 @@ fhandler_socket::recv_internal (LPWSAMSG wsamsg)
bool use_recvmsg = false;
static LPFN_WSARECVMSG WSARecvMsg;
- bool waitall = (wsamsg->dwFlags & MSG_WAITALL);
+ bool waitall = !!(wsamsg->dwFlags & MSG_WAITALL);
+ bool dontwait = !!(wsamsg->dwFlags & MSG_DONTWAIT);
wsamsg->dwFlags &= (MSG_OOB | MSG_PEEK | MSG_DONTROUTE);
if (wsamsg->Control.len > 0)
{
@@ -1339,7 +1340,7 @@ fhandler_socket::recv_internal (LPWSAMSG wsamsg)
/* Note: Don't call WSARecvFrom(MSG_PEEK) without actually having data
waiting in the buffers, otherwise the event handling gets messed up
for some reason. */
- while (!(res = wait_for_events (evt_mask | FD_CLOSE))
+ while (!(res = wait_for_events (evt_mask | FD_CLOSE, dontwait))
|| saw_shutdown_read ())
{
if (use_recvmsg)
@@ -1472,7 +1473,10 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
DWORD ret = 0, err = 0, sum = 0, off = 0;
WSABUF buf;
bool use_sendmsg = false;
+ bool dontwait = !!(flags & MSG_DONTWAIT);
+ bool nosignal = !(flags & MSG_NOSIGNAL);
+ flags &= (MSG_OOB | MSG_DONTROUTE);
if (wsamsg->Control.len > 0)
use_sendmsg = true;
for (DWORD i = 0; i < wsamsg->dwBufferCount;
@@ -1486,14 +1490,10 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
do
{
if (use_sendmsg)
- res = WSASendMsg (get_socket (), wsamsg,
- flags & (MSG_OOB | MSG_DONTROUTE), &ret,
- NULL, NULL);
+ res = WSASendMsg (get_socket (), wsamsg, flags, &ret, NULL, NULL);
else
- res = WSASendTo (get_socket (), &buf, 1, &ret,
- flags & (MSG_OOB | MSG_DONTROUTE),
- wsamsg->name, wsamsg->namelen,
- NULL, NULL);
+ res = WSASendTo (get_socket (), &buf, 1, &ret, flags,
+ wsamsg->name, wsamsg->namelen, NULL, NULL);
if (res && (err = WSAGetLastError ()) == WSAEWOULDBLOCK)
{
LOCK_EVENTS;
@@ -1502,7 +1502,7 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
}
}
while (res && err == WSAEWOULDBLOCK
- && !(res = wait_for_events (FD_WRITE | FD_CLOSE)));
+ && !(res = wait_for_events (FD_WRITE | FD_CLOSE), dontwait));
if (!res)
{
@@ -1527,7 +1527,7 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
if (get_errno () == ESHUTDOWN && get_socket_type () == SOCK_STREAM)
{
set_errno (EPIPE);
- if (!(flags & MSG_NOSIGNAL))
+ if (!nosignal)
raise (SIGPIPE);
}
}
diff --git a/winsup/cygwin/include/cygwin/socket.h b/winsup/cygwin/include/cygwin/socket.h
index f521f0ad8..fdb842dc6 100644
--- a/winsup/cygwin/include/cygwin/socket.h
+++ b/winsup/cygwin/include/cygwin/socket.h
@@ -1,6 +1,6 @@
/* cygwin/socket.h
- Copyright 1999, 2000, 2001, 2005, 2006, 2007 Red Hat, Inc.
+ Copyright 1999, 2000, 2001, 2005, 2006, 2007, 2009 Red Hat, Inc.
This file is part of Cygwin.
@@ -191,6 +191,7 @@ struct OLD_msghdr
#define MSG_PEEK 0x2 /* peek at incoming message */
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
#define MSG_WAITALL 0x8 /* wait for all requested bytes */
+#define MSG_DONTWAIT 0x10 /* selective non-blocking operation */
#define MSG_NOSIGNAL 0x20 /* Don't raise SIGPIPE */
#define MSG_TRUNC 0x0100 /* Normal data truncated */
#define MSG_CTRUNC 0x0200 /* Control data truncated */
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index d0293c096..6a321f98d 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -352,12 +352,13 @@ details. */
201: Export wprintf, fwprintf, swprintf, vwprintf, vfwprintf, vswprintf.
202: Export gethostbyname2.
203: Export wcsftime.
+ 204: recv/send flag MSG_DONTWAIT added.
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 203
+#define CYGWIN_VERSION_API_MINOR 204
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible