GPollFD pollfd;
GCancellable *cancellable;
gulong cancelled_tag;
- GObject *object;
} FDSource;
static gboolean
return g_cancellable_is_cancelled (fd_source->cancellable);
}
-static gboolean
+static gboolean
fd_source_check (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
{
GFDSourceFunc func = (GFDSourceFunc)callback;
- GFDSourceObjectFunc func2 = (GFDSourceObjectFunc)callback;
FDSource *fd_source = (FDSource *)source;
g_warn_if_fail (func != NULL);
- 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);
+ return (*func) (user_data, fd_source->pollfd.revents, fd_source->pollfd.fd);
}
-static void
+static void
fd_source_finalize (GSource *source)
{
FDSource *fd_source = (FDSource *)source;
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 = {
}
GSource *
-_g_fd_source_new_with_object (GObject *object,
- int fd,
- gushort events,
- GCancellable *cancellable)
+_g_fd_source_new (int fd,
+ gushort events,
+ GCancellable *cancellable)
{
GSource *source;
FDSource *fd_source;
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 =
- g_cancellable_connect (cancellable,
+ g_cancellable_connect (cancellable,
(GCallback)fd_source_cancelled_cb,
NULL, NULL);
-
+
return source;
}
-
-GSource *
-_g_fd_source_new (int fd,
- gushort events,
- GCancellable *cancellable)
-{
- return _g_fd_source_new_with_object (NULL, fd, events, cancellable);
-}
#include "gsocket.h"
#include "gcancellable.h"
#include "gioenumtypes.h"
+#include "ginetaddress.h"
#include "ginitable.h"
-#include "gasynchelper.h"
#include "gioerror.h"
#include "gioenums.h"
#include "gioerror.h"
#include "gnetworkingprivate.h"
+#include "gsocketaddress.h"
+#include "gsocketcontrolmessage.h"
#include "glibintl.h"
#include "gioalias.h"
return condition;
}
+#endif
typedef struct {
GSource source;
GIOCondition condition;
GCancellable *cancellable;
GPollFD cancel_pollfd;
- GIOCondition result_condition;
-} GWinsockSource;
+} GSocketSource;
static gboolean
-winsock_prepare (GSource *source,
- gint *timeout)
+socket_source_prepare (GSource *source,
+ gint *timeout)
{
- GWinsockSource *winsock_source = (GWinsockSource *)source;
- GIOCondition current_condition;
+ GSocketSource *socket_source = (GSocketSource *)source;
- current_condition = update_condition (winsock_source->socket);
+#ifdef G_OS_WIN32
+ socket_source->pollfd.revents = update_condition (socket_source->socket);
+#endif
+ *timeout = -1;
- if (g_cancellable_is_cancelled (winsock_source->cancellable))
- {
- winsock_source->result_condition = current_condition;
- return TRUE;
- }
+ if (g_cancellable_is_cancelled (socket_source->cancellable))
+ return TRUE;
- if ((winsock_source->condition & current_condition) != 0)
- {
- winsock_source->result_condition = current_condition;
- return TRUE;
- }
+ if ((socket_source->condition & socket_source->pollfd.revents) != 0)
+ return TRUE;
return FALSE;
}
static gboolean
-winsock_check (GSource *source)
+socket_source_check (GSource *source)
{
- GWinsockSource *winsock_source = (GWinsockSource *)source;
- GIOCondition current_condition;
-
- current_condition = update_condition (winsock_source->socket);
-
- if (g_cancellable_is_cancelled (winsock_source->cancellable))
- {
- winsock_source->result_condition = current_condition;
- return TRUE;
- }
-
- if ((winsock_source->condition & current_condition) != 0)
- {
- winsock_source->result_condition = current_condition;
- return TRUE;
- }
+ int timeout;
- return FALSE;
+ return socket_source_prepare (source, &timeout);
}
static gboolean
-winsock_dispatch (GSource *source,
- GSourceFunc callback,
- gpointer user_data)
+socket_source_dispatch (GSource *source,
+ GSourceFunc callback,
+ gpointer user_data)
{
GSocketSourceFunc func = (GSocketSourceFunc)callback;
- GWinsockSource *winsock_source = (GWinsockSource *)source;
+ GSocketSource *socket_source = (GSocketSource *)source;
- return (*func) (winsock_source->socket,
- winsock_source->result_condition & winsock_source->condition,
+ return (*func) (socket_source->socket,
+ socket_source->pollfd.revents & socket_source->condition,
user_data);
}
static void
-winsock_finalize (GSource *source)
+socket_source_finalize (GSource *source)
{
- GWinsockSource *winsock_source = (GWinsockSource *)source;
+ GSocketSource *socket_source = (GSocketSource *)source;
GSocket *socket;
- socket = winsock_source->socket;
+ socket = socket_source->socket;
+
+#ifdef G_OS_WIN32
+ remove_condition_watch (socket, &socket_source->condition);
+#endif
- remove_condition_watch (socket, &winsock_source->condition);
g_object_unref (socket);
- if (winsock_source->cancellable)
+ if (socket_source->cancellable)
{
- g_cancellable_release_fd (winsock_source->cancellable);
- g_object_unref (winsock_source->cancellable);
+ g_cancellable_release_fd (socket_source->cancellable);
+ g_object_unref (socket_source->cancellable);
}
}
-static GSourceFuncs winsock_funcs =
+static GSourceFuncs socket_source_funcs =
{
- winsock_prepare,
- winsock_check,
- winsock_dispatch,
- winsock_finalize
+ socket_source_prepare,
+ socket_source_check,
+ socket_source_dispatch,
+ socket_source_finalize
};
static GSource *
-winsock_source_new (GSocket *socket,
- GIOCondition condition,
- GCancellable *cancellable)
+socket_source_new (GSocket *socket,
+ GIOCondition condition,
+ GCancellable *cancellable)
{
GSource *source;
- GWinsockSource *winsock_source;
+ GSocketSource *socket_source;
+#ifdef G_OS_WIN32
ensure_event (socket);
if (socket->priv->event == WSA_INVALID_EVENT)
g_warning ("Failed to create WSAEvent");
return g_source_new (&broken_funcs, sizeof (GSource));
}
+#endif
condition |= G_IO_HUP | G_IO_ERR;
- source = g_source_new (&winsock_funcs, sizeof (GWinsockSource));
- winsock_source = (GWinsockSource *)source;
+ source = g_source_new (&socket_source_funcs, sizeof (GSocketSource));
+ socket_source = (GSocketSource *)source;
- winsock_source->socket = g_object_ref (socket);
- winsock_source->condition = condition;
- add_condition_watch (socket, &winsock_source->condition);
+ socket_source->socket = g_object_ref (socket);
+ socket_source->condition = condition;
if (g_cancellable_make_pollfd (cancellable,
- &winsock_source->cancel_pollfd))
+ &socket_source->cancel_pollfd))
{
- winsock_source->cancellable = g_object_ref (cancellable);
- g_source_add_poll (source, &winsock_source->cancel_pollfd);
+ socket_source->cancellable = g_object_ref (cancellable);
+ g_source_add_poll (source, &socket_source->cancel_pollfd);
}
- winsock_source->pollfd.fd = (gintptr) socket->priv->event;
- winsock_source->pollfd.events = condition;
- g_source_add_poll (source, &winsock_source->pollfd);
+#ifdef G_OS_WIN32
+ add_condition_watch (socket, &socket_source->condition);
+ socket_source->pollfd.fd = (gintptr) socket->priv->event;
+#else
+ socket_source->pollfd.fd = socket->priv->fd;
+#endif
+
+ socket_source->pollfd.events = condition;
+ socket_source->pollfd.revents = 0;
+ g_source_add_poll (source, &socket_source->pollfd);
return source;
}
-#endif
/**
* g_socket_create_source:
*
* The callback on the source is of the #GSocketSourceFunc type.
*
- * It is meaningless to specify %G_IO_ERR or %G_IO_HUP in condition;
+ * It is meaningless to specify %G_IO_ERR or %G_IO_HUP in @condition;
* these conditions will always be reported output if they are true.
*
* @cancellable if not %NULL can be used to cancel the source, which will
GIOCondition condition,
GCancellable *cancellable)
{
- GSource *source;
g_return_val_if_fail (G_IS_SOCKET (socket) && (cancellable == NULL || G_IS_CANCELLABLE (cancellable)), NULL);
-#ifdef G_OS_WIN32
- source = winsock_source_new (socket, condition, cancellable);
-#else
- source =_g_fd_source_new_with_object (G_OBJECT (socket), socket->priv->fd,
- condition, cancellable);
-#endif
- return source;
+ return socket_source_new (socket, condition, cancellable);
}
/**