nng_sub_subscribe(3)

NAME

nng_sub_subscribe - manage SUB subscriptions

SYNOPSIS

#include <nng/nng.h>
#include <nng/protocol/pubsub0/sub.h>

int nng_sub0_socket_subscribe(nng_socket s, const void *buf, size_t sz);

int nng_sub0_socket_unsubscribe(nng_socket s, const void *buf, size_t sz);

int nng_sub0_ctx_subscribe(nng_ctx c, const void *buf, size_t sz);

int nng_sub0_ctx_unsubscribe(nng_ctx c, const void *buf, size_t sz);

DESCRIPTION

These functions are used to subscribe, or unsubscribe, message topics on either the sub version 0 socket s, or the sub version 0 context c.

Message topics are used to filter messages. The first sz bytes of an incoming message is compared against buf, and if equal the message is accepted and will be available for receiving.

Multiple topics may be registered for the same socket or context, and incoming messages will be forwarded to the application if any of the topics match.

To disable filtering altogether, the buf may be NULL if sz is zero. In this case, all messages will be forwarded to the application.
These functions should be used instead of the NNG_OPT_SUB_SUBSCRIBE and NNG_OPT_SUB_UNSUBSCRIBE options.

RETURN VALUES

These functions return 0 on success, and non-zero otherwise.

ERRORS

NNG_ENOMEM

Insufficient memory is available.

NNG_ENOTSUP

The protocol is not supported.

NNG_ENOENT

The topic is not subscribed.

SEE ALSO