This commit is contained in:
lightings 2023-07-21 11:39:45 +08:00
parent 715dc47053
commit 12b4e1f775
2 changed files with 21 additions and 10 deletions

View File

@ -18,9 +18,10 @@ const newLog = function() {
const minute = date.getMinutes(); const minute = date.getMinutes();
const second = date.getSeconds(); 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); arguments.callee.oLog.apply(this, arguments);
} };
const newError = function () { const newError = function () {
const date = new Date(); const date = new Date();
@ -32,9 +33,10 @@ const newError = function() {
const minute = date.getMinutes(); const minute = date.getMinutes();
const second = date.getSeconds(); 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); arguments.callee.oError.apply(this, arguments);
} };
newLog.oLog = console.log; newLog.oLog = console.log;
newError.oError = console.error; newError.oError = console.error;
@ -75,9 +77,14 @@ function proxy(config) {
{ host: srcHost, port: srcPort, log: true }, { host: srcHost, port: srcPort, log: true },
() => { () => {
isReady = true; isReady = true;
try {
connectBuffer.forEach((data) => { connectBuffer.forEach((data) => {
stick.putData(data); stick.putData(data);
}); });
} catch (e) {
console.log("putData error", e);
socket.destroy();
}
}, },
(route, body) => { (route, body) => {
repPush(route, body); repPush(route, body);

View File

@ -118,6 +118,10 @@ const StackBuffer = function (bufferSize) {
if (availableLen < dataLength) { if (availableLen < dataLength) {
// 以512字节为基数扩展Buffer空间 // 以512字节为基数扩展Buffer空间
let exLength = Math.ceil((_dataLen + dataLength) / 512) * 512; 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); let tempBuffer = Buffer.alloc(exLength);
//_buffer.copy(tempBuffer); //_buffer.copy(tempBuffer);
_bufferLength = exLength; _bufferLength = exLength;
@ -266,7 +270,7 @@ const StackBuffer = function (bufferSize) {
if (_bufferLength - _dataReadPosition < dataLen) { if (_bufferLength - _dataReadPosition < dataLen) {
let firstPartLen = _bufferLength - _dataReadPosition; let firstPartLen = _bufferLength - _dataReadPosition;
// 读取第一部分,直接到字符尾部的数据 // 读取第一部分,直接到字符尾部的数据
_buffer.copy(readData, 0, _dataReadPosition, firstPartLen + _dataReadPosition); _buffer.copy(readData, 0, _dataReadPosition, _dataReadPosition + firstPartLen);
// 读取第二部分,存储在开头的数据 // 读取第二部分,存储在开头的数据
let secondPartLen = dataLen - firstPartLen; let secondPartLen = dataLen - firstPartLen;
_buffer.copy(readData, firstPartLen, 0, secondPartLen); _buffer.copy(readData, firstPartLen, 0, secondPartLen);