mirror of
https://github.com/libretro/RetroArch
synced 2025-03-20 01:21:03 +00:00
Merge pull request #13991 from Cthulhu-throwaway/isinprogress
(Networking) Define isinprogress function
This commit is contained in:
commit
e470461b14
@ -56,6 +56,16 @@
|
||||
|
||||
#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 setsockopt net_setsockopt
|
||||
|
||||
@ -132,35 +142,33 @@ struct SceNetInAddr inet_aton(const char *ip_addr);
|
||||
|
||||
#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)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if (bytes != SOCKET_ERROR)
|
||||
return false;
|
||||
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
||||
return false;
|
||||
return true;
|
||||
return (bytes == SOCKET_ERROR) && (WSAGetLastError() == WSAEWOULDBLOCK);
|
||||
#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)
|
||||
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)
|
||||
return (bytes == -1) && ((socketlasterr() == SO_SUCCESS) || (socketlasterr() == SO_EWOULDBLOCK));
|
||||
return (bytes == -1) && (socketlasterr() == SO_SUCCESS || socketlasterr() == SO_EWOULDBLOCK);
|
||||
#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
|
||||
}
|
||||
|
||||
|
@ -443,10 +443,7 @@ bool socket_connect_with_timeout(int fd, void *data, unsigned timeout)
|
||||
fd_set wfd, efd;
|
||||
struct timeval tv = {0};
|
||||
|
||||
if (!isagain(res))
|
||||
#if !defined(_WIN32) && defined(EINPROGRESS)
|
||||
if (errno != EINPROGRESS)
|
||||
#endif
|
||||
if (!isinprogress(res) && !isagain(res))
|
||||
return false;
|
||||
|
||||
FD_ZERO(&wfd);
|
||||
@ -460,7 +457,7 @@ bool socket_connect_with_timeout(int fd, void *data, unsigned timeout)
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SO_ERROR
|
||||
#if !defined(GEKKO) && defined(SO_ERROR)
|
||||
{
|
||||
int error = -1;
|
||||
socklen_t errsz = sizeof(error);
|
||||
|
@ -3255,16 +3255,13 @@ static bool netplay_tunnel_connect(int fd, const struct addrinfo *addr)
|
||||
if (!socket_nonblock(fd))
|
||||
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_FD_CLOEXEC(fd)
|
||||
|
||||
result = socket_connect(fd, (void*) addr, false);
|
||||
if (result && !isinprogress(result) && !isagain(result))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user