Skip to contentSkip to conversation

io/channel-socket: Document why we can ignore socket_set_cork() errors

PATCH In review Peter Maydell 2 participants 2 messages Jun 30

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io/channel-socket: Document why we can ignore socket_set_cork() errors

In qio_channel_socket_set_cork(), we call socket_set_cork() but ignore its success/failure return value. This is OK because we are implementing qio_channel_set_cork() here, and that function's API documentation states that the setting is merely a hint. So even if setting TCP_CORK on the underlying socket fails for some reason, this isn't going to be a problem for the caller; correspondingly the qio_channel_set_cork() function has no error return.

Add a comment in qio_channel_socket_set_cork() explaining why we don't check for errors.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2254

---
Spotted by a static analyzer; it seemed to me worth adding the comment.

---
 io/channel-socket.c | 6 ++++++
 1 file changed, 6 insertions(+)
io/channel-socket.c +6 -0
index ea2ec84108..12773b832c 100644
@@ -946,6 +946,12 @@ qio_channel_socket_set_cork(QIOChannel *ioc,
     QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
     int v = enabled ? 1 : 0;
 
+    /*
+     * We can ignore the error return from socket_set_cork() because
+     * at the QIO API level set_cork is only a hint, and so
+     * qio_channel_set_cork() can never fail even if it didn't
+     * actually do anything.
+     */
     socket_set_cork(sioc->fd, v);
 }
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Peter Maydell

In qio_channel_socket_set_cork(), we call socket_set_cork() but ignore its success/failure return value. This is OK because we are implementing qio_channel_set_cork() here, and that function's API documentation states that the setting is merely a hint. So even if setting TCP_CORK on the underlying socket fails for some reason, this isn't going to be a problem for the caller; correspondingly the qio_channel_set_cork() function has no error return.

Add a comment in qio_channel_socket_set_cork() explaining why we don't check for errors.

Quoted 7 lines

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2254

---
Spotted by a static analyzer; it seemed to me worth adding the comment.

---
 io/channel-socket.c | 6 ++++++
 1 file changed, 6 insertions(+)

and queued.

Quoted 22 lines
io/channel-socket.c +6 -0
index ea2ec84108..12773b832c 100644
@@ -946,6 +946,12 @@ qio_channel_socket_set_cork(QIOChannel *ioc,
     QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
     int v = enabled ? 1 : 0;
 
+    /*
+     * We can ignore the error return from socket_set_cork() because
+     * at the QIO API level set_cork is only a hint, and so
+     * qio_channel_set_cork() can never fail even if it didn't
+     * actually do anything.
+     */
     socket_set_cork(sioc->fd, v);
 }
 
Signature · 1 line
2.43.0

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|