Permalink
Browse files

ext-hub not extend socket properties

  • Loading branch information...
1 parent 70a6b57 commit 1e44ec934f15c0cff088475817c7e8f7fa8d53bc @kaven276 committed Oct 10, 2012
Showing with 23 additions and 16 deletions.
  1. +23 −16 lib/ext_hub.js
View
@@ -42,10 +42,20 @@ function gracefulQuit(){
// todo: should let oracle to send quit alert first
utl.gracefulExit(gracefulQuit);
+
+function OraSock(oraSock, data){
+ this.socket = oraSock;
+ this.sid = data.readInt32BE(4);
+ this.serial = data.readInt32BE(8);
+ this.asid = data.readUInt32BE(12);
+ this.oraSeq = data.readInt32BE(16);
+}
+
/** @define {int} */
var onDataCount = 0;
var server = net.createServer(function(oraSock){
+ var rec;
logConnOra('oracle connected');
console.log('oracle connected');
@@ -54,11 +64,12 @@ var server = net.createServer(function(oraSock){
logConnOra('NO.%d data arrived from oracle(%d,%d) len=%d', ++onDataCount, oraSock.sid || 0, oraSock.serial || 0, data.length);
});
- var sid, serial, asid;
oraSock.once('data', onHandshake);
oraSock.on('close', function(){
- delete oraSocks[oraSock.asid];
+ if (rec && rec.asid) {
+ delete oraSocks[rec.asid];
+ }
logConnOra('connection closed, now have %d', server.connections);
});
@@ -76,12 +87,10 @@ var server = net.createServer(function(oraSock){
return;
}
- oraSock.sid = sid = data.readInt32BE(4);
- oraSock.serial = serial = data.readInt32BE(8);
- oraSock.asid = asid = data.readUInt32BE(12);
- oraSock.oraSeq = data.readInt32BE(16);
- oraSocks[asid] = oraSock;
- logConnOra('oracle connected asid=%d, sid = %d, serial = %d, initial oraSeq = %d', asid, sid, serial, oraSock.oraSeq);
+ var asid = data.readUInt32BE(12);
+ rec = oraSocks[asid] = new OraSock(oraSock, data);
+
+ logConnOra('oracle connected(%d,%d,%d,%d)', rec.asid, rec.sid, rec.serial, rec.oraSeq);
new StreamSpliter(oraSock, 'readInt32BE', onOracleRequest);
if (data.length !== 20) {
@@ -95,15 +104,14 @@ var server = net.createServer(function(oraSock){
var proxyID = oraReq.readInt32BE(4)
, wpw = wpSocks[proxyID]
;
+ logPDU('> ora(%d,%d,%d,%d) - wp(%d)', rec.asid, rec.sid, rec.serial, rec.oraSeq, proxyID);
if (!wpw) {
console.warn('%s, proxy %d is not exists', new Date(), proxyID);
return;
}
/* replace proxyID field with oraSeq */
- logPDU('> ora(%d,%d,%d,%d) - wp(%d)', asid, sid, serial, oraSock.oraSeq, proxyID);
-
- oraReq.writeInt32BE(oraSock.oraSeq++, 4);
+ oraReq.writeInt32BE(rec.oraSeq, 4);
(wpw.sts === 'opened') ? wpw.wpSock.write(oraReq) : wpw.queue.push(oraReq);
}
});
@@ -160,16 +168,15 @@ function WPWrapper(id, hostp, desc){
var oraSeq = proxyResp.readInt32BE(4)
, asid = proxyResp.readInt32BE(8)
- , oraSock = oraSocks[asid]
+ , rec = oraSocks[asid]
;
- // logPDU('reply for proxySeq=%d, %s', proxySeq, proxyResp.slice(0, 6).toString('hex'));
- if (!oraSock) {
+ if (!rec) {
console.warn('can not find the sending oracle connection, reply will lose');
return;
}
- oraSock.write(proxyResp);
- logPDU('< ora(%d,%d,%d,%d) - wp(%d)', oraSock.asid, oraSock.sid, oraSock.serial, oraSeq, wpw.id);
+ rec.socket.write(proxyResp);
+ logPDU('< ora(%d,%d,%d,%d) - wp(%d)', rec.asid, rec.sid, rec.serial, oraSeq, wpw.id);
}
}

0 comments on commit 1e44ec9

Please sign in to comment.