* fhandler_socket.cc (fhandler_socket::evaluate_events): Make erase

const in parameter list.
	(fhandler_socket::wait_for_events): Take a DWORD flags value instead of
	just a bool.  Call evaluate_events with erase flag according to
	MSG_PEEK value in flags.  Replace check for dontwait with check for
	MSG_DONTWAIT in flags.
	(fhandler_socket::connect): Call wait_for_events with 0 flags value.
	(fhandler_socket::accept4): Ditto.
	(fhandler_socket::recv_internal): Save flags in wait_flags.  Drop
	dontwait variable.  Call wait_for_events with wait_flags.
	(fhandler_socket::send_internal): Save MSG_DONTWAIT flag in wait_flags
	and call wait_for_events with wait_flags as argument.  Drop dontwait
	variable.
	* fhandler.h (class fhandler_socket): Change second parameter in
	declaration of wait_for_events to const DWORD.
This commit is contained in:
Corinna Vinschen 2010-03-22 10:47:53 +00:00
parent 0f6de51ae2
commit 65b4b495c6
3 changed files with 31 additions and 12 deletions

View File

@ -1,3 +1,21 @@
2010-03-22 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::evaluate_events): Make erase
const in parameter list.
(fhandler_socket::wait_for_events): Take a DWORD flags value instead of
just a bool. Call evaluate_events with erase flag according to
MSG_PEEK value in flags. Replace check for dontwait with check for
MSG_DONTWAIT in flags.
(fhandler_socket::connect): Call wait_for_events with 0 flags value.
(fhandler_socket::accept4): Ditto.
(fhandler_socket::recv_internal): Save flags in wait_flags. Drop
dontwait variable. Call wait_for_events with wait_flags.
(fhandler_socket::send_internal): Save MSG_DONTWAIT flag in wait_flags
and call wait_for_events with wait_flags as argument. Drop dontwait
variable.
* fhandler.h (class fhandler_socket): Change second parameter in
declaration of wait_for_events to const DWORD.
2010-03-19 Corinna Vinschen <corinna@vinschen.de> 2010-03-19 Corinna Vinschen <corinna@vinschen.de>
* fhandler_disk_file.cc (fhandler_cygdrive::fstat): Add standard read * fhandler_disk_file.cc (fhandler_cygdrive::fstat): Add standard read

View File

@ -432,7 +432,7 @@ class fhandler_socket: public fhandler_base
const HANDLE wsock_event () const { return wsock_evt; } const HANDLE wsock_event () const { return wsock_evt; }
const LONG serial_number () const { return wsock_events->serial_number; } const LONG serial_number () const { return wsock_events->serial_number; }
private: private:
int wait_for_events (const long event_mask, bool dontwait); int wait_for_events (const long event_mask, const DWORD flags);
void release_events (); void release_events ();
pid_t sec_pid; pid_t sec_pid;

View File

@ -540,7 +540,7 @@ fhandler_socket::init_events ()
int int
fhandler_socket::evaluate_events (const long event_mask, long &events, fhandler_socket::evaluate_events (const long event_mask, long &events,
bool erase) const bool erase)
{ {
int ret = 0; int ret = 0;
long events_now = 0; long events_now = 0;
@ -587,7 +587,7 @@ fhandler_socket::evaluate_events (const long event_mask, long &events,
} }
int int
fhandler_socket::wait_for_events (const long event_mask, bool dontwait) fhandler_socket::wait_for_events (const long event_mask, const DWORD flags)
{ {
if (async_io ()) if (async_io ())
return 0; return 0;
@ -595,9 +595,10 @@ fhandler_socket::wait_for_events (const long event_mask, bool dontwait)
int ret; int ret;
long events; long events;
while (!(ret = evaluate_events (event_mask, events, true)) && !events) while (!(ret = evaluate_events (event_mask, events, !(flags & MSG_PEEK)))
&& !events)
{ {
if (is_nonblocking () || dontwait) if (is_nonblocking () || (flags & MSG_DONTWAIT))
{ {
WSASetLastError (WSAEWOULDBLOCK); WSASetLastError (WSAEWOULDBLOCK);
return SOCKET_ERROR; return SOCKET_ERROR;
@ -1100,7 +1101,7 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen)
if (!is_nonblocking () if (!is_nonblocking ()
&& res == SOCKET_ERROR && res == SOCKET_ERROR
&& WSAGetLastError () == WSAEWOULDBLOCK) && WSAGetLastError () == WSAEWOULDBLOCK)
res = wait_for_events (FD_CONNECT | FD_CLOSE, false); res = wait_for_events (FD_CONNECT | FD_CLOSE, 0);
if (!res) if (!res)
err = 0; err = 0;
@ -1201,7 +1202,7 @@ fhandler_socket::accept4 (struct sockaddr *peer, int *len, int flags)
int llen = sizeof (struct sockaddr_storage); int llen = sizeof (struct sockaddr_storage);
int res = 0; int res = 0;
while (!(res = wait_for_events (FD_ACCEPT | FD_CLOSE, false)) while (!(res = wait_for_events (FD_ACCEPT | FD_CLOSE, 0))
&& (res = ::accept (get_socket (), (struct sockaddr *) &lpeer, &llen)) && (res = ::accept (get_socket (), (struct sockaddr *) &lpeer, &llen))
== SOCKET_ERROR == SOCKET_ERROR
&& WSAGetLastError () == WSAEWOULDBLOCK) && WSAGetLastError () == WSAEWOULDBLOCK)
@ -1424,8 +1425,8 @@ fhandler_socket::recv_internal (LPWSAMSG wsamsg)
bool use_recvmsg = false; bool use_recvmsg = false;
static NO_COPY LPFN_WSARECVMSG WSARecvMsg; static NO_COPY LPFN_WSARECVMSG WSARecvMsg;
bool waitall = !!(wsamsg->dwFlags & MSG_WAITALL); DWORD wait_flags = wsamsg->dwFlags;
bool dontwait = !!(wsamsg->dwFlags & MSG_DONTWAIT); bool waitall = !!(wait_flags & MSG_WAITALL);
wsamsg->dwFlags &= (MSG_OOB | MSG_PEEK | MSG_DONTROUTE); wsamsg->dwFlags &= (MSG_OOB | MSG_PEEK | MSG_DONTROUTE);
if (wsamsg->Control.len > 0) if (wsamsg->Control.len > 0)
{ {
@ -1452,7 +1453,7 @@ fhandler_socket::recv_internal (LPWSAMSG wsamsg)
/* Note: Don't call WSARecvFrom(MSG_PEEK) without actually having data /* Note: Don't call WSARecvFrom(MSG_PEEK) without actually having data
waiting in the buffers, otherwise the event handling gets messed up waiting in the buffers, otherwise the event handling gets messed up
for some reason. */ for some reason. */
while (!(res = wait_for_events (evt_mask | FD_CLOSE, dontwait)) while (!(res = wait_for_events (evt_mask | FD_CLOSE, wait_flags))
|| saw_shutdown_read ()) || saw_shutdown_read ())
{ {
if (use_recvmsg) if (use_recvmsg)
@ -1609,7 +1610,7 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
DWORD ret = 0, err = 0, sum = 0, off = 0; DWORD ret = 0, err = 0, sum = 0, off = 0;
WSABUF buf; WSABUF buf;
bool use_sendmsg = false; bool use_sendmsg = false;
bool dontwait = !!(flags & MSG_DONTWAIT); DWORD wait_flags = flags & MSG_DONTWAIT;
bool nosignal = !(flags & MSG_NOSIGNAL); bool nosignal = !(flags & MSG_NOSIGNAL);
flags &= (MSG_OOB | MSG_DONTROUTE); flags &= (MSG_OOB | MSG_DONTROUTE);
@ -1649,7 +1650,7 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags)
} }
} }
while (res && err == WSAEWOULDBLOCK while (res && err == WSAEWOULDBLOCK
&& !(res = wait_for_events (FD_WRITE | FD_CLOSE, dontwait))); && !(res = wait_for_events (FD_WRITE | FD_CLOSE, wait_flags)));
if (!res) if (!res)
{ {