Skip to content

Commit

Permalink
"Added some more libnet specific functions & added a config macro to …
Browse files Browse the repository at this point in the history
…switch between lv2/sprx sockets"
  • Loading branch information
stoneMcClane authored and stoneMcClane committed Nov 20, 2010
1 parent 1d93eff commit b28e37a
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 77 deletions.
52 changes: 35 additions & 17 deletions psl1ght/include/net/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,48 @@
#include <psl1ght/types.h>
#include <sys/types.h>
#include <stdlib.h>
#include <netinet/in.h>

typedef struct sys_net_initialize_parameter {
void *memory;
int memory_size;
int flags;
} sys_net_initialize_parameter_t;
#define libnet_errno *_net_errno_loc()

//#define sys_net_errno (*_sys_net_errno_loc())

#define libnet_errno *_sys_net_errno_loc()

EXTERN_BEGIN

#define sys_net_initialize_network() ({ \
#define net_initialize_network() ({ \
static char __libnet_memory[128 * 1024]; \
sys_net_initialize_parameter_t __libnet_param; \
__libnet_param.memory = __libnet_memory; \
net_init_param_t __libnet_param; \
__libnet_param.memory = (u32)(u64)&__libnet_memory; \
__libnet_param.memory_size = sizeof(__libnet_memory); \
__libnet_param.flags = 0; \
sys_net_initialize_network_ex(&__libnet_param); \
net_initialize_network_ex(&__libnet_param); \
})

int sys_net_initialize_network_ex(sys_net_initialize_parameter_t *param);
typedef struct net_init_param {
u32 memory;
s32 memory_size;
s32 flags;
} net_init_param_t;

typedef struct net_sockinfo {
s32 s;
s32 proto;
s32 recv_queue_len;
s32 send_queue_len;
struct in_addr local_adr;
s32 local_port;
struct in_addr remote_adr;
s32 remote_port;
s32 state;
} net_sockinfo_t;

EXTERN_BEGIN

s32* _net_errno_loc(void);

s32 socketclose(s32 s);

s32* _sys_net_errno_loc(void);
s32 net_finalize_network();
s32 net_get_sockinfo(s32 s, net_sockinfo_t* p, s32 n);
s32 net_initialize_network_ex(net_init_param_t* param);
s32 net_show_ifconfig();
s32 net_show_nameserver();
s32 net_show_route();

EXTERN_END
4 changes: 4 additions & 0 deletions psl1ght/include/net/net_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

// enable/disable usage of libnet SRPX socket functions instead of Lv2 syscalls
#define USE_LIBNET_SPRX
5 changes: 5 additions & 0 deletions psl1ght/include/sys/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <psl1ght/types.h>
#include <sys/types.h>
#include <net/net_config.h>

typedef u64 socklen_t;
typedef u8 sa_family_t;
Expand Down Expand Up @@ -43,6 +44,10 @@ struct linger
int l_linger;
};

#ifdef USE_LIBNET_SPRX
#include <net/net.h>
#endif

#define SOCK_STREAM 0x0001
#define SOCK_DGRAM 0x0002
#define SOCK_RAW 0x0003
Expand Down
1 change: 1 addition & 0 deletions psl1ght/include/sysmodule/sysmodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ EXTERN_BEGIN
typedef enum
{
SYSMODULE_NET=0,
SYSMODULE_HTTP=1,

SYSMODULE_RTC=9,

Expand Down
6 changes: 6 additions & 0 deletions psl1ght/libc-glue-ppu/source/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ int ftruncate(int fd, off_t length)
int net_close(int fd);
int close(int fd)
{
#ifndef USE_LIBNET_SPRX
if (fd & SOCKET_FD_MASK)
return net_close(fd);
#endif

return lv2Errno(lv2FsClose(fd));
}
Expand All @@ -81,8 +83,10 @@ int unlink(const char* path)

ssize_t write(int fd, const void* buffer, size_t size)
{
#ifndef USE_LIBNET_SPRX
if (fd & SOCKET_FD_MASK)
return send(fd, buffer, size, 0);
#endif

u64 written;
int ret;
Expand All @@ -99,8 +103,10 @@ ssize_t write(int fd, const void* buffer, size_t size)

ssize_t read(int fd, void* buffer, size_t size)
{
#ifndef USE_LIBNET_SPRX
if (fd & SOCKET_FD_MASK)
return recv(fd, buffer, size, 0);
#endif

u64 bytes;
int ret;
Expand Down
4 changes: 4 additions & 0 deletions psl1ght/libc-glue-ppu/source/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ int h_errno = 0;

#define FD(socket) (socket & ~SOCKET_FD_MASK)

#ifndef USE_LIBNET_SPRX

int accept(int socket, const struct sockaddr* address, socklen_t* address_len) {
s32 ret = lv2NetAccept(FD(socket), address, (lv2_socklen_t *)address_len);
if (ret < 0)
Expand Down Expand Up @@ -107,3 +109,5 @@ int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* errorfds, struct
errno = ENOSYS;
return -1;
}

#endif
5 changes: 2 additions & 3 deletions psl1ght/sprx/libnet/config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include <net/net_config.h>

#define LIBRARY_NAME "sys_net"
#define LIBRARY_SYMBOL sys_net
#define LIBRARY_HEADER sys_net_header

#define LIBRARY_HEADER_1 0x2c000001
#define LIBRARY_HEADER_2 0x0009

#define USE_LIBNET_SPRX

110 changes: 55 additions & 55 deletions psl1ght/sprx/libnet/exports.h
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
#ifdef USE_LIBNET_SPRX

EXPORT(_sys_net_errno_loc, 0x6005cde1);
EXPORT(_sys_net_h_errno_loc, 0xc9157d30);
EXPORT(accept, 0xc94f6939);
EXPORT(bind, 0xb0a59804);
EXPORT(connect, 0x64f66d35);
EXPORT(gethostbyaddr, 0xf7ac8941);
EXPORT(gethostbyname, 0x71f4c717);
EXPORT(getpeername, 0xf9ec2db6);
EXPORT(getsockname, 0x13efe7f5);
EXPORT(getsockopt, 0x5a045bd1);
EXPORT(inet_addr, 0xdabbc2c0);
EXPORT(inet_aton, 0xa9a079e0);
EXPORT(inet_lnaof, 0x566893ce);
EXPORT(inet_makeaddr, 0xb4152c74);
EXPORT(inet_netof, 0xe39a62a7);
EXPORT(inet_network, 0x506ad863);
EXPORT(inet_ntoa, 0x858a930b);
EXPORT(inet_ntop, 0xc98a3146);
EXPORT(inet_pton, 0x8af3825e);
EXPORT(listen, 0x28e208bb);
EXPORT(recv, 0xfba04f37);
EXPORT(recvfrom, 0x1f953b9f);
EXPORT(recvmsg, 0xc9d09c34);
EXPORT(send, 0xdc751b40);
EXPORT(sendmsg, 0xad09481b);
EXPORT(sendto, 0x9647570b);
EXPORT(setsockopt, 0x88f03575);
EXPORT(shutdown, 0xa50777c6);
EXPORT(socket, 0x9c056962);
EXPORT(socketclose, 0x6db6e8cd);
EXPORT(socketpoll, 0x051ee3ee);
EXPORT(socketselect, 0x3f09e20a);
EXPORT(sys_net_abort_resolver, 0x8ccf05ed);
EXPORT(sys_net_abort_socket, 0x8d1b77fb);
EXPORT(sys_net_close_dump, 0x44328aa2);
EXPORT(sys_net_finalize_network, 0xb68d5625);
EXPORT(sys_net_free_thread_context, 0xfdb8f926);
EXPORT(sys_net_get_lib_name_server, 0x1d14d6e4);
EXPORT(sys_net_get_netemu_test_param, 0x368823c0);
EXPORT(sys_net_get_sockinfo, 0x3b27c780);
EXPORT(sys_net_get_sockinfo_ex, 0xa765d029);
EXPORT(sys_net_get_test_param, 0xa5a86557);
EXPORT(sys_net_get_udpp2p_test_param, 0x05bd4438);
EXPORT(sys_net_if_ctl, 0x27fb339d);
EXPORT(sys_net_initialize_network_ex, 0x139a9e9b);
EXPORT(sys_net_open_dump, 0xab447704);
EXPORT(sys_net_read_dump, 0x89c9917c);
EXPORT(sys_net_set_lib_name_server, 0x9a318259);
EXPORT(sys_net_set_netemu_test_param, 0xe2434507);
EXPORT(sys_net_set_resolver_configurations, 0x7687d48c);
EXPORT(sys_net_set_test_param, 0x4ab0b9b9);
EXPORT(sys_net_set_udpp2p_test_param, 0x10b81ed6);
EXPORT(sys_net_show_ifconfig, 0xb48636c4);
EXPORT(sys_net_show_nameserver, 0x5420e419);
EXPORT(sys_net_show_route, 0x79b61646);
EXPORT(_net_errno_loc, 0x6005cde1);
EXPORT(_net_h_errno_loc, 0xc9157d30);
EXPORT(accept, 0xc94f6939);
EXPORT(bind, 0xb0a59804);
EXPORT(connect, 0x64f66d35);
EXPORT(gethostbyaddr, 0xf7ac8941);
EXPORT(gethostbyname, 0x71f4c717);
EXPORT(getpeername, 0xf9ec2db6);
EXPORT(getsockname, 0x13efe7f5);
EXPORT(getsockopt, 0x5a045bd1);
EXPORT(inet_addr, 0xdabbc2c0);
EXPORT(inet_aton, 0xa9a079e0);
EXPORT(inet_lnaof, 0x566893ce);
EXPORT(inet_makeaddr, 0xb4152c74);
EXPORT(inet_netof, 0xe39a62a7);
EXPORT(inet_network, 0x506ad863);
EXPORT(inet_ntoa, 0x858a930b);
EXPORT(inet_ntop, 0xc98a3146);
EXPORT(inet_pton, 0x8af3825e);
EXPORT(listen, 0x28e208bb);
EXPORT(recv, 0xfba04f37);
EXPORT(recvfrom, 0x1f953b9f);
EXPORT(recvmsg, 0xc9d09c34);
EXPORT(send, 0xdc751b40);
EXPORT(sendmsg, 0xad09481b);
EXPORT(sendto, 0x9647570b);
EXPORT(setsockopt, 0x88f03575);
EXPORT(shutdown, 0xa50777c6);
EXPORT(socket, 0x9c056962);
EXPORT(socketclose, 0x6db6e8cd);
EXPORT(socketpoll, 0x051ee3ee);
EXPORT(socketselect, 0x3f09e20a);
EXPORT(net_abort_resolver, 0x8ccf05ed);
EXPORT(net_abort_socket, 0x8d1b77fb);
EXPORT(net_close_dump, 0x44328aa2);
EXPORT(net_finalize_network, 0xb68d5625);
EXPORT(net_free_thread_context, 0xfdb8f926);
EXPORT(net_get_lib_name_server, 0x1d14d6e4);
EXPORT(net_get_netemu_test_param, 0x368823c0);
EXPORT(net_get_sockinfo, 0x3b27c780);
EXPORT(net_get_sockinfo_ex, 0xa765d029);
EXPORT(net_get_test_param, 0xa5a86557);
EXPORT(net_get_udpp2p_test_param, 0x05bd4438);
EXPORT(net_if_ctl, 0x27fb339d);
EXPORT(net_initialize_network_ex, 0x139a9e9b);
EXPORT(net_open_dump, 0xab447704);
EXPORT(net_read_dump, 0x89c9917c);
EXPORT(net_set_lib_name_server, 0x9a318259);
EXPORT(net_set_netemu_test_param, 0xe2434507);
EXPORT(net_set_resolver_configurations, 0x7687d48c);
EXPORT(net_set_test_param, 0x4ab0b9b9);
EXPORT(net_set_udpp2p_test_param, 0x10b81ed6);
EXPORT(net_show_ifconfig, 0xb48636c4);
EXPORT(net_show_nameserver, 0x5420e419);
EXPORT(net_show_route, 0x79b61646);

#endif
Empty file modified psl1ght/tools/PS3Py/fself.py
100755 → 100644
Empty file.
Empty file modified psl1ght/tools/PS3Py/pkg.py
100755 → 100644
Empty file.
Empty file modified psl1ght/tools/PS3Py/sfo.py
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion samples/echoserv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ BUILD := build
SOURCE := source
INCLUDE := include
DATA := data
LIBS :=
LIBS := -lnet -lsysmodule

TITLE := ECHOServer - PSL1GHT
APPID := TEST0SRV1
Expand Down
19 changes: 18 additions & 1 deletion samples/echoserv/source/echoserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
#include <sys/types.h> /* socket types */
#include <arpa/inet.h> /* inet (3) funtions */
#include <unistd.h> /* misc. UNIX functions */
#include <sysmodule/sysmodule.h>

#include "helper.h" /* our own helper functions */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

/* Global constants */

Expand Down Expand Up @@ -52,11 +54,16 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}


#ifdef USE_LIBNET_SPRX
printf("SysLoadModule(NET)=%d\n", SysLoadModule(SYSMODULE_NET));
printf("net_init()=%d\n", net_initialize_network());
#endif

/* Create the listening socket */

if ( (list_s = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
fprintf(stderr, "ECHOSERV: Error creating listening socket.\n");
printf("errno: %d\n", errno);
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -109,10 +116,20 @@ int main(int argc, char *argv[]) {

/* Close the connected socket */

#ifdef USE_LIBNET_SPRX
if ( socketclose(conn_s) < 0 ) {
fprintf(stderr, "ECHOSERV: Error calling close()\n");
exit(EXIT_FAILURE);
}

net_finalize_network();
SysUnloadModule(SYSMODULE_NET);
#else
if ( close(conn_s) < 0 ) {
fprintf(stderr, "ECHOSERV: Error calling close()\n");
exit(EXIT_FAILURE);
}
#endif
}
}

0 comments on commit b28e37a

Please sign in to comment.