/** * Handle client communications */ void client_task_impl() { uip_tcp_appstate_t *app = &(uip_conn->appstate); GETrequest *req = (GETrequest*)app->request; if (uip_connected()) { if (verbose) { Serial.print("Connected to "); Serial.println(req->hostName); } app->ackedCount = 0; sendRequest(); } // Did we get an ack for the last packet? if (uip_acked()) { // Record the bytes that were successfully sent app->ackedCount += app->sentCount; app->sentCount = 0; // Check if we're done or need to send more content for this // request if (app->ackedCount != (int)app->cursor) { // Generate the post again to send the next packet of data sendRequest(); } } if (uip_rexmit()) { sendRequest(); } if (uip_newdata()) { setRXPin(HIGH); if (verbose) { Serial.print("RX "); Serial.print(uip_datalen()); Serial.print(" bytes from "); Serial.println(req->hostName); } // Check if the sketch cares about the returned data if ((req->returnFunc) && (uip_datalen() > 0)){ // Call the sketch's callback function req->returnFunc((char*)uip_appdata, uip_datalen()); } } if (uip_aborted() || uip_timedout() || uip_closed()) { if (req != NULL) { if (verbose) { Serial.print("Ended connection with "); Serial.println(req->hostName); } if (req->returnFunc) { // Call the sketch's callback function with 0 bytes to indicate End Of Data req->returnFunc((char*)uip_appdata, 0); } // Remove the request from the connection app->request = NULL; // Request is no longer active req->active = false; } } }
/** * Handle client communications */ void client_task_impl() { uip_tcp_appstate_t *app = &(uip_conn->appstate); GETrequest *req = (GETrequest*)app->request; if (uip_connected()) { TCP_client_connected = 1; // JM - indicate that an end point client connection is in progress TCP_new_connection = 1; // JM - indicate a new connection was made - cleared by application #ifdef DEBUG DebugPrintFO(f_ct); // Serial.print("-->Connected to "); DebugPrint((char *)(req->hostName)); #endif app->ackedCount = 0; sendRequest(); } // Did we get an ack for the last packet? if (uip_acked()) { // Record the bytes that were successfully sent app->ackedCount += app->sentCount; app->sentCount = 0; // Check if we're done or need to send more content for this // request if (app->ackedCount != (int)app->cursor) { // Generate the post again to send the next packet of data sendRequest(); } } if (uip_rexmit()) { sendRequest(); } if (uip_newdata()) { setRXPin(HIGH); #ifdef DEBUG DebugPrintFO(f_rx); // Serial.print("\n<--RX "); Serial.print(uip_datalen()); DebugPrintFO(f_bf); // Serial.print(" bytes from "); DebugPrint((char *)req->hostName); #endif // Check if the sketch cares about the returned data if ((req->returnFunc) && (uip_datalen() > 0)){ // Call the sketch's callback function req->returnFunc((char*)uip_appdata, uip_datalen()); } } if (uip_aborted() || uip_timedout() || uip_closed()) { if (req != NULL) { TCP_client_connected = 0; // JM end point connection no longer in progress TCP_connection_terminated = 1; // JM indicate a connection attempt or connection terminated #ifdef DEBUG DebugPrintFO(f_ec); DebugPrint((char *)req->hostName); #endif if (req->returnFunc) { // Call the sketch's callback function with 0 bytes to indicate End Of Data req->returnFunc((char*)uip_appdata, 0); } // Remove the request from the connection app->request = NULL; // Request is no longer active req->active = false; } } }
/* * Handles high-level server communications */ void server_task_impl() { // Get the connection's app state uip_tcp_appstate_t *app = &(uip_conn->appstate); if (uip_connected()) { if (verbose) { Serial.println("Server connected"); } // Initialize the server request data app->ackedCount = 0; app->request = NULL; } if (uip_newdata()) { setRXPin(HIGH); // Process the received packet and check if a valid GET request had been received if (processPacket((char*)uip_appdata, uip_datalen()) && app->request) { if (verbose) { Serial.print("Processing request for "); Serial.println((char*)app->request); } sendPage(); } } // Did we get an ack for the last packet? if (uip_acked()) { // Record the bytes that were successfully sent app->ackedCount += app->sentCount; app->sentCount = 0; // Check if we're done or need to send more content for this // request if (app->ackedCount == (int)app->cursor) { // Done with the current request and connection uip_close(); } else { // Generate the content again to send the next packet of data sendPage(); } } // Check if we need to retransmit if (uip_rexmit()) { // Send the same data again (same ackedCount value) sendPage(); } if (uip_aborted() || uip_closed() || uip_timedout()) { // Check if a URL was stored for this connection if (app->request != NULL) { if (verbose) { Serial.println("Server connection closed"); } // Free RAM and clear the pointer free(app->request); app->request = NULL; } } }
/* * Handles high-level server communications */ void server_task_impl() { // Get the connection's app state uip_tcp_appstate_t *app = &(uip_conn->appstate); if (uip_connected()) { #ifdef DEBUG DebugPrintF(f_sc); // JM "Server connected"; #endif // Initialize the server request data app->ackedCount = 0; app->request = NULL; } if (uip_newdata()) { setRXPin(HIGH); // Process the received packet and check if a valid GET request had been received if (processPacket((char*)uip_appdata, uip_datalen()) && app->request) { #ifdef DEBUG DebugPrintFO(f_prf); // JM "Processing request for "; DebugPrint((char*)app->request); #endif sendPage(); } } // Did we get an ack for the last packet? if (uip_acked()) { // Record the bytes that were successfully sent app->ackedCount += app->sentCount; app->sentCount = 0; // Check if we're done or need to send more content for this // request if (app->ackedCount == (int)app->cursor) { // Done with the current request and connection uip_close(); } else { // Generate the content again to send the next packet of data sendPage(); } } // Check if we need to retransmit if (uip_rexmit()) { // Send the same data again (same ackedCount value) sendPage(); } if (uip_aborted() || uip_closed() || uip_timedout()) { // Check if a URL was stored for this connection if (app->request != NULL) { #ifdef DEBUG DebugPrintF(f_scc); // "Server connection closed" #endif // Free RAM and clear the pointer // GregEigsti - jrwifi submitted WiServer stability fix // free(app->request); app->request = NULL; } } }