Skip to content

Commit

Permalink
reconstruct subchan
Browse files Browse the repository at this point in the history
  • Loading branch information
reqshark committed Mar 16, 2015
1 parent 295fa06 commit 58f5535
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function Socket (type, opts) {

this.binding = nn.Socket(this.af_domain, this.protocol);
this.queue = [];
this.channels = {};

for(var sokopt in sol){
if(opts.hasOwnProperty(sokopt)) this[sokopt](opts[sokopt]);
Expand Down Expand Up @@ -372,6 +373,28 @@ function opt (option) {
}
};

/* chan and rmchan sockopt methods. only relevant for subscription sockets */
Socket.prototype.chan = function(){
var args = arguments;
var channels = args.length;
while(channels--) {
if (nn.Subchan(this.binding, args[channels]) == 0){
this.channels[args[channels]] = true;
}
};
}

Socket.prototype.rmchan = function(){
var args = arguments;
var channels = args.length;
while(channels--) {
if (this.channels[args[channels]] &&
nn.Setopt(this.binding, nn.NN_SUB, nn.NN_SUB_UNSUBSCRIBE, args[channels]) == 0){
this.channels[args[channels]] = false;
}
};
}

/**
* module API
*/
Expand Down

0 comments on commit 58f5535

Please sign in to comment.