Permalink
Browse files

TOOLS-1589 Want make check in node-watershed

Reviewed by: Josh Wilsdon <jwilsdon@joyent.com>
Reviewed by: Joshua M. Clulow <jmc@joyent.com>
Approved by: Joshua M. Clulow <jmc@joyent.com>
  • Loading branch information...
1 parent 494c74d commit 5109e835c883e6dcad087080aec3c56d04059d01 @richardkiene richardkiene committed Oct 27, 2016
View
@@ -0,0 +1,5 @@
+node_modules
+coverage
+docs/*.html
+docs/*.json
+*.swp
View
@@ -0,0 +1,6 @@
+[submodule "deps/jsstyle"]
+ path = deps/jsstyle
+ url = https://github.com/davepacheco/jsstyle.git
+[submodule "deps/javascriptlint"]
+ path = deps/javascriptlint
+ url = https://github.com/davepacheco/javascriptlint.git
View
@@ -1 +1,12 @@
-test/
+/.gitmodules
+/node_modules
+/tmp
+/npm-debug.log
+/deps
+/examples
+/tools
+/Makefile
+/test
+/docs
+/build
+/watershed-*.tgz
View
@@ -0,0 +1,7 @@
+# node-watershed changelog
+
+## not yet released
+
+## 0.3.2
+
+* Initial move to Joyent org plus make check
View
@@ -0,0 +1,60 @@
+#
+# Copyright 2016 Joyent, Inc.
+#
+# Makefile for node-watershed
+#
+
+#
+# Vars, Tools, Files, Flags
+#
+JS_FILES := $(shell find lib test -name '*.js')
+JSL_CONF_NODE = tools/jsl.node.conf
+JSL_FILES_NODE = $(JS_FILES)
+JSSTYLE_FILES = $(JS_FILES)
+JSSTYLE_FLAGS = -f tools/jsstyle.conf
+CLEAN_FILES += ./node_modules
+
+include ./tools/mk/Makefile.defs
+
+#
+# Targets
+#
+.PHONY: all
+all:
+ npm install
+
+check:: versioncheck
+
+# Ensure CHANGES.md and package.json have the same version.
+.PHONY: versioncheck
+versioncheck:
+ @echo version is: $(shell cat package.json | json version)
+ [[ `cat package.json | json version` == `grep '^## ' CHANGES.md | \
+ head -2 | tail -1 | awk '{print $$2}'` ]]
+
+.PHONY: cutarelease
+cutarelease: versioncheck
+ [[ -z `git status --short` ]] # If this fails, the working dir is dirty.
+ @which json 2>/dev/null 1>/dev/null && \
+ ver=$(shell json -f package.json version) && \
+ name=$(shell json -f package.json name) && \
+ publishedVer=$(shell npm view -j $(shell json -f \
+ package.json name)@$(shell json -f package.json version) \
+ version 2>/dev/null) && \
+ if [[ -n "$$publishedVer" ]]; then \
+ echo "error: $$name@$$ver is already published to npm"; \
+ exit 1; \
+ fi && \
+ echo "** Are you sure you want to tag and publish $$name@$$ver \
+ to npm?" && \
+ echo "** Enter to continue, Ctrl+C to abort." && \
+ read
+ ver=$(shell cat package.json | json version) && \
+ date=$(shell date -u "+%Y-%m-%d") && \
+ git tag -a "$$ver" -m "version $$ver ($$date)" && \
+ git push --tags origin && \
+ npm publish
+
+include ./tools/mk/Makefile.deps
+include ./tools/mk/Makefile.targ
+JSL_FLAGS += --nofilelist
Submodule javascriptlint added at 040bf5
Submodule jsstyle added at b94eb6
View
@@ -1,9 +1,8 @@
-#!/usr/bin/env node
/*
* Watershed:
* An implementation of RFC6455 (The WebSocket Protocol)
*
- * Copyright (c) 2013, Joyent, Inc. All rights reserved.
+ * Copyright 2016 Joyent, Inc.
*/
var crypto = require('crypto');
@@ -69,7 +68,7 @@ _generateResponse(wskey)
'Connection: Upgrade',
'Sec-WebSocket-Accept: ' + wsaccept
].join('\r\n') + '\r\n\r\n');
-};
+}
function
_wrapSocket(socket)
@@ -119,7 +118,7 @@ generateKey()
nonce[i] = Math.floor(Math.random() * 256);
}
return (nonce.toString('base64'));
-}
+};
/*
* Public: Watershed.accept(http.ServerRequest, net.Socket, Buffer)
@@ -183,7 +182,7 @@ accept(req, socket, head, detached)
local: local
};
return (new WatershedConnection(options, socket));
-}
+};
/*
* Public: Watershed.connect(http.ClientResponse, net.Socket, Buffer, String)
@@ -235,7 +234,7 @@ connect(res, socket, head, wskey, detached)
local: local
};
return (new WatershedConnection(options, socket));
-}
+};
function
WatershedConnection(options, socket)
@@ -279,7 +278,7 @@ WatershedConnection(options, socket)
options.type
]);
});
- self.on('end', function(code, reason) {
+ self.on('end', function (code, reason) {
dtrace._watershed_probes['end'].fire(function () {
return ([
self._id,
@@ -299,16 +298,16 @@ WatershedConnection(options, socket)
* for now.
*/
self._outofconstructor = false;
- process.nextTick(function() {
+ process.nextTick(function () {
self._outofconstructor = true;
self._ws_readFromSocket();
});
- self._socket.on('readable', function() {
+ self._socket.on('readable', function () {
if (!self._outofconstructor)
return;
self._ws_readFromSocket();
});
- self._socket.on('end', function() {
+ self._socket.on('end', function () {
/*
* If we did not receive a CLOSE frame, then the connection was
* terminated prematurely.
@@ -322,7 +321,7 @@ WatershedConnection(options, socket)
self.emit('end', self._close_code, self._close_reason);
});
- self._socket.on('error', function(err) {
+ self._socket.on('error', function (err) {
if (self._end_emitted)
return;
self._end_emitted = true;
@@ -360,7 +359,7 @@ end(reason)
this._close_written = true;
this._ws_writeClose(CLOSECODE.NORMAL, reason);
-}
+};
/*
* Public: WatershedConnection.destroy()
@@ -380,7 +379,7 @@ destroy()
this.emit('end', this._close_code, this._close_reason);
this._end_emitted = true;
}
-}
+};
/*
* Public: WatershedConnection.send(string)
@@ -391,14 +390,14 @@ destroy()
WatershedConnection.prototype.send = function
send(data)
{
- assert(typeof(data) === 'string' || Buffer.isBuffer(data));
+ assert(typeof (data) === 'string' || Buffer.isBuffer(data));
if (Buffer.isBuffer(data)) {
this._ws_writeBinary(data);
} else {
this._ws_writeText(data);
}
-}
+};
WatershedConnection.prototype._ws_readFromSocket = function
_ws_readFromSocket()
@@ -413,7 +412,7 @@ _ws_readFromSocket()
break;
}
}
-}
+};
/*
* Ensure that at least 'len' bytes are contiguous in the data buffer.
@@ -471,7 +470,7 @@ _ws_writeBinary(buffer)
]);
});
this._ws_writeFrameCommon(OPCODE.BINARY, buffer);
-}
+};
WatershedConnection.prototype._ws_writeText = function
_ws_writeText(text)
@@ -488,7 +487,7 @@ _ws_writeText(text)
]);
});
this._ws_writeFrameCommon(OPCODE.TEXT, new Buffer(text, 'utf8'));
-}
+};
WatershedConnection.prototype._ws_writeClose = function
_ws_writeClose(code, reason)
@@ -514,19 +513,19 @@ _ws_writeClose(code, reason)
]);
});
this._ws_writeFrameCommon(OPCODE.CLOSE, buf);
-}
+};
WatershedConnection.prototype._ws_writePing = function
_ws_writePing(nonce)
{
this._ws_writeFrameCommon(OPCODE.PING, nonce);
-}
+};
WatershedConnection.prototype._ws_writePong = function
_ws_writePong(nonce)
{
this._ws_writeFrameCommon(OPCODE.PONG, nonce);
-}
+};
WatershedConnection.prototype._ws_writeFrameCommon = function
_ws_writeFrameCommon(opcode, data)
@@ -548,8 +547,8 @@ _ws_writeFrameCommon(opcode, data)
for (var i = 0; i < maskbuf.length; i++) {
maskbuf[i] = Math.floor(Math.random * 256);
}
- for (var i = 0; i < data.length; i++) {
- data[i] = data[i] ^ maskbuf[i % maskbuf.length];
+ for (var j = 0; j < data.length; j++) {
+ data[j] = data[j] ^ maskbuf[j % maskbuf.length];
}
}
@@ -590,7 +589,7 @@ _ws_writeFrameCommon(opcode, data)
this._socket.write(maskbuf);
this._socket.write(data);
this._stats.sentFrames++;
-}
+};
WatershedConnection.prototype._ws_readFrame = function
_ws_readFrame()
@@ -712,8 +711,8 @@ _ws_readFrame()
* If the remote connection masked their payload, unmask it:
*/
if (obj.mask) {
- for (var i = 0; i < obj.payload.length; i++) {
- obj.payload[i] = obj.payload[i] ^ obj.maskbytes[i % 4];
+ for (var k = 0; k < obj.payload.length; k++) {
+ obj.payload[k] = obj.payload[k] ^ obj.maskbytes[k % 4];
}
}
@@ -751,7 +750,7 @@ _ws_readFrame()
/*
* XXX We should probably let the user do this for themselves:
*/
- this._writePong(payload);
+ this._writePong(obj.payload);
} else if (obj.opcode === OPCODE.PONG) {
this.emit('pong', obj.payload);
} else if (obj.opcode === OPCODE.CLOSE) {
@@ -784,7 +783,7 @@ _ws_readFrame()
*/
this._data = this._data.slice(pos);
return (true);
-}
+};
View
@@ -1,6 +1,6 @@
{
"name": "watershed",
- "version": "0.3.1",
+ "version": "0.3.2",
"description": "simple websockets (RFC6455) client and server",
"main": "./lib/watershed.js",
"author": "Joshua M. Clulow <jmc@joyent.com>",
View
@@ -1,31 +1,33 @@
#!/usr/bin/env node
+/*
+ * Copyright 2016 Joyent, Inc.
+ */
var http = require('http');
var Watershed = require('../../lib/watershed').Watershed;
var shed = new Watershed();
var wskey = shed.generateKey();
var options = {
- port: 9554,
- hostname: '127.0.0.1',
- headers: {
- 'connection': 'upgrade',
- 'upgrade': 'websocket',
- 'Sec-WebSocket-Key': wskey
- }
+ port: 9554,
+ hostname: '127.0.0.1',
+ headers: {
+ 'connection': 'upgrade',
+ 'upgrade': 'websocket',
+ 'Sec-WebSocket-Key': wskey
+ }
};
var req = http.request(options);
req.end();
-req.on('upgrade', function(res, socket, head) {
- socket.setNoDelay(true);
- var wsc = shed.connect(res, socket, head, wskey);
- wsc.on('text', function(text) {
- console.log('received text: %s', text);
- wsc.end('thank you and good night');
- });
- wsc.on('end', function(code, reason) {
- console.log('end! (%s: %s)', code, reason ? reason : '<null>');
- });
- wsc.send('Hi there!');
+req.on('upgrade', function (res, socket, head) {
+ socket.setNoDelay(true);
+ var wsc = shed.connect(res, socket, head, wskey);
+ wsc.on('text', function (text) {
+ console.log('received text: %s', text);
+ wsc.end('thank you and good night');
+ });
+ wsc.on('end', function (code, reason) {
+ console.log('end! (%s: %s)', code, reason ? reason : '<null>');
+ });
+ wsc.send('Hi there!');
});
-
Oops, something went wrong.

0 comments on commit 5109e83

Please sign in to comment.