Skip to content

Commit

Permalink
expose option: socket.rcvmaxsize()
Browse files Browse the repository at this point in the history
fixes #138, expose option socket.rcvmaxsize()

Signed-off-by: Bent Cardan <bent@nothingsatisfies.com>
  • Loading branch information
reqshark committed Dec 12, 2015
1 parent 8a5550e commit 1b1314c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ nano.socket('bus', { raw: true } );
* `'sndprio'` *(Number, default: `0`)*: see [`socket.sndprio(priority)`](https://github.com/nickdesaulniers/node-nanomsg#socketsndpriopriority)
* `'rcvprio'` *(Number, default: `0`)*: see [`socket.rcvprio(priority)`](https://github.com/nickdesaulniers/node-nanomsg#socketrcvpriopriority)
* `'ipv6'` *(Boolean, default: `false`)*: see [`socket.ipv6(boolean)`](https://github.com/nickdesaulniers/node-nanomsg#socketipv6boolean)
* `'rcvmaxsize'` *(Number, default: `false`)*: see [`socket.rcvmaxsize(size)`](https://github.com/nickdesaulniers/node-nanomsg#socketrcvmaxsizesize)
* `'chan'` *(Array, default: `['']`)*: see [`socket.chan(Array)`](https://github.com/nickdesaulniers/node-nanomsg#socketchanarray)

### socket.shutdown(address)
Expand Down Expand Up @@ -309,6 +310,17 @@ socket.ipv6(true);
console.log(socket.ipv6()); // true
```

### socket.rcvmaxsize(size)

*(Function, param: Number, size in bytes, default: `1024kB`)*: Maximum message size that can be received, in bytes. Negative value means that the received size is limited only by available addressable memory.

Pass no parameter for the socket's maximum receive buffer size.

```js
socket.rcvmaxsize(10000000);
console.log(socket.rcvmaxsize()); // 10000000
```

# test

```bash
Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var sol = {
maxreconn : nn.NN_RECONNECT_IVL_MAX,
sndprio : nn.NN_SNDPRIO,
rcvprio : nn.NN_RCVPRIO,
rcvmaxsize : nn.NN_RCVMAXSIZE,
tcpnodelay : nn.NN_TCP_NODELAY,
ipv6 : nn.NN_IPV4ONLY,
}
Expand Down Expand Up @@ -374,6 +375,7 @@ Socket.prototype.reconn = opt('reconn');
Socket.prototype.maxreconn = opt('maxreconn');
Socket.prototype.sndprio = opt('sndprio');
Socket.prototype.rcvprio = opt('rcvprio');
Socket.prototype.rcvmaxsize = opt('rcvmaxsize');

/* ipv6 & tcpnodelay sockopt methods. these two opts are a little different */
Socket.prototype.ipv6 = function (bool) {
Expand Down
5 changes: 5 additions & 0 deletions test/sockoptapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ test('sockopt api methods', function(t){
t.equal( sock.rcvprio(10), true, 'sock.rcvprio(10) sets: 10 priority');
t.equal( sock.rcvprio(), 10, 'sock.rcvprio() gets: 10');

//rcvmaxsize
t.equal( sock.rcvmaxsize(), 1048576, 'rcvmaxsize default: 1048576 bytes');
t.equal( sock.rcvmaxsize(10000000), true, 'rcvmaxsize sets: 1M bytes');
t.equal( sock.rcvmaxsize(), 10000000, 'rcvmaxsize gets: 1M bytes');

//ipv6
t.equal( sock.ipv6(), false, 'sock.ipv6() gets: false');
t.equal( sock.ipv6(true), true, 'sock.ipv6(true) gets: true');
Expand Down

0 comments on commit 1b1314c

Please sign in to comment.