Skip to content
Browse files

fixed bugs with node 0.10.*

  • Loading branch information...
1 parent 524c6a3 commit aa3925ee2a35c1cca29f6780492c0c1ccf311d3c @VanCoding committed Apr 3, 2013
Showing with 30 additions and 28 deletions.
  1. +5 −2 examples/ws/target.js
  2. +19 −14 lib/ancillary.js
  3. +6 −12 lib/spdyroot.js
View
7 examples/ws/target.js
@@ -13,8 +13,8 @@ function route(req,res,data){
//handle the upgrade request
wss.handleUpgrade(req,res,data,function(c){
- console.log("got connection");
- var i = 0;
+ console.log("got connection");
+ var i = 0;
setInterval(function(){
c.send((i++)+"");
},1000);
@@ -31,6 +31,9 @@ function route(req,res,data){
"var ws = new WebSocket('wss://'+location.host);",
"ws.onopen=function(){",
"console.log('connected to server');",
+ "setInterval(function(){",
+ "ws.send('hello world!')",
+ "},1000);",
"}",
"ws.onmessage=function(d){",
"console.log('got data from server: '+d.data);",
View
33 lib/ancillary.js
@@ -17,7 +17,7 @@ module.exports.proxySpdy = require("./spdyroot.js");
module.exports.attachHttp = function(server,raw){
if(raw){
server.on("connection",function(c){
- var req = new httpjs.httpParser(c,true);
+ var req = new httpjs.httpParser(c,true);
req.on("open",function(res){
if(req.headers.upgrade == "websocket" || req.headers.connection == "upgrade"){
req.upgrade = true;
@@ -26,6 +26,7 @@ module.exports.attachHttp = function(server,raw){
server.emit("request",req,res);
}
});
+ req.resume();
});
}else{
server.on("connection",function(c){
@@ -54,12 +55,12 @@ module.exports.createServer = function(cb){
var p = new Pipe(true);
p.onconnection = function(c){
c.onread = function(){
- var s = new net.Socket({handle:arguments[3]});
+ var s = new net.Socket({handle:arguments[3],allowHalfOpen:true});
s.readable = s.writable = true;
- server.emit("connection",s);
-
- s._handle.onread(arguments[0],arguments[1]+1,arguments[2]-1);
- s.resume();
+ server.emit("connection",s);
+ var data = arguments[0].slice(arguments[1]+1,arguments[2]-1);
+ arguments[3].onread(arguments[0],arguments[1]+1,arguments[2]-1);
+ s.resume();
}
ancillary.makeIPC(c);
c.readStart();
@@ -94,9 +95,8 @@ var connectionlist = {};
var queues = {};
module.exports.send = function(name,socket,data){
-
- if(socket.connection){
-
+
+ if(socket.connection){
var req = socket;
socket = req.connection;
data = req.method+" "+req.url+" HTTP/"+req.httpVersion+"\r\n";
@@ -109,7 +109,9 @@ module.exports.send = function(name,socket,data){
data += d;
});
}
- socket.pause();
+ socket._handle.readStop();
+
+
setTimeout(continueSend,0);
function continueSend(){
@@ -134,19 +136,20 @@ module.exports.send = function(name,socket,data){
try{
var p = new Pipe(true);
p.connect(name).oncomplete = function(fd){
- connectionlist[name] = p;
if(fd >= 0){
+ connectionlist[name] = p;
p.onread = function(got){
if(!got){
p.shutdown().oncomplete = function(){};
delete connectionlist[name];
}
};
- p.readStart();
+ p.readStart();
}
- continueSendHandle(p);
+ continueSendHandle(p);
}
}catch(e){
+ console.log(e);
}
}
}else{
@@ -157,10 +160,12 @@ module.exports.send = function(name,socket,data){
function continueSendHandle(p){
try{
p.writeUtf8String(queues[name][0].data,queues[name][0].handle).oncomplete = function(a){
- queues[name].shift().socket.destroy();
+ var item = queues[name].shift();
+ item.socket.destroy();
process();
};
}catch(e){
+ console.log(e);
}
}
}
View
18 lib/spdyroot.js
@@ -23,7 +23,7 @@ module.exports = function(port,opts,target){
var s = spdy.createServer(opts,handle);
- function handle(req,res){
+ function handle(req,res,sock){
var c = net.connect(serverpath,function(){
@@ -34,15 +34,15 @@ module.exports = function(port,opts,target){
}
header += "\r\n";
c.write(header);
- req.pipe(c);
+ (sock?sock:req).pipe(c);
var res2 = new httpjs.httpParser(c,false);
var open = false;
res2.on("open",function(){
open = true;
res.writeHead(res2.statusCode,res2.statusMessage,res2.headers);
- res2.pipe(res);
+ res2.pipe(res);
});
res2.on("close",function(){
if(!open){
@@ -55,15 +55,9 @@ module.exports = function(port,opts,target){
s.on("upgrade",function(req,sock,data){
- sock.on("data",function(d){
- req.emit("data",d);
- });
- sock.on("end",function(){
- req.emit("end");
- });
- var res = new httpjs.httpResponse(sock);
- handle(req,res);
- });
+ var res = new httpjs.httpResponse(sock);
+ handle(req,res,sock);
+ });
s.listen(port);

0 comments on commit aa3925e

Please sign in to comment.
Something went wrong with that request. Please try again.