(net_compat.c) Style nits
This commit is contained in:
parent
1974a3051d
commit
9b4a99d506
|
@ -20,6 +20,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <net/net_compat.h>
|
#include <net/net_compat.h>
|
||||||
|
#include <compat/strl.h>
|
||||||
|
|
||||||
#if defined(VITA)
|
#if defined(VITA)
|
||||||
static void *_net_compat_net_memory = NULL;
|
static void *_net_compat_net_memory = NULL;
|
||||||
|
@ -29,67 +30,60 @@ static void *_net_compat_net_memory = NULL;
|
||||||
|
|
||||||
typedef uint32_t in_addr_t;
|
typedef uint32_t in_addr_t;
|
||||||
|
|
||||||
struct in_addr {
|
struct in_addr
|
||||||
|
{
|
||||||
in_addr_t s_addr;
|
in_addr_t s_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
char *inet_ntoa(struct SceNetInAddr in)
|
char *inet_ntoa(struct SceNetInAddr in)
|
||||||
{
|
{
|
||||||
static char ip_addr[INET_ADDRSTRLEN+1];
|
static char ip_addr[INET_ADDRSTRLEN + 1];
|
||||||
|
|
||||||
if(sceNetInetNtop(AF_INET, &in, ip_addr, INET_ADDRSTRLEN) == NULL)
|
if(sceNetInetNtop(AF_INET, &in, ip_addr, INET_ADDRSTRLEN) == NULL)
|
||||||
{
|
strlcpy(ip_addr, "Invalid", sizeof(ip_addr));
|
||||||
strcpy(ip_addr, "Invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
return ip_addr;
|
return ip_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SceNetInAddr inet_aton(const char * ip_addr)
|
struct SceNetInAddr inet_aton(const char *ip_addr)
|
||||||
{
|
{
|
||||||
SceNetInAddr inaddr;
|
SceNetInAddr inaddr;
|
||||||
|
|
||||||
sceNetInetPton(AF_INET, ip_addr, &inaddr);
|
sceNetInetPton(AF_INET, ip_addr, &inaddr);
|
||||||
return inaddr;
|
return inaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int inet_addr(const char *cp)
|
unsigned int inet_addr(const char *cp)
|
||||||
{
|
{
|
||||||
return inet_aton(cp).s_addr;
|
return inet_aton(cp).s_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hostent *gethostbyname(const char *name)
|
struct hostent *gethostbyname(const char *name)
|
||||||
{
|
{
|
||||||
static struct hostent ent;
|
int err;
|
||||||
static char sname[MAX_NAME] = "";
|
static struct hostent ent;
|
||||||
static struct SceNetInAddr saddr = { 0 };
|
static char sname[MAX_NAME] = "";
|
||||||
static char *addrlist[2] = { (char *) &saddr, NULL };
|
static struct SceNetInAddr saddr = { 0 };
|
||||||
int rid;
|
static char *addrlist[2] = { (char *) &saddr, NULL };
|
||||||
|
int rid = sceNetResolverCreate("resolver", NULL, 0);
|
||||||
|
|
||||||
|
if(rid < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
int err;
|
err = sceNetResolverStartNtoa(rid, name, &saddr, 0,0,0);
|
||||||
rid = sceNetResolverCreate("resolver", NULL, 0);
|
sceNetResolverDestroy(rid);
|
||||||
if(rid < 0)
|
if(err < 0)
|
||||||
{
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = sceNetResolverStartNtoa(rid, name, &saddr, 0,0,0);
|
addrlist[0] = inet_ntoa(saddr);
|
||||||
sceNetResolverDestroy(rid);
|
ent.h_name = sname;
|
||||||
if(err < 0)
|
ent.h_aliases = 0;
|
||||||
{
|
ent.h_addrtype = AF_INET;
|
||||||
return NULL;
|
ent.h_length = sizeof(struct in_addr);
|
||||||
}
|
ent.h_addr_list = addrlist;
|
||||||
|
ent.h_addr = addrlist[0];
|
||||||
|
|
||||||
addrlist[0]=inet_ntoa(saddr);
|
return &ent;
|
||||||
ent.h_name = sname;
|
|
||||||
ent.h_aliases = 0;
|
|
||||||
ent.h_addrtype = AF_INET;
|
|
||||||
ent.h_length = sizeof(struct in_addr);
|
|
||||||
ent.h_addr_list = addrlist;
|
|
||||||
ent.h_addr = addrlist[0];
|
|
||||||
|
|
||||||
return &ent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int rarch_epoll_fd;
|
int rarch_epoll_fd;
|
||||||
|
@ -194,19 +188,19 @@ int socket_select(int nfds, fd_set *readfs, fd_set *writefds,
|
||||||
#if defined(__CELLOS_LV2__)
|
#if defined(__CELLOS_LV2__)
|
||||||
return socketselect(nfds, readfs, writefds, errorfds, timeout);
|
return socketselect(nfds, readfs, writefds, errorfds, timeout);
|
||||||
#elif defined(VITA)
|
#elif defined(VITA)
|
||||||
SceNetEpollEvent ev = {0};
|
int i = 0;
|
||||||
ev.events = PSP2_NET_EPOLLIN | PSP2_NET_EPOLLHUP;
|
SceNetEpollEvent ev = {0};
|
||||||
ev.data.fd = nfds;
|
|
||||||
|
|
||||||
int i = 0;
|
ev.events = PSP2_NET_EPOLLIN | PSP2_NET_EPOLLHUP;
|
||||||
if((i = sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_ADD, nfds, &ev))){
|
ev.data.fd = nfds;
|
||||||
int ret = sceNetEpollWait(rarch_epoll_fd, &ev, 1, 0);
|
|
||||||
sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_DEL, nfds, NULL);
|
if((i = sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_ADD, nfds, &ev)))
|
||||||
return ret;
|
{
|
||||||
}else{
|
int ret = sceNetEpollWait(rarch_epoll_fd, &ev, 1, 0);
|
||||||
return 0;
|
sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_DEL, nfds, NULL);
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
return select(nfds, readfs, writefds, errorfds, timeout);
|
return select(nfds, readfs, writefds, errorfds, timeout);
|
||||||
#endif
|
#endif
|
||||||
|
@ -274,20 +268,23 @@ bool network_init(void)
|
||||||
#elif defined(VITA)
|
#elif defined(VITA)
|
||||||
SceNetInitParam initparam;
|
SceNetInitParam initparam;
|
||||||
/* Init Net */
|
/* Init Net */
|
||||||
if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT) {
|
if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT)
|
||||||
_net_compat_net_memory = malloc(COMPAT_NET_INIT_SIZE);
|
{
|
||||||
|
_net_compat_net_memory = malloc(COMPAT_NET_INIT_SIZE);
|
||||||
|
|
||||||
initparam.memory = _net_compat_net_memory;
|
initparam.memory = _net_compat_net_memory;
|
||||||
initparam.size = COMPAT_NET_INIT_SIZE;
|
initparam.size = COMPAT_NET_INIT_SIZE;
|
||||||
initparam.flags = 0;
|
initparam.flags = 0;
|
||||||
|
|
||||||
sceNetInit(&initparam);
|
sceNetInit(&initparam);
|
||||||
//printf("sceNetInit(): 0x%08X\n", ret);
|
//printf("sceNetInit(): 0x%08X\n", ret);
|
||||||
|
|
||||||
/* Init NetCtl */
|
/* Init NetCtl */
|
||||||
sceNetCtlInit();
|
sceNetCtlInit();
|
||||||
} else {
|
}
|
||||||
//printf("Net is already initialized.\n");
|
else
|
||||||
|
{
|
||||||
|
//printf("Net is already initialized.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
rarch_epoll_fd = sceNetEpollCreate("epoll", 0);
|
rarch_epoll_fd = sceNetEpollCreate("epoll", 0);
|
||||||
|
@ -313,12 +310,13 @@ void network_deinit(void)
|
||||||
sys_net_finalize_network();
|
sys_net_finalize_network();
|
||||||
cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
|
cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
|
||||||
#elif defined(VITA)
|
#elif defined(VITA)
|
||||||
sceNetCtlTerm();
|
sceNetCtlTerm();
|
||||||
sceNetTerm();
|
sceNetTerm();
|
||||||
|
|
||||||
if (_net_compat_net_memory) {
|
if (_net_compat_net_memory)
|
||||||
free(_net_compat_net_memory);
|
{
|
||||||
_net_compat_net_memory = NULL;
|
free(_net_compat_net_memory);
|
||||||
}
|
_net_compat_net_memory = NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue