Skip to content

Commit 696e583

Browse files
committed
gvstream: check socket buffer size is actually applied
In some cases, the `setsockopt()` call is ignored and the actual socket buffer size is lower than the requested one. In this case, emit an aravis warning. This patch alos improves the documentation of the socket buffer related parameters.
1 parent a06d9e9 commit 696e583

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

src/arvgvstream.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,8 @@ arv_gv_stream_class_init (ArvGvStreamClass *gv_stream_class)
18341834
/**
18351835
* ArvGvStream:socket-buffer-size:
18361836
*
1837-
* Size in bytes of the incoming socket buffer. A greater value helps to lower the number of missings packets,
1838-
* as the expense of an increased memory usage.
1837+
* Size in bytes of the incoming socket buffer. A greater value helps to lower the number of missing packets,
1838+
* as the expense of an increased memory usage. If the value is not strictly positive, this setting is ignored.
18391839
*/
18401840
g_object_class_install_property (
18411841
object_class, ARV_GV_STREAM_PROPERTY_SOCKET_BUFFER_SIZE,

src/arvgvstream.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ typedef enum {
4646

4747
/**
4848
* ArvGvStreamSocketBuffer:
49-
* @ARV_GV_STREAM_SOCKET_BUFFER_FIXED: socket buffer is set to a given fixed value
50-
* @ARV_GV_STREAM_SOCKET_BUFFER_AUTO: socket buffer size is set to the payload size
49+
* @ARV_GV_STREAM_SOCKET_BUFFER_FIXED: socket buffer is set using [[email protected]:socket-buffer-size] value
50+
* @ARV_GV_STREAM_SOCKET_BUFFER_AUTO: socket buffer size is set to the payload size if
51+
* [property@Aravis:socket-buffer-size] is not strictly positive, or the minimum of both values
5152
*/
5253

5354
typedef enum {

src/arvnetwork.c

+41-9
Original file line numberDiff line numberDiff line change
@@ -456,23 +456,55 @@ arv_network_interface_free(ArvNetworkInterface *a)
456456
g_free (a);
457457
}
458458

459-
460459
gboolean
461460
arv_socket_set_recv_buffer_size (int socket_fd, gint buffer_size)
462461
{
462+
#ifdef G_OS_WIN32
463+
DWORD _buffer_size;
464+
DWORD buffer_size_reported;
465+
#else
466+
gint _buffer_size;
467+
gint buffer_size_reported;
468+
#endif
463469
int result;
470+
socklen_t optlen;
464471

465-
#ifndef G_OS_WIN32
466-
result = setsockopt (socket_fd, SOL_SOCKET, SO_RCVBUF, &buffer_size, sizeof (buffer_size));
467-
#else
468-
{
469-
DWORD _buffer_size=buffer_size;
470-
result = setsockopt (socket_fd, SOL_SOCKET, SO_RCVBUF,
471-
(const char*) &_buffer_size, sizeof (_buffer_size));
472+
_buffer_size = buffer_size;
473+
optlen = sizeof(buffer_size_reported);
474+
475+
result = setsockopt (socket_fd, SOL_SOCKET, SO_RCVBUF,
476+
(const char*) &_buffer_size, sizeof (_buffer_size));
477+
if(result != 0) {
478+
arv_warning_interface ("[set_recv_buffer_size] Setting socket buffer to %d bytes failed (%s)",
479+
_buffer_size, strerror(errno));
480+
return FALSE;
472481
}
482+
483+
/* setsockopt() succeeded, but sometimes the requested size is not actually be set. Ask
484+
* to see the new setting to confirm. */
485+
result = getsockopt (socket_fd, SOL_SOCKET, SO_RCVBUF, &buffer_size_reported, &optlen);
486+
if (result != 0) {
487+
arv_warning_interface ("[set_recv_buffer_size] Read of socket buffer size (SO_RCVBUF) failed (%s)",
488+
strerror(errno));
489+
return FALSE;
490+
}
491+
g_assert (optlen == sizeof (buffer_size_reported));
492+
493+
if(buffer_size_reported < buffer_size)
494+
{
495+
arv_warning_interface ("[set_recv_buffer_size] Unexpected socket buffer size (SO_RCVBUF):"
496+
" actual %d < expected %d bytes"
497+
"\nYou might see missing packets and timeouts"
498+
#ifndef G_OS_WIN32
499+
"\nMost likely /proc/sys/net/core/rmem_max is too low"
500+
"\nSee the socket(7) manpage\n"
473501
#endif
502+
, buffer_size_reported, buffer_size);
503+
504+
return FALSE;
505+
}
474506

475-
return result == 0;
507+
return TRUE;
476508
}
477509

478510

0 commit comments

Comments
 (0)