bluez5: refcount transport acquire and release, let it manage fd

Backends don't necessarily allow for opening the same device multiple
times, and it shouldn't be necessary.

Since source and sink are not necessarily both running at the same time,
refcount the transport acquire/release so that it knows to close the fd
only when no source/sink is running.

Let the transport manage the fd lifecycle, also closing it once it is
not needed.

Don't return the fd from acquire(), since each transport is associated
with a single socket fd.
This commit is contained in:
Pauli Virtanen 2020-12-22 20:36:04 +02:00 committed by Wim Taymans
parent 8942f6b402
commit 036c10717d
7 changed files with 85 additions and 51 deletions

View file

@ -233,6 +233,7 @@ static int sco_acquire_cb(void *data, bool optional)
if (sock < 0)
goto fail;
t->fd = sock;
t->read_mtu = 48;
t->write_mtu = 48;
@ -250,7 +251,9 @@ static int sco_acquire_cb(void *data, bool optional)
t->write_mtu = sco_opt.mtu;
}
}
return sock;
return 0;
fail:
return -1;
}
@ -259,8 +262,14 @@ static int sco_release_cb(void *data)
{
struct spa_bt_transport *t = data;
struct spa_bt_backend *backend = t->backend;
spa_log_info(backend->log, NAME": Transport %s released", t->path);
/* device will close the SCO socket for us */
spa_log_info(backend->log, "Transport %s released", t->path);
/* Shutdown and close the socket */
shutdown(t->fd, SHUT_RDWR);
close(t->fd);
t->fd = -1;
return 0;
}
@ -661,4 +670,4 @@ struct spa_bt_backend *backend_hsp_native_new(struct spa_bt_monitor *monitor,
backend->conn = dbus_connection;
return backend;
}
}