lwip-users
[Top][All Lists]
Advanced

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

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


From: Michał
Subject: Re: [lwip-users] Sending large files over netconn and TCP
Date: Tue, 12 Jul 2016 12:33:07 +0200
User-agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Hello,
It was a problem with too many requests to TCP/IP thread, to prevent this situation you need to check that the previous "chunk" was already sended.

My solution:

#define BUFFER_OUT                64000
static BYTE archDownBuffer[BUFFER_OUT] __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 (;;)
        {
            if(conn->state == NETCONN_NONE) // check the state
            {
                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_MORE, &written);
                if (test != ERR_OK) break; /* error or disk full */
                if (written != archDownCounter) break;
                vTaskDelay(150); //time for other tasks
            }
        }


        f_close(&arch_file);
    }
}

Regards,
Michał Gołębiowski

reply via email to

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