* Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
* Copyright 2004-2011 Novell, Inc (http://www.novell.com)
*/
+#include <config.h>
+#include <glib.h>
+#include <errno.h>
+
+#include <mono/metadata/mono-ptr-array.h>
+#include <mono/metadata/threadpool.h>
+#include <mono/metadata/threadpool-internals.h>
+#include <mono/utils/mono-semaphore.h>
+#include <mono/utils/mono-poll.h>
#define INIT_POLLFD(a, b, c) {(a)->fd = b; (a)->events = c; (a)->revents = 0;}
struct _tp_poll_data {
typedef struct _tp_poll_data tp_poll_data;
static void tp_poll_shutdown (gpointer event_data);
-static void tp_poll_modify (gpointer event_data, int fd, int operation, int events, gboolean is_new);
+static void tp_poll_modify (gpointer p, int fd, int operation, int events, gboolean is_new);
static void tp_poll_wait (gpointer p);
-static gpointer
+gpointer tp_poll_init (SocketIOData *data);
+
+gpointer
tp_poll_init (SocketIOData *data)
{
tp_poll_data *result;
}
static void
-tp_poll_modify (gpointer event_data, int fd, int operation, int events, gboolean is_new)
+tp_poll_modify (gpointer p, int fd, int operation, int events, gboolean is_new)
{
- tp_poll_data *data = event_data;
+ SocketIOData *socket_io_data;
+ tp_poll_data *data;
char msg [1];
+ int unused G_GNUC_UNUSED;
+
+ socket_io_data = p;
+ data = socket_io_data->event_data;
+ mono_mutex_unlock (&socket_io_data->io_lock);
+
MONO_SEM_WAIT (&data->new_sem);
INIT_POLLFD (&data->newpfd, GPOINTER_TO_INT (fd), events);
*msg = (char) operation;
#ifndef HOST_WIN32
- write (data->pipe [1], msg, 1);
+ unused = write (data->pipe [1], msg, 1);
#else
- send ((SOCKET) data->pipe [1], msg, 1, 0);
+ unused = send ((SOCKET) data->pipe [1], msg, 1, 0);
#endif
}
gint maxfd = 1;
gint allocated;
gint i;
- MonoInternalThread *thread;
tp_poll_data *data;
SocketIOData *socket_io_data = p;
MonoPtrArray async_results;
gint nresults;
- thread = mono_thread_internal_current ();
-
data = socket_io_data->event_data;
allocated = INITIAL_POLLFD_SIZE;
pfds = g_new0 (mono_pollfd, allocated);
do {
if (nsock == -1) {
- if (THREAD_WANTS_A_BREAK (thread))
- mono_thread_interruption_checkpoint ();
+ check_for_interruption_critical ();
}
nsock = mono_poll (pfds, maxfd, -1);
/* Got a new socket */
if ((pfds->revents & MONO_POLLIN) != 0) {
int nread;
+ gboolean found = FALSE;
for (i = 1; i < allocated; i++) {
pfd = &pfds [i];
- if (pfd->fd == -1 || pfd->fd == data->newpfd.fd)
+ if (pfd->fd == data->newpfd.fd) {
+ found = TRUE;
break;
+ }
+ }
+
+ if (!found) {
+ for (i = 1; i < allocated; i++) {
+ pfd = &pfds [i];
+ if (pfd->fd == -1)
+ break;
+ }
}
if (i == allocated) {
if (nsock == 0)
continue;
- EnterCriticalSection (&socket_io_data->io_lock);
+ mono_mutex_lock (&socket_io_data->io_lock);
if (socket_io_data->inited == 3) {
g_free (pfds);
mono_ptr_array_destroy (async_results);
- LeaveCriticalSection (&socket_io_data->io_lock);
+ mono_mutex_unlock (&socket_io_data->io_lock);
return; /* cleanup called */
}
maxfd--;
}
}
- LeaveCriticalSection (&socket_io_data->io_lock);
- threadpool_append_jobs (&async_io_tp, (MonoObject **) async_results.data, nresults);
+ mono_mutex_unlock (&socket_io_data->io_lock);
+ threadpool_append_async_io_jobs ((MonoObject **) async_results.data, nresults);
mono_ptr_array_clear (async_results);
}
}