diff --git a/Platform.cpp b/Platform.cpp index e8dc672..d120772 100644 --- a/Platform.cpp +++ b/Platform.cpp @@ -716,6 +716,11 @@ void SetNetworkDataToSend(char* data, int length); void CloseConnection(); +bool NoMoreData() +{ + return !reprap.GetWebserver()->WebserverIsWriting(); +} + // Called to put out a message via the RepRap firmware. void RepRapNetworkMessage(char* s) @@ -806,10 +811,6 @@ void Network::Spin() SendDataFromRepRapNetwork(); - // Poll the network, and update its timers. - - ethernet_task(); - // If we've finished generating data, queue up the // last bytes recorded (which may not fill the // buffer) to send. @@ -822,6 +823,7 @@ void Network::Spin() outputPointer = 0; } } + } @@ -862,7 +864,7 @@ void Network::Write(char b) return; } - if(outputLength > 0) + if(outputLength >= 0) { reprap.GetPlatform()->Message(HOST_MESSAGE, "Network::Write(char b) - Attempt to write to unflushed buffer.\n"); return; @@ -897,7 +899,7 @@ void Network::Write(char b) bool Network::DataToSendAvailable() { - return (outputLength > 0); + return (outputLength >= 0); } bool Network::CanWrite() @@ -911,7 +913,7 @@ void Network::SetWriteEnable(bool enable) // Reset the write buffer if needs be. - if(writeEnabled && outputLength > 0) + if(writeEnabled && outputLength >= 0) { outputLength = -1; outputPointer = 0; @@ -945,7 +947,8 @@ bool Network::Read(char& b) void Network::Close() { - CloseConnection(); + if(Status() && clientLive) + CloseConnection(); Reset(); } diff --git a/network/httpd.c b/network/httpd.c index ea5726a..ed1722c 100644 --- a/network/httpd.c +++ b/network/httpd.c @@ -73,6 +73,7 @@ struct http_state { void RepRapNetworkReceiveInput(char* ip, int length); void RepRapNetworkMessage(char* s); void RepRapNetworkAllowWriting(); +bool NoMoreData(); // Static storage for pointers that need to be saved when we go // out to the RepRap firmware for when it calls back in again. @@ -85,7 +86,6 @@ static struct http_state* activeHttpState; static struct pbuf* pbufToFree = 0; static struct tcp_pcb* sendingPcb = 0; static int initCount = 0; -bool alreadySending = false; /*-----------------------------------------------------------------------------------*/ static void @@ -106,14 +106,13 @@ void CloseConnection() { if(pcbToClose == 0) return; - RepRapNetworkMessage("CloseConnection() called.\n"); tcp_arg(pcbToClose, NULL); tcp_sent(pcbToClose, NULL); tcp_recv(pcbToClose, NULL); //mem_free(hs); tcp_close(pcbToClose); pcbToClose = 0; - alreadySending = false; + RepRapNetworkMessage("CloseConnection() called.\n"); } // httpd.c's close function, slightly mashed... @@ -127,7 +126,6 @@ close_conn(struct tcp_pcb *pcb, struct http_state *hs) tcp_recv(pcb, NULL); //mem_free(hs); tcp_close(pcb); - alreadySending = false; } char scratch[40]; @@ -159,6 +157,8 @@ send_data(struct tcp_pcb *pcb, struct http_state *hs) } } while (err == ERR_MEM && len > 1); + tcp_output(pcb); + if (err == ERR_OK) { hs->file += len; hs->left -= len; @@ -210,16 +210,13 @@ http_sent(void *arg, struct tcp_pcb *pcb, u16_t len) send_data(pcb, hs); } else { - // See if there is more to send, and remember the - // pcb for when the connection is closed. + // See if there is more to send // TODO - possible memory leak? RepRapNetworkAllowWriting(); - sendingPcb = pcb; - pcbToClose = pcb; - tcp_sent(pcb, http_sent); - //close_conn(pcb, hs); } + pcbToClose = pcb; + return ERR_OK; } /*-----------------------------------------------------------------------------------*/ @@ -244,16 +241,11 @@ void SetNetworkDataToSend(char* data, int length) send_data(sendingPcb, activeHttpState); - if(alreadySending) - return; - /* Tell TCP that we wish be to informed of data that has been successfully sent by a call to the http_sent() function. */ tcp_sent(sendingPcb, http_sent); - - alreadySending = true; } static err_t