Permalink
Browse files

Raw versions of PUB and SUB socket added

Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
  • Loading branch information...
1 parent e21ab60 commit 179f54414e88f189597d8288b3d8311a2604ea40 @sustrik sustrik committed Nov 25, 2013
View
@@ -188,7 +188,11 @@ PROTOCOLS_PUBSUB = \
src/protocols/pubsub/sub.h \
src/protocols/pubsub/sub.c \
src/protocols/pubsub/trie.h \
- src/protocols/pubsub/trie.c
+ src/protocols/pubsub/trie.c \
+ src/protocols/pubsub/xpub.h \
+ src/protocols/pubsub/xpub.c \
+ src/protocols/pubsub/xsub.h \
+ src/protocols/pubsub/xsub.c
PROTOCOLS_REQREP = \
src/protocols/reqrep/req.h \
View
@@ -172,6 +172,10 @@ set (NN_SOURCES
protocols/pubsub/sub.c
protocols/pubsub/trie.h
protocols/pubsub/trie.c
+ protocols/pubsub/xpub.h
+ protocols/pubsub/xpub.c
+ protocols/pubsub/xsub.h
+ protocols/pubsub/xsub.c
protocols/reqrep/req.h
protocols/reqrep/req.c
View
@@ -51,6 +51,8 @@
#include "../protocols/pair/xpair.h"
#include "../protocols/pubsub/pub.h"
#include "../protocols/pubsub/sub.h"
+#include "../protocols/pubsub/xpub.h"
+#include "../protocols/pubsub/xsub.h"
#include "../protocols/reqrep/rep.h"
#include "../protocols/reqrep/req.h"
#include "../protocols/reqrep/xrep.h"
@@ -253,6 +255,8 @@ static void nn_global_init (void)
nn_global_add_socktype (nn_xpair_socktype);
nn_global_add_socktype (nn_pub_socktype);
nn_global_add_socktype (nn_sub_socktype);
+ nn_global_add_socktype (nn_xpub_socktype);
+ nn_global_add_socktype (nn_xsub_socktype);
nn_global_add_socktype (nn_rep_socktype);
nn_global_add_socktype (nn_req_socktype);
nn_global_add_socktype (nn_xrep_socktype);
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved.
+ Copyright (c) 2013 250bpm s.r.o. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
@@ -21,182 +21,18 @@
*/
#include "pub.h"
+#include "xpub.h"
#include "../../nn.h"
#include "../../pubsub.h"
-
-#include "../utils/dist.h"
-
-#include "../../utils/err.h"
-#include "../../utils/cont.h"
-#include "../../utils/fast.h"
-#include "../../utils/alloc.h"
#include "../../utils/list.h"
-#include "../../utils/attr.h"
-
-#include <stddef.h>
-
-struct nn_pub_data {
- struct nn_dist_data item;
-};
-
-struct nn_pub {
-
- /* The generic socket base class. */
- struct nn_sockbase sockbase;
-
- /* Distributor. */
- struct nn_dist outpipes;
-};
-
-/* Private functions. */
-static void nn_pub_init (struct nn_pub *self,
- const struct nn_sockbase_vfptr *vfptr, void *hint);
-static void nn_pub_term (struct nn_pub *self);
-
-/* Implementation of nn_sockbase's virtual functions. */
-static void nn_pub_destroy (struct nn_sockbase *self);
-static int nn_pub_add (struct nn_sockbase *self, struct nn_pipe *pipe);
-static void nn_pub_rm (struct nn_sockbase *self, struct nn_pipe *pipe);
-static void nn_pub_in (struct nn_sockbase *self, struct nn_pipe *pipe);
-static void nn_pub_out (struct nn_sockbase *self, struct nn_pipe *pipe);
-static int nn_pub_events (struct nn_sockbase *self);
-static int nn_pub_send (struct nn_sockbase *self, struct nn_msg *msg);
-static int nn_pub_setopt (struct nn_sockbase *self, int level, int option,
- const void *optval, size_t optvallen);
-static int nn_pub_getopt (struct nn_sockbase *self, int level, int option,
- void *optval, size_t *optvallen);
-static const struct nn_sockbase_vfptr nn_pub_sockbase_vfptr = {
- NULL,
- nn_pub_destroy,
- nn_pub_add,
- nn_pub_rm,
- nn_pub_in,
- nn_pub_out,
- nn_pub_events,
- nn_pub_send,
- NULL,
- nn_pub_setopt,
- nn_pub_getopt
-};
-
-static void nn_pub_init (struct nn_pub *self,
- const struct nn_sockbase_vfptr *vfptr, void *hint)
-{
- nn_sockbase_init (&self->sockbase, vfptr, hint);
- nn_dist_init (&self->outpipes);
-}
-
-static void nn_pub_term (struct nn_pub *self)
-{
- nn_dist_term (&self->outpipes);
- nn_sockbase_term (&self->sockbase);
-}
-
-void nn_pub_destroy (struct nn_sockbase *self)
-{
- struct nn_pub *pub;
-
- pub = nn_cont (self, struct nn_pub, sockbase);
-
- nn_pub_term (pub);
- nn_free (pub);
-}
-
-static int nn_pub_add (struct nn_sockbase *self, struct nn_pipe *pipe)
-{
- struct nn_pub *pub;
- struct nn_pub_data *data;
-
- pub = nn_cont (self, struct nn_pub, sockbase);
-
- data = nn_alloc (sizeof (struct nn_pub_data), "pipe data (pub)");
- alloc_assert (data);
- nn_dist_add (&pub->outpipes, pipe, &data->item);
- nn_pipe_setdata (pipe, data);
-
- return 0;
-}
-
-static void nn_pub_rm (struct nn_sockbase *self, struct nn_pipe *pipe)
-{
- struct nn_pub *pub;
- struct nn_pub_data *data;
-
- pub = nn_cont (self, struct nn_pub, sockbase);
- data = nn_pipe_getdata (pipe);
-
- nn_dist_rm (&pub->outpipes, pipe, &data->item);
-
- nn_free (data);
-}
-
-static void nn_pub_in (NN_UNUSED struct nn_sockbase *self,
- NN_UNUSED struct nn_pipe *pipe)
-{
- /* We shouldn't get any messages from subscribers. */
- nn_assert (0);
-}
-
-static void nn_pub_out (struct nn_sockbase *self, struct nn_pipe *pipe)
-{
- struct nn_pub *pub;
- struct nn_pub_data *data;
-
- pub = nn_cont (self, struct nn_pub, sockbase);
- data = nn_pipe_getdata (pipe);
-
- nn_dist_out (&pub->outpipes, pipe, &data->item);
-}
-
-static int nn_pub_events (NN_UNUSED struct nn_sockbase *self)
-{
- return NN_SOCKBASE_EVENT_OUT;
-}
-
-static int nn_pub_send (struct nn_sockbase *self, struct nn_msg *msg)
-{
- return nn_dist_send (&nn_cont (self, struct nn_pub, sockbase)->outpipes,
- msg, NULL);
-}
-
-static int nn_pub_setopt (NN_UNUSED struct nn_sockbase *self,
- NN_UNUSED int level, NN_UNUSED int option,
- NN_UNUSED const void *optval, NN_UNUSED size_t optvallen)
-{
- return -ENOPROTOOPT;
-}
-
-static int nn_pub_getopt (NN_UNUSED struct nn_sockbase *self,
- NN_UNUSED int level, NN_UNUSED int option,
- NN_UNUSED void *optval, NN_UNUSED size_t *optvallen)
-{
- return -ENOPROTOOPT;
-}
-
-static int nn_pub_create (void *hint, struct nn_sockbase **sockbase)
-{
- struct nn_pub *self;
-
- self = nn_alloc (sizeof (struct nn_pub), "socket (pub)");
- alloc_assert (self);
- nn_pub_init (self, &nn_pub_sockbase_vfptr, hint);
- *sockbase = &self->sockbase;
-
- return 0;
-}
-
-static int nn_pub_ispeer (int socktype)
-{
- return socktype == NN_SUB ? 1 : 0;
-}
static struct nn_socktype nn_pub_socktype_struct = {
AF_SP,
NN_PUB,
NN_SOCKTYPE_FLAG_NORECV,
- nn_pub_create,
- nn_pub_ispeer,
+ nn_xpub_create,
+ nn_xpub_ispeer,
NN_LIST_ITEM_INITIALIZER
};
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2012-2013 250bpm s.r.o. All rights reserved.
+ Copyright (c) 2013 250bpm s.r.o. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),
@@ -28,4 +28,3 @@
extern struct nn_socktype *nn_pub_socktype;
#endif
-
Oops, something went wrong.

0 comments on commit 179f544

Please sign in to comment.