tass-belgium / picotcp-modules

Application level modules to run on top of the popular Embedded picoTCP TCP/IP stack
GNU General Public License v2.0
8 stars 11 forks source link

[HTTP server] in send_data, the client state is possibly incorrect #11

Open phalox opened 8 years ago

phalox commented 8 years ago

ref https://github.com/tass-belgium/picotcp-modules/blob/master/libhttp/pico_http_server.c#L867

void send_data(struct http_client _client) { uint16_t length; while (client->buffer_sent < client->buffer_size && (length = (uint16_t)pico_socket_write(client->sck, (uint8_t )client->buffer + client->buffer_sent, \ client->buffer_size - client->buffer_sent)) > 0 ) { client->buffer_sent = (uint16_t)(client->buffer_sent + length); server.wakeup(EV_HTTP_PROGRESS, client->connectionID); } if (client->buffer_sent == client->buffer_size && client->buffersize) { / send chunk trail _/ if (pico_socketwrite(client->sck, "\r\n", 2) > 0) { / free the buffer / if (client->state == HTTP_SENDING_DATA) { PICO_FREE(client->buffer); }

        client->buffer = NULL;

        //client->state = HTTP_WAIT_DATA;             << if you do that, for large static_data (HTTP_STATIC_RESOURCE), the memory will be allocated & copied on next line if server submit data....
        client->state = (client->state == HTTP_SENDING_DATA) ? HTTP_WAIT_DATA : HTTP_WAIT_STATIC_DATA;                                     << the code should have been like that
        server.wakeup(EV_HTTP_SENT, client->connectionID);
    }
}

}

phalox commented 8 years ago

@robbinvandamme Can you have a look at this?

robbinvandamme commented 8 years ago

Haven't been working on the server, so I won't be able to take a "quick look" at this.

phalox commented 8 years ago

@WimLeflere I believe you're the right person to talk to. Could you have a look at this suggestion to see if it makes sense?