Commit 174cf0b6 authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor
Browse files

Committing main loop changes into a branch for the moment.

This will be merged into the main branch in a few days.

Sat Nov 28 12:53:47 1998  Owen Taylor  <otaylor@redhat.com>

	* Makefile.am configure.in acconfig.h giochannel.c
	  glib.h glist.c gmain.c gutils.c:

        - Revised GIOChannel to provide a generic virtual-function
	based interface.
	- Added unix fd-based GIOChannel's
	- Added generic main-loop abstraction
	- Added timeouts and idle functions using main-loop abstraction.
parent e666e812
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
Sat Nov 28 12:53:47 1998 Owen Taylor <otaylor@redhat.com>
* Makefile.am configure.in acconfig.h giochannel.c
glib.h glist.c gmain.c gutils.c:
- Revised GIOChannel to provide a generic virtual-function
based interface.
- Added unix fd-based GIOChannel's
- Added generic main-loop abstraction
- Added timeouts and idle functions using main-loop abstraction.
Sat Nov 28 01:23:25 1998 Tim Janik <timj@gtk.org>
* ghash.c: implemented incremental freezing facility.
......
......@@ -35,6 +35,9 @@ libglib_la_SOURCES = \
ghash.c \
ghook.c \
glist.c \
gmain.c \
giochannel.c \
giounix.c \
gmem.c \
gmessages.c \
gnode.c \
......
......@@ -43,8 +43,10 @@
#undef HAVE_FLOAT_H
#undef HAVE_LIMITS_H
#undef HAVE_LONG_DOUBLE
#undef HAVE_POLL
#undef HAVE_PWD_H
#undef HAVE_SYS_PARAM_H
#undef HAVE_SYS_POLL_H
#undef HAVE_SYS_SELECT_H
#undef HAVE_SYS_TIME_H
#undef HAVE_SYS_TIMES_H
......
......@@ -226,6 +226,7 @@ AC_CHECK_HEADERS(float.h, AC_DEFINE(HAVE_FLOAT_H))
AC_CHECK_HEADERS(limits.h, AC_DEFINE(HAVE_LIMITS_H))
AC_CHECK_HEADERS(pwd.h, AC_DEFINE(HAVE_PWD_H))
AC_CHECK_HEADERS(sys/param.h, AC_DEFINE(HAVE_SYS_PARAM_H))
AC_CHECK_HEADERS(sys/poll.h, AC_DEFINE(HAVE_SYS_POLL_H))
AC_CHECK_HEADERS(sys/select.h, AC_DEFINE(HAVE_SYS_SELECT_H))
AC_CHECK_HEADERS(sys/time.h, AC_DEFINE(HAVE_SYS_TIME_H))
AC_CHECK_HEADERS(sys/times.h, AC_DEFINE(HAVE_SYS_TIMES_H))
......@@ -233,7 +234,7 @@ AC_CHECK_HEADERS(unistd.h, AC_DEFINE(HAVE_UNISTD_H))
AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H))
# Check for some functions
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp)
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp poll)
# Check for sys_errlist
AC_MSG_CHECKING(for sys_errlist)
......@@ -548,6 +549,9 @@ outfile_EOF
if test x$glib_values_h = xyes; then
echo '#include <values.h>' >> $outfile
fi
if test x$glib_sys_poll_h = xyes; then
echo '#include <sys/poll.h>' >> $outfile
fi
cat >> $outfile <<outfile_EOF
......@@ -696,6 +700,10 @@ x$ac_cv_header_values_h)
;;
esac
if test x$ac_cv_header_sys_poll_h = xyes ; then
glib_sys_poll_h=yes
fi
case 2 in
$ac_cv_sizeof_short) gint16=short;;
$ac_cv_sizeof_int) gint16=int;;
......
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* giochannel.c: IO Channel abstraction
* Copyright 1998 Owen Taylor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "glib.h"
#include <unistd.h>
typedef struct _GIOChannelPrivate GIOChannelPrivate;
struct _GIOChannelPrivate {
GIOChannel channel;
GIOFuncs *funcs;
guint ref_count;
gboolean closed;
};
GIOChannel *
g_io_channel_new (GIOFuncs *funcs,
gpointer channel_data)
{
GIOChannelPrivate *result;
GIOChannel *channel;
g_return_val_if_fail (funcs != NULL, NULL);
result = g_new (GIOChannelPrivate, 1);
channel = (GIOChannel *)result;
result->funcs = funcs;
result->ref_count = 1;
result->closed = FALSE;
channel->channel_data = channel_data;
return channel;
}
void
g_io_channel_ref (GIOChannel *channel)
{
GIOChannelPrivate *private;
g_return_if_fail (channel != NULL);
private = (GIOChannelPrivate *)channel;
private->ref_count++;
}
void
g_io_channel_unref (GIOChannel *channel)
{
GIOChannelPrivate *private;
g_return_if_fail (channel != NULL);
private = (GIOChannelPrivate *)channel;
private->ref_count--;
if (private->ref_count == 0)
{
/* We don't want to close the channel here, because
* the channel may just be wrapping a file or socket
* that the app is independently manipulating.
*/
private->funcs->io_free (channel);
g_free (private);
}
}
GIOError
g_io_channel_read (GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_read)
{
GIOChannelPrivate *private = (GIOChannelPrivate *)channel;
g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
g_return_val_if_fail (!private->closed, G_IO_ERROR_UNKNOWN);
return private->funcs->io_read (channel, buf, count, bytes_read);
}
GIOError
g_io_channel_write (GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_written)
{
GIOChannelPrivate *private = (GIOChannelPrivate *)channel;
g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
g_return_val_if_fail (!private->closed, G_IO_ERROR_UNKNOWN);
return private->funcs->io_write (channel, buf, count, bytes_written);
}
GIOError
g_io_channel_seek (GIOChannel *channel,
gint offset,
GSeekType type)
{
GIOChannelPrivate *private = (GIOChannelPrivate *)channel;
g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
g_return_val_if_fail (!private->closed, G_IO_ERROR_UNKNOWN);
return private->funcs->io_seek (channel, offset, type);
}
void
g_io_channel_close (GIOChannel *channel)
{
GIOChannelPrivate *private = (GIOChannelPrivate *)channel;
g_return_if_fail (channel != NULL);
g_return_if_fail (!private->closed);
private->closed = TRUE;
private->funcs->io_close (channel);
}
guint
g_io_add_watch_full (GIOChannel *channel,
gint priority,
GIOCondition condition,
GIOFunc func,
gpointer user_data,
GDestroyNotify notify)
{
GIOChannelPrivate *private = (GIOChannelPrivate *)channel;
g_return_val_if_fail (channel != NULL, 0);
g_return_val_if_fail (!private->closed, 0);
return private->funcs->io_add_watch (channel, priority, condition,
func, user_data, notify);
}
guint
g_io_add_watch (GIOChannel *channel,
GIOCondition condition,
GIOFunc func,
gpointer user_data)
{
return g_io_add_watch_full (channel, 0, condition, func, user_data, NULL);
}
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* giounix.c: IO Channels using unix file descriptors
* Copyright 1998 Owen Taylor
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "glib.h"
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
/*
* Unix IO Channels
*/
typedef struct _GIOUnixChannel GIOUnixChannel;
typedef struct _GIOUnixWatch GIOUnixWatch;
struct _GIOUnixChannel {
gint fd;
};
struct _GIOUnixWatch {
GPollFD pollfd;
GIOChannel *channel;
GIOCondition condition;
GIOFunc callback;
};
static GIOError g_io_unix_read (GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_written);
static GIOError g_io_unix_write(GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_written);
static GIOError g_io_unix_seek (GIOChannel *channel,
gint offset,
GSeekType type);
static void g_io_unix_close (GIOChannel *channel);
static void g_io_unix_free (GIOChannel *channel);
static guint g_io_unix_add_watch (GIOChannel *channel,
gint priority,
GIOCondition condition,
GIOFunc func,
gpointer user_data,
GDestroyNotify notify);
static gboolean g_io_unix_prepare (gpointer source_data,
GTimeVal *current_time,
gint *timeout);
static gboolean g_io_unix_check (gpointer source_data,
GTimeVal *current_time);
static gboolean g_io_unix_dispatch (gpointer source_data,
GTimeVal *current_time,
gpointer user_data);
static void g_io_unix_destroy (gpointer source_data);
GSourceFuncs unix_watch_funcs = {
g_io_unix_prepare,
g_io_unix_check,
g_io_unix_dispatch,
g_io_unix_destroy
};
GIOFuncs unix_channel_funcs = {
g_io_unix_read,
g_io_unix_write,
g_io_unix_seek,
g_io_unix_close,
g_io_unix_add_watch,
g_io_unix_free,
};
static gboolean
g_io_unix_prepare (gpointer source_data,
GTimeVal *current_time,
gint *timeout)
{
*timeout = -1;
return FALSE;
}
static gboolean
g_io_unix_check (gpointer source_data,
GTimeVal *current_time)
{
GIOUnixWatch *data = source_data;
return (data->pollfd.revents & data->condition);
}
static gboolean
g_io_unix_dispatch (gpointer source_data,
GTimeVal *current_time,
gpointer user_data)
{
GIOUnixWatch *data = source_data;
return (*data->callback)(data->channel,
data->pollfd.revents & data->condition,
user_data);
}
static void
g_io_unix_destroy (gpointer source_data)
{
GIOUnixWatch *data = source_data;
g_main_poll_remove (&data->pollfd);
g_io_channel_unref (data->channel);
g_free (data);
}
static GIOError
g_io_unix_read (GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_read)
{
GIOUnixChannel *unix_channel = channel->channel_data;
gint result;
result = read (unix_channel->fd, buf, count);
if (result < 0)
{
*bytes_read = 0;
switch (errno)
{
case EINVAL:
return G_IO_ERROR_INVAL;
case EAGAIN:
return G_IO_ERROR_AGAIN;
default:
return G_IO_ERROR_UNKNOWN;
}
}
else
{
*bytes_read = result;
return G_IO_ERROR_NONE;
}
}
static GIOError
g_io_unix_write(GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_written)
{
GIOUnixChannel *unix_channel = channel->channel_data;
gint result;
result = write (unix_channel->fd, buf, count);
if (result < 0)
{
*bytes_written = 0;
switch (errno)
{
case EINVAL:
return G_IO_ERROR_INVAL;
case EAGAIN:
return G_IO_ERROR_AGAIN;
default:
return G_IO_ERROR_UNKNOWN;
}
}
else
{
*bytes_written = result;
return G_IO_ERROR_NONE;
}
}
static GIOError
g_io_unix_seek (GIOChannel *channel,
gint offset,
GSeekType type)
{
GIOUnixChannel *unix_channel = channel->channel_data;
int whence;
off_t result;
switch (type)
{
case G_SEEK_SET:
whence = SEEK_SET;
break;
case G_SEEK_CUR:
whence = SEEK_CUR;
break;
case G_SEEK_END:
whence = SEEK_END;
break;
default:
g_warning ("g_io_unix_seek: unknown seek type");
return G_IO_ERROR_UNKNOWN;
}
result = lseek (unix_channel->fd, offset, whence);
if (result < 0)
{
switch (errno)
{
case EINVAL:
return G_IO_ERROR_INVAL;
default:
return G_IO_ERROR_UNKNOWN;
}
}
else
return G_IO_ERROR_NONE;
}
static void
g_io_unix_close (GIOChannel *channel)
{
GIOUnixChannel *unix_channel = channel->channel_data;
close (unix_channel->fd);
}
static void
g_io_unix_free (GIOChannel *channel)
{
GIOUnixChannel *unix_channel = channel->channel_data;
g_free (unix_channel);
}
static guint
g_io_unix_add_watch (GIOChannel *channel,
gint priority,
GIOCondition condition,
GIOFunc func,
gpointer user_data,
GDestroyNotify notify)
{
GIOUnixWatch *watch = g_new (GIOUnixWatch, 1);
GIOUnixChannel *unix_channel = channel->channel_data;
watch->channel = channel;
g_io_channel_ref (channel);
watch->callback = func;
watch->condition = condition;
watch->pollfd.fd = unix_channel->fd;
watch->pollfd.events = condition;
g_main_poll_add (priority, &watch->pollfd);
return g_source_add (priority, TRUE, &unix_watch_funcs, watch, user_data, notify);
}
GIOChannel *
g_io_channel_unix_new (gint fd)
{
GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
unix_channel->fd = fd;
return g_io_channel_new (&unix_channel_funcs, unix_channel);
}
gint
g_io_channel_unix_get_fd (GIOChannel *channel)
{
GIOUnixChannel *unix_channel = channel->channel_data;
return unix_channel->fd;
}
......@@ -155,7 +155,7 @@ extern "C" {
* we define G_CAN_INLINE, if the compiler seems to be actually
* *capable* to do function inlining, in which case inline function bodys