So for anyone having this problem in the future. Thanks to Barmar I could solve the issue. If you want to read without error I use this
int read() {
std::vector<uint8_t> vector;
int temp = 0;
int read_status = 1;
memset(buffer, 0, sizeof(buffer));
while (true) {
read_status = recv(client_socket, buffer, sizeof(buffer) - 1, 0);
if (read_status == 0 || read_status == -1)
break;
for (int i = 0; i < read_status; i++)
vector.push_back(buffer[i]);
for (std::vector<uint8_t>::iterator it = vector.begin(); it != vector.end(); ++it)
request += *it;
vector.clear();
if (!body(request, temp, loop, boundary))
break;
temp++;
}
}
bool body(std::string request, int temp, bool &loop, std::string& boundary) {
bool found = false;
if (temp == 0) {
return true;
}
std::stringstream stream(request);
std::string line;
if (!loop) {
while (std::getline(stream, line)) {
if (line.find("boundary=") != std::string::npos) {
std::size_t pos = line.find("boundary=");
line.erase(0, pos + 9);
boundary = "--" + line;
boundary.erase(boundary.length() - 1, boundary.length());
if (boundary[boundary.length() + 1] == 10)
loop = true;
stream.clear();
line.clear();
break;
}
}
}
if (request.find(boundary + "--") != std::string::npos) {
return false;
}
if (boundary.length() == 0) {
if (request.find("\r\n\r\n") != std::string::npos) {
return false;
}
}
return true;
}
The body function only works with small buffersize. if you want a bigger buffer size, you have to make a check for the first iteration. I know that it is not cleanly written, but its just a prototype.