mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 17:43:02 +00:00
(Networking) Define isinprogress function
This commit is contained in:
parent
cb6b41e10f
commit
8f7b5a1050
@ -56,6 +56,16 @@
|
|||||||
|
|
||||||
#include <network.h>
|
#include <network.h>
|
||||||
|
|
||||||
|
#define sendto(s, msg, len, flags, addr, tolen) net_sendto(s, msg, len, 0, addr, 8)
|
||||||
|
#define socket(domain, type, protocol) net_socket(domain, type, protocol)
|
||||||
|
#define bind(s, name, namelen) net_bind(s, name, namelen)
|
||||||
|
#define listen(s, backlog) net_listen(s, backlog)
|
||||||
|
#define accept(s, addr, addrlen) net_accept(s, addr, addrlen)
|
||||||
|
#define connect(s, addr, addrlen) net_connect(s, addr, addrlen)
|
||||||
|
#define send(s, data, size, flags) net_send(s, data, size, flags)
|
||||||
|
#define recv(s, mem, len, flags) net_recv(s, mem, len, flags)
|
||||||
|
#define recvfrom(s, mem, len, flags, from, fromlen) net_recvfrom(s, mem, len, flags, from, fromlen)
|
||||||
|
#define select(maxfdp1, readset, writeset, exceptset, timeout) net_select(maxfdp1, readset, writeset, exceptset, timeout)
|
||||||
#define getsockopt net_getsockopt
|
#define getsockopt net_getsockopt
|
||||||
#define setsockopt net_setsockopt
|
#define setsockopt net_setsockopt
|
||||||
|
|
||||||
@ -132,35 +142,33 @@ struct SceNetInAddr inet_aton(const char *ip_addr);
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef GEKKO
|
|
||||||
#define sendto(s, msg, len, flags, addr, tolen) net_sendto(s, msg, len, 0, addr, 8)
|
|
||||||
#define socket(domain, type, protocol) net_socket(domain, type, protocol)
|
|
||||||
#define bind(s, name, namelen) net_bind(s, name, namelen)
|
|
||||||
#define listen(s, backlog) net_listen(s, backlog)
|
|
||||||
#define accept(s, addr, addrlen) net_accept(s, addr, addrlen)
|
|
||||||
#define connect(s, addr, addrlen) net_connect(s, addr, addrlen)
|
|
||||||
#define send(s, data, size, flags) net_send(s, data, size, flags)
|
|
||||||
#define recv(s, mem, len, flags) net_recv(s, mem, len, flags)
|
|
||||||
#define recvfrom(s, mem, len, flags, from, fromlen) net_recvfrom(s, mem, len, flags, from, fromlen)
|
|
||||||
#define select(maxfdp1, readset, writeset, exceptset, timeout) net_select(maxfdp1, readset, writeset, exceptset, timeout)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static INLINE bool isagain(int bytes)
|
static INLINE bool isagain(int bytes)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (bytes != SOCKET_ERROR)
|
return (bytes == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK);
|
||||||
return false;
|
|
||||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
#elif !defined(__PSL1GHT__) && defined(__PS3__)
|
#elif !defined(__PSL1GHT__) && defined(__PS3__)
|
||||||
return (sys_net_errno == SYS_NET_EWOULDBLOCK) || (sys_net_errno == SYS_NET_EAGAIN);
|
return (sys_net_errno == SYS_NET_EAGAIN) || (sys_net_errno == SYS_NET_EWOULDBLOCK);
|
||||||
#elif defined(VITA)
|
#elif defined(VITA)
|
||||||
return (bytes<0 && (bytes == SCE_NET_ERROR_EAGAIN || bytes == SCE_NET_ERROR_EWOULDBLOCK));
|
return (bytes == SCE_NET_ERROR_EAGAIN) || (bytes == SCE_NET_ERROR_EWOULDBLOCK);
|
||||||
#elif defined(WIIU)
|
#elif defined(WIIU)
|
||||||
return (bytes == -1) && ((socketlasterr() == SO_SUCCESS) || (socketlasterr() == SO_EWOULDBLOCK));
|
return (bytes == -1) && (socketlasterr() == SO_SUCCESS || socketlasterr() == SO_EWOULDBLOCK);
|
||||||
#else
|
#else
|
||||||
return (bytes < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
|
return (bytes < 0) && (errno == EAGAIN || errno == EWOULDBLOCK);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static INLINE bool isinprogress(int bytes)
|
||||||
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
return (bytes == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK);
|
||||||
|
#elif !defined(__PSL1GHT__) && defined(__PS3__)
|
||||||
|
return (sys_net_errno == SYS_NET_EINPROGRESS);
|
||||||
|
#elif defined(VITA)
|
||||||
|
return (bytes == SCE_NET_ERROR_EINPROGRESS);
|
||||||
|
#elif defined(WIIU)
|
||||||
|
return (bytes == -1) && (socketlasterr() == SO_SUCCESS || socketlasterr() == SO_EWOULDBLOCK);
|
||||||
|
#else
|
||||||
|
return (bytes < 0) && (errno == EINPROGRESS);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,10 +443,7 @@ bool socket_connect_with_timeout(int fd, void *data, unsigned timeout)
|
|||||||
fd_set wfd, efd;
|
fd_set wfd, efd;
|
||||||
struct timeval tv = {0};
|
struct timeval tv = {0};
|
||||||
|
|
||||||
if (!isagain(res))
|
if (!isinprogress(res) && !isagain(res))
|
||||||
#if !defined(_WIN32) && defined(EINPROGRESS)
|
|
||||||
if (errno != EINPROGRESS)
|
|
||||||
#endif
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
FD_ZERO(&wfd);
|
FD_ZERO(&wfd);
|
||||||
|
@ -3255,16 +3255,13 @@ static bool netplay_tunnel_connect(int fd, const struct addrinfo *addr)
|
|||||||
if (!socket_nonblock(fd))
|
if (!socket_nonblock(fd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
result = socket_connect(fd, (void*) addr, false);
|
|
||||||
if (result && !isagain(result))
|
|
||||||
#if !defined(_WIN32) && defined(EINPROGRESS)
|
|
||||||
if (errno != EINPROGRESS)
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SET_TCP_NODELAY(fd)
|
SET_TCP_NODELAY(fd)
|
||||||
SET_FD_CLOEXEC(fd)
|
SET_FD_CLOEXEC(fd)
|
||||||
|
|
||||||
|
result = socket_connect(fd, (void*) addr, false);
|
||||||
|
if (result && !isinprogress(result) && !isagain(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user