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
This commit is contained in:
Petr Kulhavy 2016-11-16 13:18:53 +01:00 committed by Dan Winship
parent 4ddaa891e0
commit 437474318f

View File

@ -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);
}
}