Skip to content

Commit f7bc088

Browse files
committed
add devoptab device for network code
1 parent d0f4ea8 commit f7bc088

4 files changed

Lines changed: 132 additions & 1 deletion

File tree

libogc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_library(ogc STATIC
77
lwpcompat/lwpc_sem.c
88
lwpcompat/lwpc_mq.c
99

10+
ogc_sockets/soc_init.c
1011
ogc_sockets/soc_common.c
1112
ogc_sockets/soc_socket.c
1213
ogc_sockets/soc_bind.c

libogc/network_wii.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ distribution.
5151
#include <fcntl.h>
5252
#include <malloc.h>
5353
#include <poll.h>
54-
54+
5555
#include "ipc.h"
5656
#include "processor.h"
5757
#include "network.h"
5858
#include "ogcsys.h"
5959
#include "lwp_heap.h"
6060

61+
#include "ogc_sockets/soc.h"
62+
6163
#define NET_HEAP_SIZE 64*1024
6264

6365
#define IOS_O_NONBLOCK 0x04 //(O_NONBLOCK >> 16) - it's in octal representation, so this shift leads to 0 and hence nonblocking sockets didn't work. changed it to the right value.
@@ -1209,6 +1211,8 @@ s32 if_configex(struct in_addr *local_ip, struct in_addr *netmask, struct in_add
12091211

12101212
if(netmask)
12111213
netmask->s_addr = ipconfig->subnetMask;
1214+
1215+
socInit();
12121216

12131217
if(!gateway)
12141218
return 0;

libogc/ogc_sockets/soc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
int socInit(void);
4+
int socExit(void);

libogc/ogc_sockets/soc_init.c

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "soc_common.h"
2+
#include <errno.h>
3+
#include <sys/socket.h>
4+
5+
static int
6+
soc_open(struct _reent *r,
7+
void *fileStruct,
8+
const char *path,
9+
int flags,
10+
int mode)
11+
{
12+
r->_errno = ENOSYS;
13+
return -1;
14+
}
15+
16+
static int
17+
soc_close(struct _reent *r,
18+
void *fd)
19+
{
20+
21+
int ret = net_close(*(Handle*)fd);
22+
23+
if (ret < 0 ) {
24+
errno = -ret;
25+
ret = -1;
26+
}
27+
28+
return ret;
29+
}
30+
31+
static ssize_t
32+
soc_write(struct _reent *r,
33+
void *fd,
34+
const char *ptr,
35+
size_t len)
36+
{
37+
38+
int ret = net_sendto(*(Handle*)fd, ptr, len, 0, NULL, 0);
39+
40+
if (ret < 0 ) {
41+
errno = -ret;
42+
ret = -1;
43+
}
44+
45+
return ret;
46+
}
47+
48+
static ssize_t
49+
soc_read(struct _reent *r,
50+
void *fd,
51+
char *ptr,
52+
size_t len)
53+
{
54+
55+
int ret = net_recvfrom(*(Handle*)fd, ptr, len, 0, NULL, NULL);
56+
57+
if (ret < 0 ) {
58+
errno = -ret;
59+
ret = -1;
60+
}
61+
return ret;
62+
}
63+
64+
65+
static devoptab_t
66+
soc_devoptab =
67+
{
68+
.name = "soc",
69+
.structSize = sizeof(Handle),
70+
.open_r = soc_open,
71+
.close_r = soc_close,
72+
.write_r = soc_write,
73+
.read_r = soc_read,
74+
.seek_r = NULL,
75+
.fstat_r = NULL,
76+
.stat_r = NULL,
77+
.link_r = NULL,
78+
.unlink_r = NULL,
79+
.chdir_r = NULL,
80+
.rename_r = NULL,
81+
.mkdir_r = NULL,
82+
.dirStateSize = 0,
83+
.diropen_r = NULL,
84+
.dirreset_r = NULL,
85+
.dirnext_r = NULL,
86+
.dirclose_r = NULL,
87+
.statvfs_r = NULL,
88+
.ftruncate_r = NULL,
89+
.fsync_r = NULL,
90+
.deviceData = 0,
91+
.chmod_r = NULL,
92+
.fchmod_r = NULL,
93+
};
94+
95+
96+
int socInit(void)
97+
{
98+
/* check that the "soc" device doesn't already exist */
99+
int dev = FindDevice("soc:");
100+
if(dev >= 0)
101+
return -1;
102+
103+
/* add the "soc" device */
104+
dev = AddDevice(&soc_devoptab);
105+
if(dev < 0)
106+
return -1;
107+
108+
return 0;
109+
}
110+
111+
int socExit(void)
112+
{
113+
int ret = 0;
114+
int dev;
115+
116+
dev = FindDevice("soc:");
117+
118+
if(dev >= 0)
119+
RemoveDevice("soc:");
120+
121+
return ret;
122+
}

0 commit comments

Comments
 (0)