channel->buffer = NULL;
channel->running = FALSE;
channel->thread_id = 0;
+ channel->data_avail_event = NULL;
+ channel->space_avail_event = NULL;
}
static void
sec_attrs.lpSecurityDescriptor = NULL;
sec_attrs.bInheritHandle = FALSE;
- channel->data_avail_event = NULL;
- channel->space_avail_event = NULL;
-
/* The data available event is manual reset, the space available event
* is automatic reset.
*/
nbytes = MIN ((channel->rdp + BUFFER_SIZE - channel->wrp - 1) % BUFFER_SIZE,
BUFFER_SIZE - channel->wrp);
+ if (channel->debug)
+ g_print ("thread %#x: calling reader for %d bytes\n",
+ channel->thread_id, nbytes);
+
UNLOCK (channel->mutex);
nbytes = (*channel->reader) (channel->fd, buffer, nbytes);
g_io_win32_destroy
};
+static guint
+g_io_win32_add_watch (GIOChannel *channel,
+ gint priority,
+ GIOCondition condition,
+ GIOFunc func,
+ gpointer user_data,
+ GDestroyNotify notify,
+ int (*reader) (int, guchar *, int))
+{
+ GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
+ GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
+
+ watch->channel = channel;
+ g_io_channel_ref (channel);
+
+ watch->callback = func;
+ watch->condition = condition;
+
+ if (win32_channel->data_avail_event == NULL)
+ create_events (win32_channel);
+
+ watch->pollfd.fd = (gint) win32_channel->data_avail_event;
+ watch->pollfd.events = condition;
+
+ if (win32_channel->debug)
+ g_print ("g_io_win32_add_watch: fd:%d handle:%#x\n",
+ win32_channel->fd, watch->pollfd.fd);
+
+ if (win32_channel->thread_id == 0)
+ create_reader_thread (win32_channel, reader);
+
+ g_main_add_poll (&watch->pollfd, priority);
+
+ return g_source_add (priority, TRUE, &win32_watch_funcs, watch,
+ user_data, notify);
+}
+
static GIOError
g_io_win32_msg_read (GIOChannel *channel,
gchar *buf,
return G_IO_ERROR_UNKNOWN;
}
-
static void
g_io_win32_msg_close (GIOChannel *channel)
{
static GIOError
g_io_win32_fd_read (GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_read)
+ gchar *buf,
+ guint count,
+ guint *bytes_read)
{
GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
gint result;
GIOError error;
+ if (win32_channel->debug)
+ g_print ("g_io_win32_fd_read: fd:%d count:%d\n",
+ win32_channel->fd, count);
+
if (win32_channel->thread_id)
{
result = buffer_read (win32_channel, buf, count, &error);
}
static GIOError
-g_io_win32_fd_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
+g_io_win32_fd_write (GIOChannel *channel,
+ gchar *buf,
+ guint count,
+ guint *bytes_written)
{
GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
gint result;
static GIOError
g_io_win32_fd_seek (GIOChannel *channel,
- gint offset,
- GSeekType type)
+ gint offset,
+ GSeekType type)
{
GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
int whence;
gpointer user_data,
GDestroyNotify notify)
{
- GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
- DWORD nbytes;
- char dummy[1];
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- create_events (win32_channel);
-
- watch->pollfd.fd = (gint) win32_channel->data_avail_event;
- watch->pollfd.events = condition;
-
- if (win32_channel->debug)
- g_print ("g_io_win32_fd_add_watch: fd:%d handle:%#x\n",
- win32_channel->fd, watch->pollfd.fd);
-
- create_reader_thread (win32_channel, fd_reader);
-
- g_main_add_poll (&watch->pollfd, priority);
-
- return g_source_add (priority, TRUE, &win32_watch_funcs,
- watch, user_data, notify);
+ return g_io_win32_add_watch (channel, priority, condition,
+ func, user_data, notify, fd_reader);
}
static GIOError
}
static GIOError
-g_io_win32_sock_write(GIOChannel *channel,
- gchar *buf,
- guint count,
- guint *bytes_written)
+g_io_win32_sock_write (GIOChannel *channel,
+ gchar *buf,
+ guint count,
+ guint *bytes_written)
{
GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
gint result;
gpointer user_data,
GDestroyNotify notify)
{
- GIOWin32Watch *watch = g_new (GIOWin32Watch, 1);
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
-
- watch->channel = channel;
- g_io_channel_ref (channel);
-
- watch->callback = func;
- watch->condition = condition;
-
- create_events (win32_channel);
-
- watch->pollfd.fd = (gint) win32_channel->data_avail_event;
- watch->pollfd.events = condition;
-
- /* Sockets are always readable, aren't they? */
- create_reader_thread (win32_channel, sock_reader);
-
- g_main_add_poll (&watch->pollfd, priority);
-
- return g_source_add (priority, TRUE, &win32_watch_funcs, watch,
- user_data, notify);
+ return g_io_win32_add_watch (channel, priority, condition,
+ func, user_data, notify, sock_reader);
}
static GIOFuncs win32_channel_msg_funcs = {
}
gint
-g_io_channel_win32_wait_for_condition (GIOChannel *channel,
- GIOCondition condition,
- gint timeout)
+g_io_channel_win32_poll (GPollFD *fds,
+ gint n_fds,
+ gint timeout)
{
- GPollFD pollfd;
- GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
int result;
- pollfd.fd = (gint) win32_channel->data_avail_event;
- pollfd.events = condition;
+ g_return_val_if_fail (n_fds >= 0, 0);
- if (win32_channel->debug)
- g_print ("g_io_channel_win32_wait_for_condition: fd:%d event:%#x timeout:%d\n",
- win32_channel->fd, pollfd.fd, timeout);
-
- result = (*g_main_win32_get_poll_func ()) (&pollfd, 1, timeout);
-
- if (win32_channel->debug)
- g_print ("g_io_channel_win32_wait_for_condition: done:%d\n", result);
+ result = (*g_main_win32_get_poll_func ()) (fds, n_fds, timeout);
return result;
}
+void
+g_io_channel_win32_make_pollfd (GIOChannel *channel,
+ GIOCondition condition,
+ GPollFD *fd)
+{
+ GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
+
+ if (win32_channel->data_avail_event == NULL)
+ create_events (win32_channel);
+
+ fd->fd = (gint) win32_channel->data_avail_event;
+ fd->events = condition;
+
+ if (win32_channel->thread_id == 0)
+ if (win32_channel->type == G_IO_FILE_DESC)
+ create_reader_thread (win32_channel, fd_reader);
+ else if (win32_channel->type == G_IO_STREAM_SOCKET)
+ create_reader_thread (win32_channel, sock_reader);
+}
/* This variable and the functions below are present just to be
* binary compatible with old clients... But note that in GIMP, the
GIOChannel *
g_io_channel_win32_new_pipe_with_wakeups (int fd,
- guint peer,
- int peer_fd)
+ guint peer,
+ int peer_fd)
{
return g_io_channel_win32_new_fd (fd);
}
void
g_io_channel_win32_pipe_request_wakeups (GIOChannel *channel,
- guint peer,
- int peer_fd)
+ guint peer,
+ int peer_fd)
{
/* Nothing needed now */
}
void
g_io_channel_win32_pipe_readable (gint fd,
- guint offset)
+ guint offset)
{
/* Nothing needed now */
}