Revert "Updated/Fixed queueOutboundClientMessage(..), sendHttpResponse(..), and hasPendingWrite()."
This reverts commit 48724e445c.
This commit is contained in:
@@ -1100,7 +1100,10 @@ public class WebServer {
|
||||
}//if//
|
||||
else if(!buffer.hasRemaining()) {
|
||||
//Clear the buffer pointer indicating the message buffer is done.//
|
||||
close();
|
||||
//Does this cause the bug?
|
||||
// close();
|
||||
//Comment out buffer = null;
|
||||
buffer = null;
|
||||
result = false;
|
||||
}//else if//
|
||||
//Does this cause the bug?
|
||||
@@ -1553,23 +1556,21 @@ public class WebServer {
|
||||
*/
|
||||
private void queueOutboundClientMessage(MessageBuffer messageBuffer) {
|
||||
boolean notify = false;
|
||||
|
||||
if(messageBuffer != null) {
|
||||
synchronized(getLock()) {
|
||||
if(currentOutboundMessage == null) {
|
||||
lastOutboundMessage = currentOutboundMessage = messageBuffer;
|
||||
notify = true;
|
||||
|
||||
synchronized(this) {
|
||||
if(currentOutboundMessage == null) {
|
||||
lastOutboundMessage = currentOutboundMessage = messageBuffer;
|
||||
notify = true;
|
||||
}//if//
|
||||
else {
|
||||
lastOutboundMessage.setNext(messageBuffer);
|
||||
lastOutboundMessage = messageBuffer;
|
||||
}//else//
|
||||
}//synchronized()//
|
||||
|
||||
if(notify) {
|
||||
notifyListenerOfPendingWrite();
|
||||
lastOutboundMessage.setNext(messageBuffer);
|
||||
lastOutboundMessage = messageBuffer;
|
||||
}//else//
|
||||
}//synchronized()//
|
||||
|
||||
if(notify) {
|
||||
notifyListenerOfPendingWrite();
|
||||
}//if//
|
||||
}//if//
|
||||
}//queueOutboundClientMessage()//
|
||||
private void writeSessionCookies(PrintStream pout) {
|
||||
Response response = currentResponse;
|
||||
@@ -1607,23 +1608,20 @@ public class WebServer {
|
||||
* @result Whether request is in a receive state. Will be false if the request generated a response that could not be completely transmitted.
|
||||
*/
|
||||
public synchronized boolean sendHttpResponse(Response response) {
|
||||
queueOutboundClientMessage(new HttpMessageBuffer(response));
|
||||
request = null;
|
||||
if(currentResponse != null) {
|
||||
lastResponse.setNextResponse(response);
|
||||
lastResponse = response;
|
||||
}//if//
|
||||
else {
|
||||
lastResponse = currentResponse = response;
|
||||
sentBytes = 0;
|
||||
prepareResponse();
|
||||
|
||||
//Note: Not going to process the response on this thread. Allow the flag to be set for writing to the socket, and have the next thread in the network listener handle the write. This allows for cleaner code and pipelining without all the synchronizing.
|
||||
// result = internalProcessResponses();
|
||||
}//else//
|
||||
|
||||
// if(currentResponse != null) {
|
||||
// lastResponse.setNextResponse(response);
|
||||
// lastResponse = response;
|
||||
// }//if//
|
||||
// else {
|
||||
// lastResponse = currentResponse = response;
|
||||
// sentBytes = 0;
|
||||
// prepareResponse();
|
||||
//
|
||||
// //Note: Not going to process the response on this thread. Allow the flag to be set for writing to the socket, and have the next thread in the network listener handle the write. This allows for cleaner code and pipelining without all the synchronizing.
|
||||
//// result = internalProcessResponses();
|
||||
// }//else//
|
||||
//
|
||||
// request = null;
|
||||
request = null;
|
||||
|
||||
return false;
|
||||
}//sendHttpResponse()//
|
||||
@@ -1655,14 +1653,8 @@ public class WebServer {
|
||||
*/
|
||||
protected void writeOutgoingMessages() throws IOException {
|
||||
Debug.log(id + "," + System.nanoTime() + "," + "Writing outgoing messages.");
|
||||
if(key.channel().isOpen() && currentOutboundMessage != null && !currentOutboundMessage.isClosed()) {
|
||||
if(key.channel().isOpen() && currentOutboundMessage != null && currentOutboundMessage.isClosed()) {
|
||||
writeClientBoundMessage();
|
||||
|
||||
if(currentOutboundMessage.isClosed()) {
|
||||
//Sets the current outbound message to null, or to the next outgoing message if there are messages queued.//
|
||||
currentOutboundMessage = currentOutboundMessage.getNext();
|
||||
Debug.log(id + "," + System.nanoTime() + "," + "Message Finished Sending! currentOutboundMessage=" + currentOutboundMessage);
|
||||
}//if//
|
||||
}//if//
|
||||
else {
|
||||
Debug.log(id + "," + System.nanoTime() + "," + "No outgoing messages to write!.");
|
||||
@@ -1712,6 +1704,49 @@ public class WebServer {
|
||||
// }//else//
|
||||
// }//while//
|
||||
}//writeOutgoingMessages()//
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
private synchronized void internalProcessResponses() {
|
||||
boolean finishedSending = true;
|
||||
|
||||
//Keep sending responses while the buffers are not full and there is another response to send.//
|
||||
while(finishedSending && currentResponse != null) {
|
||||
//If the socket is open then send the next buffer of data.//
|
||||
if(key.channel().isOpen()) {
|
||||
//Send the pending response object's prepared buffer of data.//
|
||||
finishedSending = writeClientBoundMessage();
|
||||
}//if//
|
||||
|
||||
//Close the response if successfully sent, or if the socket is closed.//
|
||||
if(finishedSending || !key.channel().isOpen()) {
|
||||
try {currentResponse.close();} catch(Throwable e) {}
|
||||
}//if//
|
||||
|
||||
//If we finished sending the current response then load the next one.//
|
||||
if(finishedSending) {
|
||||
currentResponse = currentResponse.getNextResponse();
|
||||
|
||||
if(currentResponse == null) {
|
||||
lastResponse = null;
|
||||
}//if//
|
||||
else if(key.channel().isOpen()) {
|
||||
//Prep the next response object for sending.//
|
||||
prepareResponse();
|
||||
}//else//
|
||||
else {
|
||||
//Clean up after all the left over responses.//
|
||||
while(currentResponse != null) {
|
||||
currentResponse.close();
|
||||
currentResponse = currentResponse.getNextResponse();
|
||||
}//while//
|
||||
|
||||
currentResponse = null;
|
||||
lastResponse = null;
|
||||
}//else//
|
||||
}//if//
|
||||
}//while//
|
||||
}//processCurrentResponse()//
|
||||
/**
|
||||
* Loads the next outbound websocket message and attempts to write it to the socket until all outbound messages have been sent, or the socket's buffers are full and a wait is required.
|
||||
* If a message could only be partially sent then the next call will attempt to finish sending it.
|
||||
@@ -2372,8 +2407,7 @@ public class WebServer {
|
||||
* @see com.foundation.web.server.WebServer.AbstractSocketContext#hasPendingWrite()
|
||||
*/
|
||||
protected boolean hasPendingWrite() {
|
||||
//Will have a pending write if either the current outbound messages is non-null (finished messages should no longer be referenced), or if SSL is used and there is a handshake or maintenance message queued in the encrypted write buffer.//
|
||||
return currentOutboundMessage != null || (sslEngine != null && encryptedWriteBuffer.hasRemaining());
|
||||
return currentOutboundMessage != null || (encryptedWriteBuffer != null && encryptedWriteBuffer.hasRemaining());
|
||||
}//hasPendingWrite()//
|
||||
/* (non-Javadoc)
|
||||
* @see com.foundation.web.interfaces.IConnectionContext#upgradeToWebsocket(java.lang.String, long, com.foundation.web.interfaces.WebsocketHandler)
|
||||
|
||||
Reference in New Issue
Block a user