summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7ffdc91)
This is very useful when you have multiple sockets with sources.
GPollFD pollfd;
GCancellable *cancellable;
gulong cancelled_tag;
GPollFD pollfd;
GCancellable *cancellable;
gulong cancelled_tag;
} FDSource;
static gboolean
} FDSource;
static gboolean
return g_cancellable_is_cancelled (fd_source->cancellable);
}
return g_cancellable_is_cancelled (fd_source->cancellable);
}
fd_source_check (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
fd_source_check (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
{
GFDSourceFunc func = (GFDSourceFunc)callback;
{
GFDSourceFunc func = (GFDSourceFunc)callback;
+ GFDSourceObjectFunc func2 = (GFDSourceObjectFunc)callback;
FDSource *fd_source = (FDSource *)source;
g_warn_if_fail (func != NULL);
FDSource *fd_source = (FDSource *)source;
g_warn_if_fail (func != NULL);
- return (*func) (user_data, fd_source->pollfd.revents, fd_source->pollfd.fd);
+ if (fd_source->object)
+ return (*func2) (fd_source->object, fd_source->pollfd.revents, user_data);
+ else
+ return (*func) (user_data, fd_source->pollfd.revents, fd_source->pollfd.fd);
fd_source_finalize (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
fd_source_finalize (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
if (fd_source->cancellable)
g_object_unref (fd_source->cancellable);
if (fd_source->cancellable)
g_object_unref (fd_source->cancellable);
+
+ if (fd_source->object)
+ g_object_unref (fd_source->object);
}
static GSourceFuncs fd_source_funcs = {
}
static GSourceFuncs fd_source_funcs = {
-_g_fd_source_new (int fd,
- gushort events,
- GCancellable *cancellable)
+_g_fd_source_new_with_object (GObject *object,
+ int fd,
+ gushort events,
+ GCancellable *cancellable)
{
GSource *source;
FDSource *fd_source;
{
GSource *source;
FDSource *fd_source;
if (cancellable)
fd_source->cancellable = g_object_ref (cancellable);
if (cancellable)
fd_source->cancellable = g_object_ref (cancellable);
+
+ if (object)
+ fd_source->object = g_object_ref (object);
+
fd_source->pollfd.fd = fd;
fd_source->pollfd.events = events;
g_source_add_poll (source, &fd_source->pollfd);
if (cancellable)
fd_source->cancelled_tag =
fd_source->pollfd.fd = fd;
fd_source->pollfd.events = events;
g_source_add_poll (source, &fd_source->pollfd);
if (cancellable)
fd_source->cancelled_tag =
- g_cancellable_connect (cancellable,
+ g_cancellable_connect (cancellable,
(GCallback)fd_source_cancelled_cb,
NULL, NULL);
(GCallback)fd_source_cancelled_cb,
NULL, NULL);
+
+GSource *
+_g_fd_source_new (int fd,
+ gushort events,
+ GCancellable *cancellable)
+{
+ return _g_fd_source_new_with_object (NULL, fd, events, cancellable);
+}
#define __G_ASYNC_HELPER_H__
#include <gio/gio.h>
#define __G_ASYNC_HELPER_H__
#include <gio/gio.h>
+#include <glib-object.h>
typedef gboolean (*GFDSourceFunc) (gpointer user_data,
GIOCondition condition,
int fd);
typedef gboolean (*GFDSourceFunc) (gpointer user_data,
GIOCondition condition,
int fd);
+typedef gboolean (*GFDSourceObjectFunc) (GObject *object,
+ GIOCondition condition,
+ gpointer user_data);
void _g_queue_async_result (GAsyncResultData *result,
gpointer async_object,
void _g_queue_async_result (GAsyncResultData *result,
gpointer async_object,
gpointer user_data,
GSourceFunc source_func);
gpointer user_data,
GSourceFunc source_func);
-GSource *_g_fd_source_new (int fd,
- gushort events,
- GCancellable *cancellable);
+GSource *_g_fd_source_new_with_object (GObject *object,
+ int fd,
+ gushort events,
+ GCancellable *cancellable);
+GSource *_g_fd_source_new (int fd,
+ gushort events,
+ GCancellable *cancellable);
- * @user_data: data passed in by the user.
+ * @socket: the #GSocket
* @condition: the current condition at the source fired.
* @condition: the current condition at the source fired.
+ * @user_data: data passed in by the user.
*
* This is the function type of the callback used for the #GSource
* returned by g_socket_create_source().
*
* Since: 2.22
*/
*
* This is the function type of the callback used for the #GSource
* returned by g_socket_create_source().
*
* Since: 2.22
*/
-typedef gboolean (*GSocketSourceFunc) (gpointer user_data,
- GIOCondition condition);
+typedef gboolean (*GSocketSourceFunc) (GSocket *socket,
+ GIOCondition condition,
+ gpointer user_data);
GSocketSourceFunc func = (GSocketSourceFunc)callback;
GWinsockSource *winsock_source = (GWinsockSource *)source;
GSocketSourceFunc func = (GSocketSourceFunc)callback;
GWinsockSource *winsock_source = (GWinsockSource *)source;
- return (*func) (user_data,
- winsock_source->result_condition & winsock_source->condition);
+ return (*func) (winsock_source->socket,
+ winsock_source->result_condition & winsock_source->condition,
+ user_data);
#ifdef G_OS_WIN32
source = winsock_source_new (socket, condition, cancellable);
#else
#ifdef G_OS_WIN32
source = winsock_source_new (socket, condition, cancellable);
#else
- source =_g_fd_source_new (socket->priv->fd, condition, cancellable);
+ source =_g_fd_source_new_with_object (G_OBJECT (socket), socket->priv->fd,
+ condition, cancellable);