refactor(socket/mime): change function sign
This commit is contained in:
@@ -3,21 +3,18 @@
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
size_t cws_socket_read(int sockfd, string_s *str) {
|
||||
ssize_t cws_socket_read(int sockfd, string_s *str) {
|
||||
char tmp[4096] = {0};
|
||||
|
||||
size_t n = recv(sockfd, tmp, sizeof tmp, 0);
|
||||
ssize_t n = recv(sockfd, tmp, sizeof tmp, 0);
|
||||
if (n < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
/* No data available right now */
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (n == 0) {
|
||||
/* Connection closed */
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -26,19 +23,17 @@ size_t cws_socket_read(int sockfd, string_s *str) {
|
||||
return n;
|
||||
}
|
||||
|
||||
size_t cws_socket_send(int sockfd, char *buffer, size_t len, int flags) {
|
||||
ssize_t cws_socket_send(int sockfd, const char *buffer, size_t len, int flags) {
|
||||
size_t total_sent = 0;
|
||||
size_t n;
|
||||
ssize_t n;
|
||||
|
||||
while (total_sent < len) {
|
||||
n = send(sockfd, buffer + total_sent, len - total_sent, flags);
|
||||
|
||||
if (n < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
/* Buffer full, return bytes sent */
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ static mimetype mimetypes[] = {{"html", "text/html"}, {"css", "text/css"}, {"js"
|
||||
{"jpg", "image/jpeg"}, {"png", "image/png"}, {"ico", "image/x-icon"}};
|
||||
|
||||
int cws_mime_get_ct(const char *location_path, char *content_type) {
|
||||
/* Find last occurrence of a string */
|
||||
char *ptr = strrchr(location_path, '.');
|
||||
if (ptr == NULL) {
|
||||
return CWS_CONTENT_TYPE_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user