mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Local sockets: Local stream sockets had problem of double releasing pipes (both server and client attempt release), which causes wrong pipe pair being closed in multi-client case. Solve by adding per connection instance ID to pipe names. From Jussi Kivilinna (2015-05-12).
This commit is contained in:
@@ -59,6 +59,26 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_generate_instance_id
|
||||
****************************************************************************/
|
||||
|
||||
static int32_t local_generate_instance_id(void)
|
||||
{
|
||||
static int32_t g_next_instance_id = 0;
|
||||
int32_t id;
|
||||
|
||||
/* Called from local_connect with net_lock held. */
|
||||
|
||||
id = g_next_instance_id++;
|
||||
if (g_next_instance_id < 0)
|
||||
{
|
||||
g_next_instance_id = 0;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: _local_semtake() and _local_semgive()
|
||||
*
|
||||
@@ -286,6 +306,7 @@ int psock_local_connect(FAR struct socket *psock,
|
||||
client->lc_proto = conn->lc_proto;
|
||||
strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1);
|
||||
client->lc_path[UNIX_PATH_MAX-1] = '\0';
|
||||
client->lc_instance_id = local_generate_instance_id();
|
||||
|
||||
/* The client is now bound to an address */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user