diff options
Diffstat (limited to 'src/request.c')
| -rw-r--r-- | src/request.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/request.c b/src/request.c index a0e1358..93d2421 100644 --- a/src/request.c +++ b/src/request.c @@ -4,6 +4,9 @@ #include <stddef.h> #include <string.h> +#include <sys/socket.h> +#include <sys/types.h> + struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_buf, char *buf) { @@ -93,6 +96,32 @@ struct LibHTTPC_Request *LibHTTPC_loadRequest(struct LibHTTPC_Request *request_b return request_buf; } +#ifdef LibHTTPC_SOCK +struct LibHTTPC_Request *LibHTTPC_readRequest( + int sockfd, + struct LibHTTPC_Request *request_buf, + char *buf, size_t buf_len +) +{ + if (!buf) + { + /* TODO: Implement behavior when buf == NULL */ + return NULL; + } else + { + if (!buf_len) + return NULL; + + ssize_t received = recv(sockfd, buf, buf_len, 0); + if (received < 0) + return NULL; + buf[buf_len - 1] = '\0'; + + return LibHTTPC_loadRequest(request_buf, buf); + } +} +#endif + int LibHTTPC_Request_(struct LibHTTPC_Request *request) { if (!LibHTTPC_free) |