lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Sending large files over netconn and TCP


From: Michał
Subject: [lwip-users] Sending large files over netconn and TCP
Date: Thu, 7 Jul 2016 15:45:27 +0200
User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1

Hello,
I have a website on LwIP with list of files with possibility to download them. I'm using function:

#define BUFFER_OUT                16000
static BYTE archDownBuffer[BUFFER_OUT] __attribute__ ((section(".sdram")));
char archive_page[WEBSITE_BUFFER] __attribute__ ((section(".sdram")));
static BYTE respond[110];
UINT archDownCounter, sentCounter;
FIL arch_file;

void archive_download(struct netconn *conn, const char* filepath)
{

    FRESULT res;
    archDownCounter = 0;
    sentCounter = 0;
    size_t written;
    int cx;
    err_t test;
    res = f_open(&arch_file, filepath, FA_READ);

    if (res == FR_OK)
    {
        cx =
                snprintf(archDownBuffer, BUFFER_OUT,
                        "HTTP/1.1 200 OK \r\nContent-Type: file/csv\r\nContent-Length: %lu\r\n\r\n",
                        arch_file.fsize);

        netconn_write(conn, (const char* )(archDownBuffer), (size_t )cx, NETCONN_NOCOPY);

        for (;;)
        {
            res = f_read(&arch_file, archDownBuffer, sizeof archDownBuffer, &archDownCounter); /* Read a chunk of source file */
            if (res || archDownCounter == 0)
                break; /* error or eof */
            test = netconn_write_partly(conn, (const char*) (archDownBuffer), (size_t) archDownCounter, NETCONN_NOCOPY, &written);

            if (test != ERR_OK) break; /* error or disk full */
            if (written != archDownCounter) break;

            vTaskDelay(40); //time for other tasks
        }

        f_close(&arch_file);
    }
}

to send them to a browser but after a couple of iterations the loop and whole stack freezes and LwIP stops working.
With really small vTaskDelay and large BUFFER_OUT there is possibility of Hard Fault pointing to lwip_netconn_do_writemore.

Is there any better method to send large files by netconn?

Regards,
Michal Golebiowski

reply via email to

[Prev in Thread] Current Thread [Next in Thread]