Skip to content

Commit 8fc5051

Browse files
authored
Merge pull request #211 from simeyc/add-draft-apis
feat: support draft APIs ZMQ_HELLO_MSG, ZMQ_DISCONNECT_MSG and ZMQ_HICCUP_MSG
2 parents 90ebe3a + a48e3ba commit 8fc5051

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

draft/socketget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ func (soc *Socket) Getusefd() (int, error) {
691691
//
692692
// Returns OR'ed value of options
693693
//
694-
// Returns ErrorNotImplemented3 with ZeroMQ version < 4.3
694+
// Returns ErrorNotImplemented43 with ZeroMQ version < 4.3
695695
//
696696
// See https://libzmq.readthedocs.io/en/latest/zmq_getsockopt.html#_zmq_router_notify_retrieve_router_socket_notification_settings
697697
func (soc *Socket) GetRouterNotify() (RouterNotifyOption, error) {

draft/socketset.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ const (
852852
//
853853
// Multiple options can be OR'ed
854854
//
855-
// Returns ErrorNotImplemented3 with ZeroMQ version < 4.3
855+
// Returns ErrorNotImplemented43 with ZeroMQ version < 4.3
856856
//
857857
// See https://libzmq.readthedocs.io/en/latest/zmq_setsockopt.html#_zmq_router_notify_send_connect_and_disconnect_notifications
858858
func (soc *Socket) SetRouterNotify(value RouterNotifyOption) error {
@@ -861,3 +861,48 @@ func (soc *Socket) SetRouterNotify(value RouterNotifyOption) error {
861861
}
862862
return soc.setInt(C.ZMQ_ROUTER_NOTIFY, int(value))
863863
}
864+
865+
// ZMQ_HELLO_MSG: Set a message to be sent to peers when they connect
866+
//
867+
// Returns ErrorNotImplemented433 with ZeroMQ version < 4.3.3
868+
//
869+
// See https://libzmq.readthedocs.io/en/latest/zmq_setsockopt.html#_zmq_hello_msg_set_an_hello_message_that_will_be_sent_when_a_new_peer_connect
870+
func (soc *Socket) SetHelloMsg(value string) error {
871+
if minor < 3 || (minor == 3 && patch < 3) {
872+
return ErrorNotImplemented433
873+
}
874+
if len(value) == 0 {
875+
return soc.setNullString(C.ZMQ_HELLO_MSG)
876+
}
877+
return soc.setString(C.ZMQ_HELLO_MSG, value)
878+
}
879+
880+
// ZMQ_DISCONNECT_MSG: Set a message to be generated when accepted peers disconnect
881+
//
882+
// Returns ErrorNotImplemented433 with ZeroMQ version < 4.3.3
883+
//
884+
// See https://libzmq.readthedocs.io/en/latest/zmq_setsockopt.html#_zmq_disconnect_msg_set_a_disconnect_message_that_the_socket_will_generate_when_accepted_peer_disconnect
885+
func (soc *Socket) SetDisconnectMsg(value string) error {
886+
if minor < 3 || (minor == 3 && patch < 3) {
887+
return ErrorNotImplemented433
888+
}
889+
if len(value) == 0 {
890+
return soc.setNullString(C.ZMQ_DISCONNECT_MSG)
891+
}
892+
return soc.setString(C.ZMQ_DISCONNECT_MSG, value)
893+
}
894+
895+
// ZMQ_HICCUP_MSG: Set a message to be generated when connected peers temporarily disconnect
896+
//
897+
// Returns ErrorNotImplemented435 with ZeroMQ version < 4.3.5
898+
//
899+
// See https://libzmq.readthedocs.io/en/latest/zmq_setsockopt.html#_zmq_hiccup_msg_set_a_hiccup_message_that_the_socket_will_generate_when_connected_peer_temporarily_disconnect
900+
func (soc *Socket) SetHiccupMsg(value string) error {
901+
if minor < 3 || (minor == 3 && patch < 5) {
902+
return ErrorNotImplemented435
903+
}
904+
if len(value) == 0 {
905+
return soc.setNullString(C.ZMQ_HICCUP_MSG)
906+
}
907+
return soc.setString(C.ZMQ_HICCUP_MSG, value)
908+
}

draft/zmq4.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ var (
8888
ErrorNotImplemented42 = errors.New("Not implemented, requires 0MQ version 4.2")
8989
ErrorNotImplemented42draft = errors.New("Not implemented, requires 0MQ version 4.2 with drafts enabled")
9090
ErrorNotImplemented43 = errors.New("Not implemented, requires 0MQ version 4.3")
91+
ErrorNotImplemented433 = errors.New("Not implemented, requires 0MQ version 4.3.3")
92+
ErrorNotImplemented435 = errors.New("Not implemented, requires 0MQ version 4.3.5")
9193
ErrorNotImplementedWindows = errors.New("Not implemented on Windows")
9294
ErrorNoSocket = errors.New("No such socket")
9395

draft/zmq43draft.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#if ZMQ_VERSION_MINOR < 3
2+
// Version < 4.3
23
#define ZMQ_ROUTER_NOTIFY -1
34
#define ZMQ_NOTIFY_CONNECT 1
45
#define ZMQ_NOTIFY_DISCONNECT 2
56
#endif
7+
8+
#if ZMQ_VERSION_MINOR < 3 || (ZMQ_VERSION_MINOR == 3 && ZMQ_VERSION_PATCH < 3)
9+
// Version < 4.3.3
10+
#define ZMQ_HELLO_MSG -1
11+
#define ZMQ_DISCONNECT_MSG -1
12+
#endif
13+
14+
#if ZMQ_VERSION_MINOR < 3 || (ZMQ_VERSION_MINOR == 3 && ZMQ_VERSION_PATCH < 5)
15+
// Version < 4.3.5
16+
#define ZMQ_HICCUP_MSG -1
17+
#endif

0 commit comments

Comments
 (0)