(net_compat.c) Style nits

This commit is contained in:
twinaphex 2015-09-29 02:41:41 +02:00
parent 1974a3051d
commit 9b4a99d506
1 changed files with 64 additions and 66 deletions

View File

@ -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,23 +30,22 @@ 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;
@ -60,28 +60,22 @@ unsigned int inet_addr(const char *cp)
struct hostent *gethostbyname(const char *name) struct hostent *gethostbyname(const char *name)
{ {
int err;
static struct hostent ent; static struct hostent ent;
static char sname[MAX_NAME] = ""; static char sname[MAX_NAME] = "";
static struct SceNetInAddr saddr = { 0 }; static struct SceNetInAddr saddr = { 0 };
static char *addrlist[2] = { (char *) &saddr, NULL }; static char *addrlist[2] = { (char *) &saddr, NULL };
int rid; int rid = sceNetResolverCreate("resolver", NULL, 0);
int err;
rid = sceNetResolverCreate("resolver", NULL, 0);
if(rid < 0) if(rid < 0)
{
return NULL; return NULL;
}
err = sceNetResolverStartNtoa(rid, name, &saddr, 0,0,0); err = sceNetResolverStartNtoa(rid, name, &saddr, 0,0,0);
sceNetResolverDestroy(rid); sceNetResolverDestroy(rid);
if(err < 0) if(err < 0)
{
return NULL; return NULL;
}
addrlist[0]=inet_ntoa(saddr); addrlist[0] = inet_ntoa(saddr);
ent.h_name = sname; ent.h_name = sname;
ent.h_aliases = 0; ent.h_aliases = 0;
ent.h_addrtype = AF_INET; ent.h_addrtype = AF_INET;
@ -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)
int i = 0;
SceNetEpollEvent ev = {0}; SceNetEpollEvent ev = {0};
ev.events = PSP2_NET_EPOLLIN | PSP2_NET_EPOLLHUP; ev.events = PSP2_NET_EPOLLIN | PSP2_NET_EPOLLHUP;
ev.data.fd = nfds; ev.data.fd = nfds;
int i = 0; if((i = sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_ADD, nfds, &ev)))
if((i = sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_ADD, nfds, &ev))){ {
int ret = sceNetEpollWait(rarch_epoll_fd, &ev, 1, 0); int ret = sceNetEpollWait(rarch_epoll_fd, &ev, 1, 0);
sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_DEL, nfds, NULL); sceNetEpollControl(rarch_epoll_fd, PSP2_NET_EPOLL_CTL_DEL, nfds, NULL);
return ret; return ret;
}else{
return 0;
} }
return 0;
#else #else
return select(nfds, readfs, writefds, errorfds, timeout); return select(nfds, readfs, writefds, errorfds, timeout);
#endif #endif
@ -274,7 +268,8 @@ 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;
@ -286,7 +281,9 @@ bool network_init(void)
/* Init NetCtl */ /* Init NetCtl */
sceNetCtlInit(); sceNetCtlInit();
} else { }
else
{
//printf("Net is already initialized.\n"); //printf("Net is already initialized.\n");
} }
@ -316,7 +313,8 @@ void network_deinit(void)
sceNetCtlTerm(); sceNetCtlTerm();
sceNetTerm(); sceNetTerm();
if (_net_compat_net_memory) { if (_net_compat_net_memory)
{
free(_net_compat_net_memory); free(_net_compat_net_memory);
_net_compat_net_memory = NULL; _net_compat_net_memory = NULL;
} }