* select.cc (struct socketinf): Convert ser_num and w4 to dynamically
allocated arrays. Add max_w4 member to keep track. (thread_socket): Make timeout depending on number of sockets to wait for. Loop WFMO over all sockets. (start_thread_socket): Handle any number of sockets. Fix typo. Don't close socket event in out of memory condition. (socket_cleanup): Free ser_num and w4.
This commit is contained in:
parent
d95c57921f
commit
9565e2333c
|
@ -1,3 +1,13 @@
|
||||||
|
2006-10-11 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* select.cc (struct socketinf): Convert ser_num and w4 to dynamically
|
||||||
|
allocated arrays. Add max_w4 member to keep track.
|
||||||
|
(thread_socket): Make timeout depending on number of sockets to wait
|
||||||
|
for. Loop WFMO over all sockets.
|
||||||
|
(start_thread_socket): Handle any number of sockets. Fix typo. Don't
|
||||||
|
close socket event in out of memory condition.
|
||||||
|
(socket_cleanup): Free ser_num and w4.
|
||||||
|
|
||||||
2006-10-06 David Jade <d3@mutable.net>
|
2006-10-06 David Jade <d3@mutable.net>
|
||||||
|
|
||||||
* path.cc (path_conv::get_nt_native_path): Properly detect \\?\ paths.
|
* path.cc (path_conv::get_nt_native_path): Properly detect \\?\ paths.
|
||||||
|
|
|
@ -1285,9 +1285,10 @@ static int start_thread_socket (select_record *, select_stuff *);
|
||||||
struct socketinf
|
struct socketinf
|
||||||
{
|
{
|
||||||
cygthread *thread;
|
cygthread *thread;
|
||||||
|
int max_w4;
|
||||||
int num_w4;
|
int num_w4;
|
||||||
LONG ser_num[MAXIMUM_WAIT_OBJECTS];
|
LONG *ser_num;
|
||||||
HANDLE w4[MAXIMUM_WAIT_OBJECTS];
|
HANDLE *w4;
|
||||||
select_record *start;
|
select_record *start;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1295,6 +1296,7 @@ static DWORD WINAPI
|
||||||
thread_socket (void *arg)
|
thread_socket (void *arg)
|
||||||
{
|
{
|
||||||
socketinf *si = (socketinf *) arg;
|
socketinf *si = (socketinf *) arg;
|
||||||
|
DWORD timeout = 64 / (si->max_w4 / MAXIMUM_WAIT_OBJECTS);
|
||||||
bool event = false;
|
bool event = false;
|
||||||
|
|
||||||
select_printf ("stuff_start %p", si->start);
|
select_printf ("stuff_start %p", si->start);
|
||||||
|
@ -1305,18 +1307,22 @@ thread_socket (void *arg)
|
||||||
if (peek_socket (s, false))
|
if (peek_socket (s, false))
|
||||||
event = true;
|
event = true;
|
||||||
if (!event)
|
if (!event)
|
||||||
|
for (int i = 0; i < si->max_w4; i += MAXIMUM_WAIT_OBJECTS)
|
||||||
|
switch (WaitForMultipleObjects (min (si->num_w4 - i,
|
||||||
|
MAXIMUM_WAIT_OBJECTS),
|
||||||
|
si->w4 + i, FALSE, timeout))
|
||||||
{
|
{
|
||||||
switch (WaitForMultipleObjects (si->num_w4, si->w4, FALSE, 50))
|
|
||||||
{
|
|
||||||
case WAIT_OBJECT_0:
|
|
||||||
case WAIT_FAILED:
|
case WAIT_FAILED:
|
||||||
goto out;
|
goto out;
|
||||||
|
case WAIT_OBJECT_0:
|
||||||
|
if (!i) /* Socket event set. */
|
||||||
|
goto out;
|
||||||
|
break;
|
||||||
case WAIT_TIMEOUT:
|
case WAIT_TIMEOUT:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
out:
|
out:
|
||||||
select_printf ("leaving thread_socket");
|
select_printf ("leaving thread_socket");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1334,6 +1340,11 @@ start_thread_socket (select_record *me, select_stuff *stuff)
|
||||||
}
|
}
|
||||||
|
|
||||||
si = new socketinf;
|
si = new socketinf;
|
||||||
|
si->ser_num = (LONG *) malloc (MAXIMUM_WAIT_OBJECTS * sizeof (LONG));
|
||||||
|
si->w4 = (HANDLE *) malloc (MAXIMUM_WAIT_OBJECTS * sizeof (HANDLE));
|
||||||
|
if (!si->ser_num || !si->w4)
|
||||||
|
return 0;
|
||||||
|
si->max_w4 = MAXIMUM_WAIT_OBJECTS;
|
||||||
select_record *s = &stuff->start;
|
select_record *s = &stuff->start;
|
||||||
if (_my_tls.locals.select_sockevt != INVALID_HANDLE_VALUE)
|
if (_my_tls.locals.select_sockevt != INVALID_HANDLE_VALUE)
|
||||||
si->w4[0] = _my_tls.locals.select_sockevt;
|
si->w4[0] = _my_tls.locals.select_sockevt;
|
||||||
|
@ -1348,17 +1359,28 @@ start_thread_socket (select_record *me, select_stuff *stuff)
|
||||||
/* No event/socket should show up multiple times. Every socket
|
/* No event/socket should show up multiple times. Every socket
|
||||||
is uniquely identified by its serial number in the global
|
is uniquely identified by its serial number in the global
|
||||||
wsock_events record. */
|
wsock_events record. */
|
||||||
const LONG ser_num = ((fhandler_socket *) me->fh)->serial_number ();
|
const LONG ser_num = ((fhandler_socket *) s->fh)->serial_number ();
|
||||||
for (int i = 1; i < si->num_w4; ++i)
|
for (int i = 1; i < si->num_w4; ++i)
|
||||||
if (si->ser_num[i] == ser_num)
|
if (si->ser_num[i] == ser_num)
|
||||||
goto continue_outer_loop;
|
goto continue_outer_loop;
|
||||||
if (si->num_w4 < MAXIMUM_WAIT_OBJECTS)
|
if (si->num_w4 >= si->max_w4)
|
||||||
{
|
{
|
||||||
si->ser_num[si->num_w4] = ser_num;
|
LONG *nser = (LONG *) realloc (si->ser_num,
|
||||||
si->w4[si->num_w4++] = ((fhandler_socket *) me->fh)->wsock_event ();
|
(si->max_w4 + MAXIMUM_WAIT_OBJECTS)
|
||||||
|
* sizeof (LONG));
|
||||||
|
if (!nser)
|
||||||
|
return 0;
|
||||||
|
si->ser_num = nser;
|
||||||
|
HANDLE *nw4 = (HANDLE *) realloc (si->w4,
|
||||||
|
(si->max_w4 + MAXIMUM_WAIT_OBJECTS)
|
||||||
|
* sizeof (HANDLE));
|
||||||
|
if (!nw4)
|
||||||
|
return 0;
|
||||||
|
si->w4 = nw4;
|
||||||
|
si->max_w4 += MAXIMUM_WAIT_OBJECTS;
|
||||||
}
|
}
|
||||||
else /* for now */
|
si->ser_num[si->num_w4] = ser_num;
|
||||||
goto err;
|
si->w4[si->num_w4++] = ((fhandler_socket *) s->fh)->wsock_event ();
|
||||||
continue_outer_loop:
|
continue_outer_loop:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -1368,10 +1390,6 @@ start_thread_socket (select_record *me, select_stuff *stuff)
|
||||||
si->thread = new cygthread (thread_socket, 0, si, "select_socket");
|
si->thread = new cygthread (thread_socket, 0, si, "select_socket");
|
||||||
me->h = *si->thread;
|
me->h = *si->thread;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
err:
|
|
||||||
CloseHandle (si->w4[0]);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1386,6 +1404,10 @@ socket_cleanup (select_record *, select_stuff *stuff)
|
||||||
si->thread->detach ();
|
si->thread->detach ();
|
||||||
ResetEvent (si->w4[0]);
|
ResetEvent (si->w4[0]);
|
||||||
stuff->device_specific_socket = NULL;
|
stuff->device_specific_socket = NULL;
|
||||||
|
if (si->ser_num)
|
||||||
|
free (si->ser_num);
|
||||||
|
if (si->w4)
|
||||||
|
free (si->w4);
|
||||||
delete si;
|
delete si;
|
||||||
}
|
}
|
||||||
select_printf ("returning");
|
select_printf ("returning");
|
||||||
|
|
Loading…
Reference in New Issue