Skip to content

Commit 2998ff3

Browse files
authored
Problem: No direct support for setting socket priority (#4118)
* Problem: No direct support for setting socket priority Solution: Add ZMQ_PRIORITY socket option, which sets the SO_PRIORITY socket option on the underlying socket. This socket option is not supported under Windows. Check option and set socket option on creation of underlying socket.
1 parent 9936ce8 commit 2998ff3

File tree

18 files changed

+172
-0
lines changed

18 files changed

+172
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ if(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
723723
zmq_check_o_cloexec()
724724
zmq_check_so_bindtodevice()
725725
zmq_check_so_keepalive()
726+
zmq_check_so_priority()
726727
zmq_check_tcp_keepcnt()
727728
zmq_check_tcp_keepidle()
728729
zmq_check_tcp_keepintvl()

RELICENSE/nokia.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Permission to Relicense under MPLv2
2+
3+
This is a statement by Nokia
4+
that grants permission to relicense its copyrights in the libzmq C++
5+
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2).
6+
7+
A portion of the commits made by the Github handle "aheroff1", with
8+
commit author "Andy Heroff", are copyright of Nokia.
9+
This document hereby grants the libzmq project team to relicense libzmq,
10+
including all past, present and future contributions of the author listed above.
11+
12+
Andy Heroff
13+
2021/01/05

acinclude.m4

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,33 @@ int main (int argc, char *argv [])
870870
AS_IF([test "x$libzmq_cv_tcp_keepalive" = "xyes"], [$1], [$2])
871871
}])
872872

873+
dnl ################################################################################
874+
dnl # LIBZMQ_CHECK_SO_PRIORITY([action-if-found], [action-if-not-found]) #
875+
dnl # Check if SO_PRIORITY is supported #
876+
dnl ################################################################################
877+
AC_DEFUN([LIBZMQ_CHECK_SO_PRIORITY], [{
878+
AC_CACHE_CHECK([whether SO_PRIORITY is supported], [libzmq_cv_so_priority],
879+
[AC_TRY_RUN([/* SO_PRIORITY test */
880+
#include <sys/types.h>
881+
#include <sys/socket.h>
882+
883+
int main (int argc, char *argv [])
884+
{
885+
int s, rc, opt = 1;
886+
return (
887+
((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
888+
((rc = setsockopt (s, SOL_SOCKET, SO_PRIORITY, (char*) &opt, sizeof (int))) == -1)
889+
);
890+
}
891+
],
892+
[libzmq_cv_so_priority="yes"],
893+
[libzmq_cv_so_priority="no"],
894+
[libzmq_cv_so_priority="not during cross-compile"]
895+
)]
896+
)
897+
AS_IF([test "x$libzmq_cv_so_priority" = "xyes"], [$1], [$2])
898+
}])
899+
873900
dnl ################################################################################
874901
dnl # LIBZMQ_CHECK_GETRANDOM([action-if-found], [action-if-not-found]) #
875902
dnl # Checks if getrandom is supported #

builds/cmake/Modules/ZMQSourceRunChecks.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,22 @@ int main(int argc, char *argv [])
311311
"
312312
ZMQ_HAVE_NOEXCEPT)
313313
endmacro()
314+
315+
macro(zmq_check_so_priority)
316+
message(STATUS "Checking whether SO_PRIORITY is supported")
317+
check_c_source_runs(
318+
"
319+
#include <sys/types.h>
320+
#include <sys/socket.h>
321+
322+
int main (int argc, char *argv [])
323+
{
324+
int s, rc, opt = 1;
325+
return (
326+
((s = socket (PF_INET, SOCK_STREAM, 0)) == -1) ||
327+
((rc = setsockopt (s, SOL_SOCKET, SO_PRIORITY, (char*) &opt, sizeof (int))) == -1)
328+
);
329+
}
330+
"
331+
ZMQ_HAVE_SO_PRIORITY)
332+
endmacro()

builds/cmake/platform.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#cmakedefine ZMQ_HAVE_SOCK_CLOEXEC
4242
#cmakedefine ZMQ_HAVE_SO_KEEPALIVE
43+
#cmakedefine ZMQ_HAVE_SO_PRIORITY
4344
#cmakedefine ZMQ_HAVE_TCP_KEEPCNT
4445
#cmakedefine ZMQ_HAVE_TCP_KEEPIDLE
4546
#cmakedefine ZMQ_HAVE_TCP_KEEPINTVL

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,12 @@ LIBZMQ_CHECK_TCP_KEEPALIVE([
959959
[Whether TCP_KEEPALIVE is supported.])
960960
])
961961

962+
LIBZMQ_CHECK_SO_PRIORITY([
963+
AC_DEFINE([ZMQ_HAVE_SO_PRIORITY],
964+
[1],
965+
[Whether SO_PRIORITY is supported.])
966+
])
967+
962968
LIBZMQ_CHECK_GETRANDOM([
963969
AC_DEFINE([ZMQ_HAVE_GETRANDOM],
964970
[1],

doc/zmq_getsockopt.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,18 @@ Default value:: -1
513513
Applicable socket types:: all bound sockets, when using IPC or TCP transport
514514

515515

516+
ZMQ_PRIORITY: Retrieve the Priority on socket
517+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
518+
Gets the protocol-defined priority for all packets to be sent on this
519+
socket, where supported by the OS.
520+
521+
[horizontal]
522+
Option value type:: int
523+
Option value unit:: >0
524+
Default value:: 0
525+
Applicable socket types:: all, only for connection-oriented transports
526+
527+
516528
ZMQ_RATE: Retrieve multicast data rate
517529
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
518530
The 'ZMQ_RATE' option shall retrieve the maximum send or receive data rate for

doc/zmq_setsockopt.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,19 @@ Default value:: -1
606606
Applicable socket types:: all bound sockets, when using IPC or TCP transport
607607

608608

609+
ZMQ_PRIORITY: Set the Priority on socket
610+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
611+
Sets the protocol-defined priority for all packets to be sent on this
612+
socket, where supported by the OS. In Linux, values greater than 6
613+
require admin capability (CAP_NET_ADMIN)
614+
615+
[horizontal]
616+
Option value type:: int
617+
Option value unit:: >0
618+
Default value:: 0
619+
Applicable socket types:: all, only for connection-oriented transports
620+
621+
609622
ZMQ_PROBE_ROUTER: bootstrap connections to ROUTER sockets
610623
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
611624
When set to 1, the socket will automatically send an empty message when a

include/zmq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ ZMQ_EXPORT void zmq_threadclose (void *thread_);
682682
#define ZMQ_RECONNECT_STOP 109
683683
#define ZMQ_HELLO_MSG 110
684684
#define ZMQ_DISCONNECT_MSG 111
685+
#define ZMQ_PRIORITY 112
685686

686687
/* DRAFT ZMQ_RECONNECT_STOP options */
687688
#define ZMQ_RECONNECT_STOP_CONN_REFUSED 0x1

src/ip.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ void zmq::set_ip_type_of_service (fd_t s_, int iptos_)
230230
#endif
231231
}
232232

233+
void zmq::set_socket_priority (fd_t s_, int priority_)
234+
{
235+
#ifdef ZMQ_HAVE_SO_PRIORITY
236+
int rc =
237+
setsockopt (s_, SOL_SOCKET, SO_PRIORITY,
238+
reinterpret_cast<char *> (&priority_), sizeof (priority_));
239+
errno_assert (rc == 0);
240+
#endif
241+
}
242+
233243
int zmq::set_nosigpipe (fd_t s_)
234244
{
235245
#ifdef SO_NOSIGPIPE

0 commit comments

Comments
 (0)