diff --git a/src/dynamic_libs/socket_functions.c b/src/dynamic_libs/socket_functions.c index 8f72ced..07012e7 100644 --- a/src/dynamic_libs/socket_functions.c +++ b/src/dynamic_libs/socket_functions.c @@ -39,6 +39,8 @@ EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const s EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen); EXPORT_DECL(char *, inet_ntoa, struct in_addr in); EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp); +EXPORT_DECL(int*, get_h_errno, void); +EXPORT_DECL(const char*, gai_strerror, int); void InitSocketFunctionPointers(void) { @@ -70,6 +72,8 @@ void InitSocketFunctionPointers(void) OS_FIND_EXPORT(nsysnet_handle, setsockopt); OS_FIND_EXPORT(nsysnet_handle, inet_ntoa); OS_FIND_EXPORT(nsysnet_handle, inet_aton); + OS_FIND_EXPORT(nsysnet_handle, get_h_errno); + OS_FIND_EXPORT(nsysnet_handle, gai_strerror); unsigned int nn_startupid; ACInitialize(); diff --git a/src/dynamic_libs/socket_functions.h b/src/dynamic_libs/socket_functions.h index c051246..54d8ebc 100644 --- a/src/dynamic_libs/socket_functions.h +++ b/src/dynamic_libs/socket_functions.h @@ -48,6 +48,15 @@ extern "C" { #define SO_NONBLOCK 0x1016 #define SO_MYADDR 0x1013 +#define ENODATA 1 +#define EISCONN 3 +#define EWOULDBLOCK 6 +#define EALREADY 10 +#define EAGAIN EWOULDBLOCK +#define EINVAL 11 +#define ENOMEM 18 +#define EINPROGRESS 22 + #define htonl(x) x #define htons(x) x #define ntohl(x) x @@ -88,6 +97,11 @@ extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen extern char * (*inet_ntoa)(struct in_addr in); extern int (*inet_aton)(const char *cp, struct in_addr *inp); +extern int *(*get_h_errno)(void); +extern const char *(*gai_strerror)(int errno); // huh, gai o.O + +#define geterrno() (*(get_h_errno())) + #ifdef __cplusplus } #endif diff --git a/src/ftp.c b/src/ftp.c index 08638e6..64d023e 100644 --- a/src/ftp.c +++ b/src/ftp.c @@ -23,7 +23,6 @@ misrepresented as being the original software. 3.This notice may not be removed or altered from any source distribution. */ -#include #include #include #include @@ -32,11 +31,9 @@ misrepresented as being the original software. #include "dynamic_libs/os_functions.h" #include "dynamic_libs/socket_functions.h" -#undef EAGAIN -#define EAGAIN 1 - //! TODO: fix those function #define gettime() OSGetTick() +#define errno geterrno() #include "ftp.h" #include "virtualpath.h" @@ -391,7 +388,7 @@ static s32 prepare_data_connection(client_t *client, void *callback, void *arg, client->data_callback = callback; client->data_connection_callback_arg = arg; client->data_connection_cleanup = cleanup; - client->data_connection_timer = gettime() + SECS_TO_TICKS(30); + client->data_connection_timer = gettime() + SECS_TO_TICKS(10); } } return result; @@ -824,8 +821,8 @@ static void process_data_events(client_t *client) { } else { result = client->data_callback(client->data_socket, client->data_connection_callback_arg); } - // stupid mess up in nintys code EAGAIN is sometimes -1 (recv, should be -11) and sometimes -11 (send) - if (result <= 0 && result != -EAGAIN && result != -11) { + + if (result <= 0 && result != -EAGAIN) { cleanup_data_resources(client); if (result < 0) { result = write_reply(client, 520, "Closing data connection, error occurred during transfer."); diff --git a/src/net.c b/src/net.c index 00e15ce..5c1841f 100644 --- a/src/net.c +++ b/src/net.c @@ -21,7 +21,6 @@ misrepresented as being the original software. 3.This notice may not be removed or altered from any source distribution. */ -#include #include #include #include @@ -69,32 +68,62 @@ void initialise_network() { s32 network_socket(u32 domain,u32 type,u32 protocol) { - return socket(domain, type, protocol); + int sock = socket(domain, type, protocol); + if(sock < 0) + { + return -geterrno(); + } + return sock; } s32 network_bind(s32 s,struct sockaddr *name,s32 namelen) { - return bind(s, name, namelen); + int res = bind(s, name, namelen); + if(res < 0) + { + return -geterrno(); + } + return res; } s32 network_listen(s32 s,u32 backlog) { - return listen(s, backlog); + int res = listen(s, backlog); + if(res < 0) + { + return -geterrno(); + } + return res; } s32 network_accept(s32 s,struct sockaddr *addr,s32 *addrlen) { - return accept(s, addr, addrlen); + int res = accept(s, addr, addrlen); + if(res < 0) + { + return -geterrno(); + } + return res; } s32 network_connect(s32 s,struct sockaddr *addr, s32 addrlen) { - return connect(s, addr, addrlen); + int res = connect(s, addr, addrlen); + if(res < 0) + { + return -geterrno(); + } + return res; } s32 network_read(s32 s,void *mem,s32 len) { - return recv(s, mem, len, 0); + int res = recv(s, mem, len, 0); + if(res < 0) + { + return -geterrno(); + } + return res; } u32 network_gethostip() @@ -111,7 +140,7 @@ s32 network_write(s32 s, const void *mem,s32 len) int ret = send(s, mem, len, 0); if(ret < 0) { - transfered = ret; + transfered = -geterrno(); break; } @@ -132,7 +161,6 @@ s32 network_close(s32 s) s32 set_blocking(s32 s, bool blocking) { s32 block = !blocking; - setsockopt(s, SOL_SOCKET, SO_NONBLOCK, &block, sizeof(block)); return 0; } diff --git a/src/utils/logger.c b/src/utils/logger.c index f4795b4..86dd652 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -2,7 +2,6 @@ #include #include #include -#include #include "common/common.h" #include "dynamic_libs/os_functions.h" #include "dynamic_libs/socket_functions.h"