This commit is contained in:
2018-06-12 21:18:11 +02:00
parent 6c3e4c0ccd
commit 28e7df6485
3 changed files with 13 additions and 1 deletions

View File

@ -272,7 +272,7 @@ bool connection_handler(const char *preprefix, const char *col1, const char *col
if (req.getMethod() == "POST" || req.getMethod() == "PUT") {
long len = req.isExistingField("Content-Length") ? strtol(req.getField("Content-Length").c_str(), nullptr, 10) : -1;
socket->receive(pipes.stdin);
socket->receive(pipes.stdin, len);
}
fclose(pipes.stdin);

View File

@ -376,6 +376,17 @@ void Socket::receive(FILE *file) {
} while (len > 0 && len == CHUNK);
}
void Socket::receive(FILE *file, long size) {
char buffer[CHUNK];
long len = 0;
long rec = 0;
do {
len = receive((void*) buffer, (CHUNK > (size - rec) && size >= 0)?(size - rec):CHUNK);
fwrite(buffer, 1, CHUNK, file);
rec += len;
} while (len > 0 && size != len);
}
string Socket::receiveLine() {
string str = receive("\n");
if (str.length() > 0 && str.at(str.length() - 1) == '\r') {

View File

@ -149,6 +149,7 @@ public:
static long select(list<Socket> read, list<Socket> write);
void receive(FILE *file, long size);
};
Socket operator<<(Socket sock, const char *str);