+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
+Tue Dec 15 17:17:46 1998 Owen Taylor <otaylor@redhat.com>
+
+ * glib.h giounix.c giochannel.c: Use an "inheritance"
+ scheme for IO channel memory allocation.h
+
1998-12-15 Havoc Pennington <hp@pobox.com>
* gdate.c (g_date_prepare_to_parse): Solaris has a broken strftime
#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)
+void
+g_io_channel_init (GIOChannel *channel)
{
- 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;
+ channel->channel_flags = 0;
+ channel->ref_count = 1;
}
void
g_io_channel_ref (GIOChannel *channel)
{
- GIOChannelPrivate *private;
g_return_if_fail (channel != NULL);
- private = (GIOChannelPrivate *)channel;
-
- private->ref_count++;
+ channel->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);
- }
+ channel->ref_count--;
+ if (channel->ref_count == 0)
+ channel->funcs->io_free (channel);
}
GIOError
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);
+ return channel->funcs->io_read (channel, buf, count, bytes_read);
}
GIOError
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);
+ return channel->funcs->io_write (channel, buf, count, bytes_written);
}
GIOError
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);
+ return channel->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);
+ channel->funcs->io_close (channel);
}
guint
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,
+ return channel->funcs->io_add_watch (channel, priority, condition,
func, user_data, notify);
}
typedef struct _GIOUnixWatch GIOUnixWatch;
struct _GIOUnixChannel {
+ GIOChannel channel;
gint fd;
};
guint count,
guint *bytes_read)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
gint result;
result = read (unix_channel->fd, buf, count);
guint count,
guint *bytes_written)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
gint result;
result = write (unix_channel->fd, buf, count);
gint offset,
GSeekType type)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
int whence;
off_t result;
static void
g_io_unix_close (GIOChannel *channel)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
close (unix_channel->fd);
}
static void
g_io_unix_free (GIOChannel *channel)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
g_free (unix_channel);
}
GDestroyNotify notify)
{
GIOUnixWatch *watch = g_new (GIOUnixWatch, 1);
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
watch->channel = channel;
g_io_channel_ref (channel);
g_io_channel_unix_new (gint fd)
{
GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
+ GIOChannel *channel = (GIOChannel *)unix_channel;
+
+ g_io_channel_init (channel);
+ channel->funcs = &unix_channel_funcs;
unix_channel->fd = fd;
- return g_io_channel_new (&unix_channel_funcs, unix_channel);
+ return channel;
}
gint
g_io_channel_unix_get_fd (GIOChannel *channel)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
return unix_channel->fd;
}
#endif
} GIOCondition;
-struct _GIOChannel {
- gpointer channel_data;
+struct _GIOChannel
+{
+ guint channel_flags;
+ guint ref_count;
+ GIOFuncs *funcs;
};
typedef gboolean (*GIOFunc) (GIOChannel *source,
void (*io_free) (GIOChannel *channel);
};
-GIOChannel *g_io_channel_new (GIOFuncs *funcs,
- gpointer channel_data);
-void g_io_channel_ref (GIOChannel *channel);
-void g_io_channel_unref (GIOChannel *channel);
-GIOError g_io_channel_read (GIOChannel *channel,
+void g_io_channel_init (GIOChannel *channel);
+void g_io_channel_ref (GIOChannel *channel);
+void g_io_channel_unref (GIOChannel *channel);
+GIOError g_io_channel_read (GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_read);
#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)
+void
+g_io_channel_init (GIOChannel *channel)
{
- 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;
+ channel->channel_flags = 0;
+ channel->ref_count = 1;
}
void
g_io_channel_ref (GIOChannel *channel)
{
- GIOChannelPrivate *private;
g_return_if_fail (channel != NULL);
- private = (GIOChannelPrivate *)channel;
-
- private->ref_count++;
+ channel->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);
- }
+ channel->ref_count--;
+ if (channel->ref_count == 0)
+ channel->funcs->io_free (channel);
}
GIOError
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);
+ return channel->funcs->io_read (channel, buf, count, bytes_read);
}
GIOError
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);
+ return channel->funcs->io_write (channel, buf, count, bytes_written);
}
GIOError
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);
+ return channel->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);
+ channel->funcs->io_close (channel);
}
guint
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,
+ return channel->funcs->io_add_watch (channel, priority, condition,
func, user_data, notify);
}
typedef struct _GIOUnixWatch GIOUnixWatch;
struct _GIOUnixChannel {
+ GIOChannel channel;
gint fd;
};
guint count,
guint *bytes_read)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
gint result;
result = read (unix_channel->fd, buf, count);
guint count,
guint *bytes_written)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
gint result;
result = write (unix_channel->fd, buf, count);
gint offset,
GSeekType type)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
int whence;
off_t result;
static void
g_io_unix_close (GIOChannel *channel)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
close (unix_channel->fd);
}
static void
g_io_unix_free (GIOChannel *channel)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
g_free (unix_channel);
}
GDestroyNotify notify)
{
GIOUnixWatch *watch = g_new (GIOUnixWatch, 1);
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = (GIOUnixChannel *)channel;
watch->channel = channel;
g_io_channel_ref (channel);
g_io_channel_unix_new (gint fd)
{
GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
+ GIOChannel *channel = (GIOChannel *)unix_channel;
+
+ g_io_channel_init (channel);
+ channel->funcs = &unix_channel_funcs;
unix_channel->fd = fd;
- return g_io_channel_new (&unix_channel_funcs, unix_channel);
+ return channel;
}
gint
g_io_channel_unix_get_fd (GIOChannel *channel)
{
- GIOUnixChannel *unix_channel = channel->channel_data;
+ GIOUnixChannel *unix_channel = g_new (GIOUnixChannel, 1);
return unix_channel->fd;
}
#endif
} GIOCondition;
-struct _GIOChannel {
- gpointer channel_data;
+struct _GIOChannel
+{
+ guint channel_flags;
+ guint ref_count;
+ GIOFuncs *funcs;
};
typedef gboolean (*GIOFunc) (GIOChannel *source,
void (*io_free) (GIOChannel *channel);
};
-GIOChannel *g_io_channel_new (GIOFuncs *funcs,
- gpointer channel_data);
-void g_io_channel_ref (GIOChannel *channel);
-void g_io_channel_unref (GIOChannel *channel);
-GIOError g_io_channel_read (GIOChannel *channel,
+void g_io_channel_init (GIOChannel *channel);
+void g_io_channel_ref (GIOChannel *channel);
+void g_io_channel_unref (GIOChannel *channel);
+GIOError g_io_channel_read (GIOChannel *channel,
gchar *buf,
guint count,
guint *bytes_read);