* fhandler_socket.cc (sock_event::~sock_event): New method.
(sock_event::load): Change to void. Check if winsock2 is available. (socke_event::wait): Return 0 if interruptible mode is not available. (fhandler_socket::connect): Remove checks for winsock2 availability. (fhandler_socket::accept): Ditto.
This commit is contained in:
parent
dae86e4507
commit
a946fb037d
@ -1,3 +1,11 @@
|
|||||||
|
2003-05-27 Thomas Pfaff <tpfaff@gmx.net>
|
||||||
|
|
||||||
|
* fhandler_socket.cc (sock_event::~sock_event): New method.
|
||||||
|
(sock_event::load): Change to void. Check if winsock2 is available.
|
||||||
|
(socke_event::wait): Return 0 if interruptible mode is not available.
|
||||||
|
(fhandler_socket::connect): Remove checks for winsock2 availability.
|
||||||
|
(fhandler_socket::accept): Ditto.
|
||||||
|
|
||||||
2003-05-27 Corinna Vinschen <corinna@vinschen.de>
|
2003-05-27 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* fhandler_socket.cc (fhandler_socket::dup): First try duplicating
|
* fhandler_socket.cc (fhandler_socket::dup): First try duplicating
|
||||||
|
@ -131,31 +131,44 @@ public:
|
|||||||
ev[0] = WSA_INVALID_EVENT;
|
ev[0] = WSA_INVALID_EVENT;
|
||||||
ev[1] = signal_arrived;
|
ev[1] = signal_arrived;
|
||||||
}
|
}
|
||||||
bool load (SOCKET sock, int type_bit)
|
~sock_event ()
|
||||||
{
|
{
|
||||||
if ((ev[0] = WSACreateEvent ()) == WSA_INVALID_EVENT)
|
if (ev[0] != WSA_INVALID_EVENT)
|
||||||
return false;
|
WSACloseEvent (ev[0]);
|
||||||
|
}
|
||||||
|
void load (SOCKET sock, int type_bit)
|
||||||
|
{
|
||||||
|
if (!winsock2_active)
|
||||||
|
/* Can not wait for signal if winsock2 is not active */
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ev[0] == WSA_INVALID_EVENT)
|
||||||
|
if ((ev[0] = WSACreateEvent ()) == WSA_INVALID_EVENT)
|
||||||
|
return;
|
||||||
|
|
||||||
evt_sock = sock;
|
evt_sock = sock;
|
||||||
evt_type_bit = type_bit;
|
evt_type_bit = type_bit;
|
||||||
if (WSAEventSelect (evt_sock, ev[0], 1 << evt_type_bit))
|
if (WSAEventSelect (evt_sock, ev[0], 1 << evt_type_bit))
|
||||||
{
|
{
|
||||||
WSACloseEvent (ev[0]);
|
WSACloseEvent (ev[0]);
|
||||||
ev[0] = WSA_INVALID_EVENT;
|
ev[0] = WSA_INVALID_EVENT;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
int wait ()
|
int wait ()
|
||||||
{
|
{
|
||||||
WSANETWORKEVENTS sock_event;
|
WSANETWORKEVENTS sock_event;
|
||||||
int wait_result = WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE,
|
int wait_result;
|
||||||
|
|
||||||
|
if (ev[0] == WSA_INVALID_EVENT)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
wait_result = WSAWaitForMultipleEvents (2, ev, FALSE, WSA_INFINITE,
|
||||||
FALSE);
|
FALSE);
|
||||||
if (wait_result == WSA_WAIT_EVENT_0)
|
if (wait_result == WSA_WAIT_EVENT_0)
|
||||||
WSAEnumNetworkEvents (evt_sock, ev[0], &sock_event);
|
WSAEnumNetworkEvents (evt_sock, ev[0], &sock_event);
|
||||||
|
|
||||||
/* Cleanup, Revert to blocking. */
|
/* Cleanup, Revert to blocking. */
|
||||||
WSAEventSelect (evt_sock, ev[0], 0);
|
WSAEventSelect (evt_sock, ev[0], 0);
|
||||||
WSACloseEvent (ev[0]);
|
|
||||||
unsigned long nonblocking = 0;
|
unsigned long nonblocking = 0;
|
||||||
ioctlsocket (evt_sock, FIONBIO, &nonblocking);
|
ioctlsocket (evt_sock, FIONBIO, &nonblocking);
|
||||||
|
|
||||||
@ -565,17 +578,13 @@ fhandler_socket::connect (const struct sockaddr *name, int namelen)
|
|||||||
if (!get_inet_addr (name, namelen, &sin, &namelen, secret))
|
if (!get_inet_addr (name, namelen, &sin, &namelen, secret))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (winsock2_active && !is_nonblocking () && !is_connect_pending ())
|
if (!is_nonblocking () && !is_connect_pending ())
|
||||||
if (!evt.load (get_socket (), FD_CONNECT_BIT))
|
evt.load (get_socket (), FD_CONNECT_BIT);
|
||||||
{
|
|
||||||
set_winsock_errno ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = ::connect (get_socket (), (sockaddr *) &sin, namelen);
|
res = ::connect (get_socket (), (sockaddr *) &sin, namelen);
|
||||||
|
|
||||||
if (winsock2_active && res && !is_nonblocking () && !is_connect_pending () &&
|
if (res && !is_nonblocking () && !is_connect_pending ()
|
||||||
WSAGetLastError () == WSAEWOULDBLOCK)
|
&& WSAGetLastError () == WSAEWOULDBLOCK)
|
||||||
switch (evt.wait ())
|
switch (evt.wait ())
|
||||||
{
|
{
|
||||||
case 1: /* Signal */
|
case 1: /* Signal */
|
||||||
@ -685,14 +694,10 @@ fhandler_socket::accept (struct sockaddr *peer, int *len)
|
|||||||
if (len && ((unsigned) *len < sizeof (struct sockaddr_in)))
|
if (len && ((unsigned) *len < sizeof (struct sockaddr_in)))
|
||||||
*len = sizeof (struct sockaddr_in);
|
*len = sizeof (struct sockaddr_in);
|
||||||
|
|
||||||
if (winsock2_active && !is_nonblocking ())
|
if (!is_nonblocking ())
|
||||||
{
|
{
|
||||||
sock_event evt;
|
sock_event evt;
|
||||||
if (!evt.load (get_socket (), FD_ACCEPT_BIT))
|
evt.load (get_socket (), FD_ACCEPT_BIT);
|
||||||
{
|
|
||||||
set_winsock_errno ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
switch (evt.wait ())
|
switch (evt.wait ())
|
||||||
{
|
{
|
||||||
case 1: /* Signal */
|
case 1: /* Signal */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user