Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
This fixes burst sends on "req" sockets. (#536)
Browse files Browse the repository at this point in the history
* This fixes burst sends on "req" sockets.

* Fix missing read flush triggered during send
  • Loading branch information
Ron Korving committed Jun 3, 2016
1 parent 51a43e8 commit 7e2d99b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
6 changes: 5 additions & 1 deletion binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,12 @@ namespace zmq {
readsReady = true;
}

if ((events & ZMQ_POLLOUT) == 0)
if ((events & ZMQ_POLLOUT) == 0) {
if (readsReady) {
socket->NotifyReadReady();
}
return info.GetReturnValue().Set(false);
}
}

Local<Object> buf = batch->Get(i).As<Object>();
Expand Down
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,11 @@ Socket.prototype._flushReads = function() {
} while (received);

this._isFlushingReads = false;

// if many sends happened, but ended up in the queue (eg. in a req/rep scenario where each send must be followed by a
// response), we can try to send again now

this._flushWrites();
};

Socket.prototype._flushWrites = function() {
Expand Down
36 changes: 36 additions & 0 deletions test/socket.req-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,40 @@ describe('socket.req-rep', function(){
}
});

it('should support a burst', function (done) {
var rep = zmq.socket('rep');
var req = zmq.socket('req');
var n = 10;

rep.on('message', function (msg) {
msg.should.be.an.instanceof(Buffer);
msg.toString().should.equal('hello');
rep.send('world');
});

rep.bind('inproc://reqrepburst', function (error) {
if (error) throw error;
req.connect('inproc://reqrepburst');

var received = 0;

req.on('message', function(msg){
msg.should.be.an.instanceof(Buffer);
msg.toString().should.equal('world');

received += 1;

if (received === n) {
rep.close();
req.close();
done();
}
});

for (var i = 0; i < n; i += 1) {
req.send('hello');
}
});
});

});

0 comments on commit 7e2d99b

Please sign in to comment.