Skip to content

Commit

Permalink
iiod-client: Use fallback client to destroy blocks and buffers
Browse files Browse the repository at this point in the history
Allow clients to pass a fallback iiod-client instance to be used when
destroying blocks and buffers.

This is useful because once a buffer is cancelled with
iio_buffer_cancel(), the iiod-client associated with that buffer cannot
be used for data transfers anymore. Using the fallback instance allows
the client to destroy the blocks and buffer properly after the buffer
has been cancelled.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Jan 31, 2024
1 parent 0036a9e commit 4883444
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions iiod-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static int iiod_client_enable_binary(struct iiod_client *client);

struct iiod_client_buffer_pdata {
struct iiod_client *client;
struct iiod_client *client_fb;
struct iiod_client_io *io;

struct iio_channels_mask *mask;
Expand Down Expand Up @@ -1419,6 +1420,7 @@ ssize_t iiod_client_writebuf(struct iiod_client_buffer_pdata *pdata,

struct iiod_client_buffer_pdata *
iiod_client_create_buffer(struct iiod_client *client,
struct iiod_client *client_fb,
const struct iio_device *dev, unsigned int idx,
struct iio_channels_mask *mask)
{
Expand All @@ -1435,6 +1437,7 @@ iiod_client_create_buffer(struct iiod_client *client,
pdata->dev = dev;
pdata->idx = (uint16_t) idx;
pdata->client = client;
pdata->client_fb = client_fb;
pdata->mask = mask;

if (iiod_client_uses_binary_interface(client)) {
Expand Down Expand Up @@ -1462,7 +1465,7 @@ iiod_client_create_buffer(struct iiod_client *client,

void iiod_client_free_buffer(struct iiod_client_buffer_pdata *pdata)
{
struct iiod_client *client = pdata->client;
struct iiod_client *client = pdata->client_fb;
struct iiod_io *io;
struct iiod_command cmd;

Expand Down Expand Up @@ -1586,7 +1589,7 @@ iiod_client_create_block(struct iiod_client_buffer_pdata *pdata,

void iiod_client_free_block(struct iio_block_pdata *block)
{
struct iiod_client *client = block->buffer->client;
struct iiod_client *client = block->buffer->client_fb;
struct iiod_io *io;
struct iiod_client_buffer_pdata *pdata = block->buffer;
struct iiod_command cmd;
Expand Down
1 change: 1 addition & 0 deletions include/iio/iiod-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ iiod_client_create_context(struct iiod_client *client,

__api struct iiod_client_buffer_pdata *
iiod_client_create_buffer(struct iiod_client *client,
struct iiod_client *client_fb,
const struct iio_device *dev, unsigned int idx,
struct iio_channels_mask *mask);
__api void iiod_client_free_buffer(struct iiod_client_buffer_pdata *pdata);
Expand Down
5 changes: 3 additions & 2 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@ network_create_buffer(const struct iio_device *dev, unsigned int idx,
goto err_free_buf;
}

buf->pdata = iiod_client_create_buffer(buf->iiod_client, dev,
idx, mask);
buf->pdata = iiod_client_create_buffer(buf->iiod_client,
pdata->iiod_client,
dev, idx, mask);
ret = iio_err(buf->pdata);
if (ret) {
dev_perror(dev, ret, "Unable to create buffer");
Expand Down
1 change: 1 addition & 0 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ serial_create_buffer(const struct iio_device *dev, unsigned int idx,
return iio_ptr(-ENOMEM);

buf->pdata = iiod_client_create_buffer(pdata->iiod_client,
pdata->iiod_client,
dev, idx, mask);
ret = iio_err(buf->pdata);
if (ret) {
Expand Down
1 change: 1 addition & 0 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ usb_create_buffer(const struct iio_device *dev, unsigned int idx,
}

buf->pdata = iiod_client_create_buffer(buf->io_ctx.iiod_client,
ctx_pdata->io_ctx.iiod_client,
dev, idx, mask);
ret = iio_err(buf->pdata);
if (ret) {
Expand Down

0 comments on commit 4883444

Please sign in to comment.