...
This commit is contained in:
parent
715dc47053
commit
12b4e1f775
25
proxy/app.js
25
proxy/app.js
@ -8,7 +8,7 @@ const process = require("process");
|
||||
const config = process.argv[2] || "default";
|
||||
const proxyList = require(`./config/${config}.json`);
|
||||
|
||||
const newLog = function() {
|
||||
const newLog = function () {
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
@ -18,11 +18,12 @@ const newLog = function() {
|
||||
const minute = date.getMinutes();
|
||||
const second = date.getSeconds();
|
||||
|
||||
arguments[0] = `${year}-${month}-${day} ${hour}:${minute}:${second} ` + arguments[0];
|
||||
arguments[0] =
|
||||
`${year}-${month}-${day} ${hour}:${minute}:${second} ` + arguments[0];
|
||||
arguments.callee.oLog.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
const newError = function() {
|
||||
const newError = function () {
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
@ -32,9 +33,10 @@ const newError = function() {
|
||||
const minute = date.getMinutes();
|
||||
const second = date.getSeconds();
|
||||
|
||||
arguments[0] = `${year}-${month}-${day} ${hour}:${minute}:${second} ` + arguments[0];
|
||||
arguments[0] =
|
||||
`${year}-${month}-${day} ${hour}:${minute}:${second} ` + arguments[0];
|
||||
arguments.callee.oError.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
newLog.oLog = console.log;
|
||||
newError.oError = console.error;
|
||||
@ -75,9 +77,14 @@ function proxy(config) {
|
||||
{ host: srcHost, port: srcPort, log: true },
|
||||
() => {
|
||||
isReady = true;
|
||||
connectBuffer.forEach((data) => {
|
||||
stick.putData(data);
|
||||
});
|
||||
try {
|
||||
connectBuffer.forEach((data) => {
|
||||
stick.putData(data);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("putData error", e);
|
||||
socket.destroy();
|
||||
}
|
||||
},
|
||||
(route, body) => {
|
||||
repPush(route, body);
|
||||
|
@ -118,6 +118,10 @@ const StackBuffer = function (bufferSize) {
|
||||
if (availableLen < dataLength) {
|
||||
// 以512字节为基数扩展Buffer空间
|
||||
let exLength = Math.ceil((_dataLen + dataLength) / 512) * 512;
|
||||
if (exLength > 1024*1024) {
|
||||
console.error('exLength > 1024*1024');
|
||||
throw new Error('exLength > 1024*1024');
|
||||
}
|
||||
let tempBuffer = Buffer.alloc(exLength);
|
||||
//_buffer.copy(tempBuffer);
|
||||
_bufferLength = exLength;
|
||||
@ -266,7 +270,7 @@ const StackBuffer = function (bufferSize) {
|
||||
if (_bufferLength - _dataReadPosition < dataLen) {
|
||||
let firstPartLen = _bufferLength - _dataReadPosition;
|
||||
// 读取第一部分,直接到字符尾部的数据
|
||||
_buffer.copy(readData, 0, _dataReadPosition, firstPartLen + _dataReadPosition);
|
||||
_buffer.copy(readData, 0, _dataReadPosition, _dataReadPosition + firstPartLen);
|
||||
// 读取第二部分,存储在开头的数据
|
||||
let secondPartLen = dataLen - firstPartLen;
|
||||
_buffer.copy(readData, firstPartLen, 0, secondPartLen);
|
||||
|
Loading…
x
Reference in New Issue
Block a user