Commit 99ae4a90 authored by mercury233's avatar mercury233

add looplimit

parent 39ee483e
...@@ -116,6 +116,8 @@ net.createServer (client) -> ...@@ -116,6 +116,8 @@ net.createServer (client) ->
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学 ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length) #buffer的错误使用方式,好孩子不要学
datas = [] datas = []
looplimit = 0
while true while true
if ctos_message_length == 0 if ctos_message_length == 0
...@@ -148,6 +150,14 @@ net.createServer (client) -> ...@@ -148,6 +150,14 @@ net.createServer (client) ->
ctos_proto = 0 ctos_proto = 0
else else
break break
looplimit++
#log.info(looplimit)
if looplimit>800
log.info("error ctos")
server.end()
break
if client.established if client.established
server.write buffer for buffer in datas server.write buffer for buffer in datas
else else
...@@ -165,6 +175,8 @@ net.createServer (client) -> ...@@ -165,6 +175,8 @@ net.createServer (client) ->
#unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous #unless ygopro.stoc_follows[stoc_proto] and ygopro.stoc_follows[stoc_proto].synchronous
client.write data client.write data
looplimit = 0
while true while true
if stoc_message_length == 0 if stoc_message_length == 0
...@@ -194,8 +206,15 @@ net.createServer (client) -> ...@@ -194,8 +206,15 @@ net.createServer (client) ->
stoc_proto = 0 stoc_proto = 0
else else
break break
return
return looplimit++
#log.info(looplimit)
if looplimit>800
log.info("error stoc")
server.end()
break
return
return
.listen settings.port, -> .listen settings.port, ->
log.info "server started", settings.ip, settings.port log.info "server started", settings.ip, settings.port
return return
......
...@@ -126,12 +126,13 @@ ...@@ -126,12 +126,13 @@
ctos_proto = 0; ctos_proto = 0;
client.pre_establish_buffers = new Array(); client.pre_establish_buffers = new Array();
client.on('data', function(data) { client.on('data', function(data) {
var b, buffer, cancel, datas, k, l, len, len1, struct; var b, buffer, cancel, datas, k, l, len, len1, looplimit, struct;
if (client.is_post_watcher) { if (client.is_post_watcher) {
client.room.watcher.write(data); client.room.watcher.write(data);
} else { } else {
ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length); ctos_buffer = Buffer.concat([ctos_buffer, data], ctos_buffer.length + data.length);
datas = []; datas = [];
looplimit = 0;
while (true) { while (true) {
if (ctos_message_length === 0) { if (ctos_message_length === 0) {
if (ctos_buffer.length >= 2) { if (ctos_buffer.length >= 2) {
...@@ -171,6 +172,12 @@ ...@@ -171,6 +172,12 @@
break; break;
} }
} }
looplimit++;
if (looplimit > 800) {
log.info("error ctos");
server.end();
break;
}
} }
if (client.established) { if (client.established) {
for (k = 0, len = datas.length; k < len; k++) { for (k = 0, len = datas.length; k < len; k++) {
...@@ -189,9 +196,10 @@ ...@@ -189,9 +196,10 @@
stoc_message_length = 0; stoc_message_length = 0;
stoc_proto = 0; stoc_proto = 0;
server.on('data', function(data) { server.on('data', function(data) {
var b, stanzas, struct; var b, looplimit, stanzas, struct;
stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length); stoc_buffer = Buffer.concat([stoc_buffer, data], stoc_buffer.length + data.length);
client.write(data); client.write(data);
looplimit = 0;
while (true) { while (true) {
if (stoc_message_length === 0) { if (stoc_message_length === 0) {
if (stoc_buffer.length >= 2) { if (stoc_buffer.length >= 2) {
...@@ -224,6 +232,12 @@ ...@@ -224,6 +232,12 @@
break; break;
} }
} }
looplimit++;
if (looplimit > 800) {
log.info("error stoc");
server.end();
break;
}
} }
}); });
}).listen(settings.port, function() { }).listen(settings.port, function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment