Skip to content

Commit 820de7e

Browse files
committed
implement accept
1 parent 10e144e commit 820de7e

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

libogc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_library(ogc STATIC
1515
ogc_sockets/soc_recv.c
1616
ogc_sockets/soc_connect.c
1717
ogc_sockets/soc_shutdown.c
18+
ogc_sockets/soc_accept.c
1819

1920
console.c
2021
lwp_queue.c

libogc/ogc_sockets/soc_accept.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+
#include <sys/socket.h>
4+
5+
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
6+
{
7+
sockfd = soc_get_fd(sockfd);
8+
9+
if(sockfd < 0) {
10+
errno = -sockfd;
11+
return -1;
12+
}
13+
14+
int dev = FindDevice("soc:");
15+
if(dev < 0) {
16+
errno = ENODEV;
17+
return -1;
18+
}
19+
20+
int fd = __alloc_handle(dev);
21+
if(fd < 0) return fd;
22+
23+
24+
int ret = net_accept(sockfd, addr, addrlen);
25+
if (ret < 0 ) {
26+
errno = -ret;
27+
return -1;
28+
}
29+
30+
__handle *handle = __get_handle(fd);
31+
*(Handle*)handle->fileStruct = ret;
32+
33+
return fd;
34+
}

0 commit comments

Comments
 (0)