[glib] GSocket: do not process control messages if not requested by the user
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GSocket: do not process control messages if not requested by the user
- Date: Sun, 20 Nov 2016 16:09:53 +0000 (UTC)
commit 437474318fb6af8087bb5821cbad268823fb5c36
Author: Petr Kulhavy <brain jikos cz>
Date: Wed Nov 16 13:18:53 2016 +0100
GSocket: do not process control messages if not requested by the user
If g_socket_receive_message_with_timeout() is called with messages ==
NULL set the msg_control buffer to empty to not request the control
messages from recvmsg() at all.
This completely disables the control message processing and reduces
overhead, which might be critical at high packet rate.
https://bugzilla.gnome.org/show_bug.cgi?id=774520
gio/gsocket.c | 29 ++++++++++++++---------------
1 files changed, 14 insertions(+), 15 deletions(-)
---
diff --git a/gio/gsocket.c b/gio/gsocket.c
index cb7c81b..856fb4f 100644
--- a/gio/gsocket.c
+++ b/gio/gsocket.c
@@ -4099,8 +4099,16 @@ G_STMT_START { \
} \
\
/* control */ \
- _msg->msg_controllen = 2048; \
- _msg->msg_control = g_alloca (_msg->msg_controllen); \
+ if (_message->control_messages == NULL) \
+ { \
+ _msg->msg_controllen = 0; \
+ _msg->msg_control = NULL; \
+ } \
+ else \
+ { \
+ _msg->msg_controllen = 2048; \
+ _msg->msg_control = g_alloca (_msg->msg_controllen); \
+ } \
\
/* flags */ \
_msg->msg_flags = _message->flags; \
@@ -4125,6 +4133,7 @@ input_message_from_msghdr (const struct msghdr *msg,
if (msg->msg_controllen >= sizeof (struct cmsghdr))
{
+ g_assert (message->control_messages != NULL);
for (cmsg = CMSG_FIRSTHDR (msg);
cmsg != NULL;
cmsg = CMSG_NXTHDR ((struct msghdr *) msg, cmsg))
@@ -4140,19 +4149,9 @@ input_message_from_msghdr (const struct msghdr *msg,
deserialization code, so just continue */
continue;
- if (message->control_messages == NULL)
- {
- /* we have to do it this way if the user ignores the
- * messages so that we will close any received fds.
- */
- g_object_unref (control_message);
- }
- else
- {
- if (my_messages == NULL)
- my_messages = g_ptr_array_new ();
- g_ptr_array_add (my_messages, control_message);
- }
+ if (my_messages == NULL)
+ my_messages = g_ptr_array_new ();
+ g_ptr_array_add (my_messages, control_message);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]