Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HTTPClient by
Diff: data/HTTPFile.cpp
- Revision:
- 27:32a53068ce03
- Parent:
- 25:76084defa790
- Child:
- 29:9ee96efc1c20
diff -r 58b6fe9f596b -r 32a53068ce03 data/HTTPFile.cpp --- a/data/HTTPFile.cpp Sun Apr 20 17:05:27 2014 +0000 +++ b/data/HTTPFile.cpp Sat Apr 26 17:24:07 2014 +0000 @@ -1,25 +1,48 @@ #include "HTTPFile.h" -#if 1 + +#define DEBUG "HTfi" +#include <cstdio> +#if (defined(DEBUG) && !defined(TARGET_LPC11U24)) +#define DBG(x, ...) std::printf("[DBG %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#else +#define DBG(x, ...) +#define WARN(x, ...) +#define ERR(x, ...) +#define INFO(x, ...) +#endif + HTTPFile::HTTPFile(char* filename) { - file = fopen(filename, "w"); + INFO("HTTPFile %s", filename); + file = fopen(filename, "w"); + m_chunked = false; } void HTTPFile::close() { + INFO("close()"); if (file) { - fclose(file); + fclose(file); + file = NULL; } } void HTTPFile::writeReset() { + INFO("writeReset()"); if (file) { rewind(file); } } int HTTPFile::write(const char* buf, size_t len) { + size_t written; + INFO("write(%d,%s) m_len(%d), chunk %d", len, buf, m_len, m_chunked); if (file) { - len = fwrite(&buf, 1, len, file); - if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !len)) { + written = fwrite(&buf, 1, len, file); + INFO(" writ:%d, ftell: %d", written, ftell(file)); + if ((!m_chunked && (ftell(file) >= m_len)) || (m_chunked && !written)) { + INFO("closing"); close(); } } @@ -27,7 +50,7 @@ } void HTTPFile::setDataType(const char* type) { - + INFO("setDataType(%s)", type); } //void HTTPFile::setLocation(const char * location) { @@ -35,10 +58,11 @@ //} void HTTPFile::setIsChunked(bool chunked) { + INFO("setIsChunked(%d)", chunked); m_chunked = chunked; } void HTTPFile::setDataLen(size_t len) { + INFO("setDataLen(%d)", len); m_len = len; } -#endif \ No newline at end of file