refactor(socket/mime): change function sign
This commit is contained in:
+4
-9
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user