Changed SocketContext.writeClientBoundPlainMessage() to be more like the master branch. Removed commented code.

This commit is contained in:
wcrisman
2014-12-29 11:08:28 -08:00
parent c0a4621a4c
commit f9be168cc8

View File

@@ -340,9 +340,7 @@ protected void writeOutgoingMessages() throws IOException {
//Close the message if possible.//
try {currentOutboundMessage.close();} catch(Throwable e) {}
//Load the next available message.//
//TODO: Swap these lines.
currentOutboundMessage = currentOutboundMessage.getNext();
// currentOutboundMessage = null;
if(currentOutboundMessage == null) lastOutboundMessage = null;
keepSending = hasPendingWrite() && key.channel().isOpen();
outboundMessage = currentOutboundMessage;
@@ -598,67 +596,46 @@ private boolean writeClientBoundPlainMessage(SocketChannel channel, MessageBuffe
boolean sendMore = true;
try {
if(sendMore && currentOutboundMessage != null) {
//Check to see if the outbound message is prepared to send more content. For chunked transfers the outbound message may be waiting for additional content from another stream and we should return later.//
if(!currentOutboundMessage.getBuffer().hasRemaining()) {
if(!currentOutboundMessage.loadBuffer()) {
if(currentOutboundMessage.getBuffer() == null && currentOutboundMessage.getNext() != null) {
currentOutboundMessage = currentOutboundMessage.getNext();
}//if//
else {
sendMore = false;
}//else//
if(sendMore && currentOutboundMessage != null && !currentOutboundMessage.isClosed()) {
//Initialize the outbound message.//
if(!currentOutboundMessage.initialize()) {
if(getWebServer().debug()) {
Debug.log(this.getId() + "|" + System.nanoTime() + "|Couldn't initialize the currentOutboundMessage.");
}//if//
if(currentOutboundMessage.getBuffer() == null) {
currentOutboundMessage = null;
lastOutboundMessage = null;
}//if//
close();
}//if//
else {
if(getWebServer().debug()) {
Debug.log(this.getId() + "|" + System.nanoTime() + "|Loading the current outbound message's buffer.");
}//if//
currentOutboundMessage.loadBuffer();
//If we have an application response pending then send it now.//
if(sendMore && currentOutboundMessage.getBuffer().hasRemaining()) {
//Keep sending encrypted frames until the output buffer is full, or we run out of message to send.//
while(sendMore && (currentOutboundMessage != null) && currentOutboundMessage.getBuffer().hasRemaining()) {
while(sendMore && currentOutboundMessage.getBuffer().hasRemaining()) { // && !currentOutboundMessage.isClosed()
//Write the bytes to the stream.//
((SocketChannel) key.channel()).write(currentOutboundMessage.getBuffer());
channel.write(currentOutboundMessage.getBuffer());
if(getWebServer().debug()) {
sentBytes += currentOutboundMessage.getBuffer().position();
Debug.log(this.getId() + "|" + System.nanoTime() + "|Wrote " + currentOutboundMessage.getBuffer().position() + " bytes to the client. Total sent: " + sentBytes + ".");
}//if//
//If not all the bytes could be written then we will need to wait until we can write more.//
if(currentOutboundMessage.getBuffer().hasRemaining()) {
sendMore = false;
}//if//
else {
if(!currentOutboundMessage.loadBuffer()) {
//Load the next pending outbound message in the chain. This is currently only used for content being passed through to another process via a second socket.//
if(currentOutboundMessage.getBuffer() == null && currentOutboundMessage.getNext() != null) {
currentOutboundMessage = currentOutboundMessage.getNext();
}//if//
else {
//Wait until additional message bytes are available.//
sendMore = false;
}//else//
}//if//
//If the message end has been reached then the buffer will be null.//
if(currentOutboundMessage.getBuffer() == null) {
currentOutboundMessage = null;
lastOutboundMessage = null;
}//if//
sendMore = currentOutboundMessage.loadBuffer();
}//else//
}//while//
}//if//
}//else//
}//if//
}//try//
catch(ClosedChannelException e) {
close();
}//catch//
catch(SSLException e) {
if(getWebServer().debug()) {
Debug.log(e);
}//if//
close();
}//catch//
catch(IOException e) {
if(getWebServer().debug()) {
Debug.log(e);
@@ -758,7 +735,6 @@ protected void readIncomingMessages() throws IOException {
IPassThroughDomain passThroughDomain = ((IPassThroughDomain) application);
//Setup the pass through socket context (and socket channel). All data will be sent to this context to be sent to the remote process.//
// relatedSocketContext = new PassThroughSocketContext(getWebServer(), getNetworkListener(), this, passThroughDomain.getAddress(), passThroughDomain.getPort());
relatedSocketContext = new PassThroughSocketContext(this, passThroughDomain.getAddress(), passThroughDomain.getPort());
}//if//
}//if//