Skip to content

Commit 92cb351

Browse files
committed
fixing issue Gottox#16
1 parent 00d1a7a commit 92cb351

File tree

1 file changed

+30
-34
lines changed

1 file changed

+30
-34
lines changed

src/io/socket/IOConnection.java

+30-34
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,17 @@ private void error(SocketIOException e) {
443443
* @param text
444444
* the Text to be send.
445445
*/
446-
private void sendPlain(String text) {
447-
synchronized (outputBuffer) {
448-
if (getState() == STATE_READY)
449-
try {
450-
logger.info("> " + text);
451-
transport.send(text);
452-
} catch (Exception e) {
453-
logger.info("IOEx: saving");
454-
outputBuffer.add(text);
455-
}
456-
else {
446+
private synchronized void sendPlain(String text) {
447+
if (getState() == STATE_READY)
448+
try {
449+
logger.info("> " + text);
450+
transport.send(text);
451+
} catch (Exception e) {
452+
logger.info("IOEx: saving");
457453
outputBuffer.add(text);
458454
}
455+
else {
456+
outputBuffer.add(text);
459457
}
460458
}
461459

@@ -505,38 +503,36 @@ private IOCallback findCallback(IOMessage message) throws SocketIOException {
505503
*
506504
* {@link IOTransport} calls this when a connection is established.
507505
*/
508-
public void transportConnected() {
506+
public synchronized void transportConnected() {
509507
setState(STATE_READY);
510508
if (reconnectTask != null) {
511509
reconnectTask.cancel();
512510
reconnectTask = null;
513511
}
514512
resetTimeout();
515-
synchronized (outputBuffer) {
516-
if (transport.canSendBulk()) {
517-
ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
518-
this.outputBuffer = new ConcurrentLinkedQueue<String>();
519-
try {
520-
// DEBUG
521-
String[] texts = outputBuffer
522-
.toArray(new String[outputBuffer.size()]);
523-
logger.info("Bulk start:");
524-
for (String text : texts) {
525-
logger.info("> " + text);
526-
}
527-
logger.info("Bulk end");
528-
// DEBUG END
529-
transport.sendBulk(texts);
530-
} catch (IOException e) {
531-
this.outputBuffer = outputBuffer;
513+
if (transport.canSendBulk()) {
514+
ConcurrentLinkedQueue<String> outputBuffer = this.outputBuffer;
515+
this.outputBuffer = new ConcurrentLinkedQueue<String>();
516+
try {
517+
// DEBUG
518+
String[] texts = outputBuffer.toArray(new String[outputBuffer
519+
.size()]);
520+
logger.info("Bulk start:");
521+
for (String text : texts) {
522+
logger.info("> " + text);
532523
}
533-
} else {
534-
String text;
535-
while ((text = outputBuffer.poll()) != null)
536-
sendPlain(text);
524+
logger.info("Bulk end");
525+
// DEBUG END
526+
transport.sendBulk(texts);
527+
} catch (IOException e) {
528+
this.outputBuffer = outputBuffer;
537529
}
538-
this.keepAliveInQueue = false;
530+
} else {
531+
String text;
532+
while ((text = outputBuffer.poll()) != null)
533+
sendPlain(text);
539534
}
535+
this.keepAliveInQueue = false;
540536
}
541537

542538
/**

0 commit comments

Comments
 (0)