[gupnp] linux-cm: Avoid static receive buffer
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] linux-cm: Avoid static receive buffer
- Date: Fri, 11 Jan 2019 09:30:22 +0000 (UTC)
commit 0123e574595e0a547ce26422633df72d63d3d0e0
Author: Jakub Adam <jakub adam collabora com>
Date: Tue Jan 8 13:04:20 2019 +0100
linux-cm: Avoid static receive buffer
The buffer in receive_netlink_message() is shared between all threads,
which poses a problem when several CM instances start accessing it at
the same time.
That can create issues e.g. with libnice where each NiceAgent instance
runs its own GUPnPContextManager in a separate thread.
Let each GUPnPLinuxContextManager have its own recvbuf.
libgupnp/gupnp-linux-context-manager.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/libgupnp/gupnp-linux-context-manager.c b/libgupnp/gupnp-linux-context-manager.c
index 81ade87..3387cee 100644
--- a/libgupnp/gupnp-linux-context-manager.c
+++ b/libgupnp/gupnp-linux-context-manager.c
@@ -81,6 +81,9 @@ struct _GUPnPLinuxContextManagerPrivate {
* structure */
GHashTable *interfaces;
+ /* Receive buffer for netlink messages. */
+ char recvbuf[8196];
+
gboolean dump_netlink_packets;
};
typedef struct _GUPnPLinuxContextManagerPrivate GUPnPLinuxContextManagerPrivate;
@@ -777,20 +780,20 @@ remove_device (GUPnPLinuxContextManager *self,
static void
receive_netlink_message (GUPnPLinuxContextManager *self, GError **error)
{
- static char buf[8196];
-
gssize len;
GError *inner_error = NULL;
- struct nlmsghdr *header = (struct nlmsghdr *) buf;
+ struct nlmsghdr *header;
struct ifinfomsg *ifi;
struct ifaddrmsg *ifa;
GUPnPLinuxContextManagerPrivate *priv;
priv = gupnp_linux_context_manager_get_instance_private (self);
+ header = (struct nlmsghdr *) priv->recvbuf;
+
len = g_socket_receive (priv->netlink_socket,
- buf,
- sizeof (buf),
+ priv->recvbuf,
+ sizeof (priv->recvbuf),
NULL,
&inner_error);
if (len == -1) {
@@ -807,7 +810,8 @@ receive_netlink_message (GUPnPLinuxContextManager *self, GError **error)
/* We should have at most len / 16 + 1 lines with 74 characters each */
hexdump = g_string_new_len (NULL, ((len / 16) + 1) * 73);
- gupnp_linux_context_manager_hexdump ((guint8 *) buf, len, hexdump);
+ gupnp_linux_context_manager_hexdump ((guint8 *) priv->recvbuf,
+ len, hexdump);
g_debug ("Netlink packet dump:\n%s", hexdump->str);
g_string_free (hexdump, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]