Commit 0a1c3efe authored by Mathias Haage's avatar Mathias Haage
Browse files

Update write_string

parent f95ad612
......@@ -147,9 +147,25 @@ int try_get_frame(struct client* client)
int client_write_string(struct client* client)
{
return write(client->connfd, client->sendBuff, strlen(client->sendBuff));
size_t n = strlen(client->sendBuff);
size_t written = 0;
while (written < n) {
ssize_t tmp = write(client->connfd, client->sendBuff, n-written);
if (tmp < 0) {
perror("writen ERROR");
return tmp;
}
written += tmp;
}
return written;
}
/*
* Returns number of bytes written.
* Returns -1 if an error occurs and sets errno.
* Note: an error occurs if the web browser closes the connection
* (might happen when reloading too frequently)
*/
int client_writen(struct client* client, size_t n)
{
size_t written = 0;
......@@ -210,7 +226,9 @@ void* serve_client(void *ctxt)
const char* msg = "501: Not implemented";
snprintf(client->sendBuff, sizeof(client->sendBuff), "HTTP/1.0 501 Not Implemented\nContent-Length: %d\nContent-Type: text/plain\n\n%s",strlen(msg), msg);
}
#ifndef USE_CAMERA
client_write_string(client);
#endif
return (void*) close(client->connfd);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment