Skip to content

Commit b8bf37a

Browse files
committed
implement socket
1 parent 21414b9 commit b8bf37a

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

libogc/CMakeLists.txt

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

1010
ogc_sockets/soc_common.c
11+
ogc_sockets/soc_socket.c
1112

1213
console.c
1314
lwp_queue.c

libogc/ogc_sockets/soc_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string.h>
66
#include <sys/iosupport.h>
77
#include <gctypes.h>
8+
#include <network.h>
89

910
#define SYNC_ERROR ENODEV
1011

libogc/ogc_sockets/soc_socket.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "soc_common.h"
2+
#include <errno.h>
3+
4+
int socket(int domain, int type, int protocol)
5+
{
6+
s32 ret = 0;
7+
int fd, dev;
8+
__handle *handle;
9+
10+
dev = FindDevice("soc:");
11+
if(dev < 0) {
12+
errno = ENODEV;
13+
return -1;
14+
}
15+
16+
fd = __alloc_handle(dev);
17+
if(fd < 0) return fd;
18+
handle = __get_handle(fd);
19+
handle->device = dev;
20+
handle->fileStruct = ((void *)handle) + sizeof(__handle);
21+
22+
23+
ret = net_socket( domain, type, protocol);
24+
25+
if (ret < 0) {
26+
__release_handle(fd);
27+
errno = -ret;
28+
return -1;
29+
}
30+
31+
*(Handle*)handle->fileStruct = ret;
32+
33+
return fd;
34+
}

0 commit comments

Comments
 (0)