*/
/**
- * SECTION: gunixfdmessage
+ * SECTION:gunixfdmessage
* @title: GUnixFDMessage
* @short_description: A GSocketControlMessage containing a GUnixFDList
* @include: gio/gunixfdmessage.h
* stream-oriented UNIX sockets, see g_unix_connection_send_fd() and
* g_unix_connection_receive_fd().
*
- * Note that <filename><gio/gunixfdmessage.h></filename> belongs to
- * the UNIX-specific GIO interfaces, thus you have to use the
- * <filename>gio-unix-2.0.pc</filename> pkg-config file when using it.
- **/
+ * Note that `<gio/gunixfdmessage.h>` belongs to the UNIX-specific GIO
+ * interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
+ * file when using it.
+ */
#include "config.h"
-#include <sys/types.h>
-#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include "gunixfdmessage.h"
#include "gunixfdlist.h"
+#include "gnetworking.h"
#include "gioerror.h"
-#include "gioalias.h"
-
-
-G_DEFINE_TYPE (GUnixFDMessage, g_unix_fd_message,
- G_TYPE_SOCKET_CONTROL_MESSAGE);
-
struct _GUnixFDMessagePrivate
{
GUnixFDList *list;
};
+G_DEFINE_TYPE_WITH_PRIVATE (GUnixFDMessage, g_unix_fd_message, G_TYPE_SOCKET_CONTROL_MESSAGE)
+
static gsize
g_unix_fd_message_get_size (GSocketControlMessage *message)
{
fds = data;
n = size / sizeof (gint);
+ /* Note we probably handled this in gsocket.c already if we're on
+ * Linux and have MSG_CMSG_CLOEXEC, but this code remains as a fallback
+ * in case the kernel is too old for MSG_CMSG_CLOEXEC.
+ */
for (i = 0; i < n; i++)
{
do
* return a reference to the caller, but the returned list is valid for
* the lifetime of @message.
*
- * Returns: the #GUnixFDList from @message
+ * Returns: (transfer none): the #GUnixFDList from @message
*
* Since: 2.24
**/
static void
g_unix_fd_message_init (GUnixFDMessage *message)
{
- message->priv = G_TYPE_INSTANCE_GET_PRIVATE (message,
- G_TYPE_UNIX_FD_MESSAGE,
- GUnixFDMessagePrivate);
+ message->priv = g_unix_fd_message_get_instance_private (message);
}
static void
GSocketControlMessageClass *scm_class = G_SOCKET_CONTROL_MESSAGE_CLASS (class);
GObjectClass *object_class = G_OBJECT_CLASS (class);
- g_type_class_add_private (class, sizeof (GUnixFDMessagePrivate));
scm_class->get_size = g_unix_fd_message_get_size;
scm_class->get_level = g_unix_fd_message_get_level;
scm_class->get_type = g_unix_fd_message_get_msg_type;
/**
* g_unix_fd_message_steal_fds:
* @message: a #GUnixFDMessage
- * @length: pointer to the length of the returned array, or %NULL
+ * @length: (out) (allow-none): pointer to the length of the returned
+ * array, or %NULL
*
* Returns the array of file descriptors that is contained in this
* object.
* This function never returns %NULL. In case there are no file
* descriptors contained in @message, an empty array is returned.
*
- * Returns: an array of file descriptors
+ * Returns: (array length=length) (transfer full): an array of file
+ * descriptors
*
* Since: 2.22
**/
g_unix_fd_message_steal_fds (GUnixFDMessage *message,
gint *length)
{
- g_return_val_if_fail (G_UNIX_FD_MESSAGE (message), FALSE);
+ g_return_val_if_fail (G_UNIX_FD_MESSAGE (message), NULL);
return g_unix_fd_list_steal_fds (message->priv->list, length);
}
{
g_return_val_if_fail (G_UNIX_FD_MESSAGE (message), FALSE);
- return g_unix_fd_list_append (message->priv->list, fd, error) > 0;
+ return g_unix_fd_list_append (message->priv->list, fd, error) >= 0;
}
-
-#define __G_UNIX_FD_MESSAGE_C__
-#include "gioaliasdef.c"