Skip to content

Commit ecb91bd

Browse files
committed
implement recv and recvfrom
1 parent f64a5bd commit ecb91bd

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

libogc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ add_library(ogc STATIC
1212
ogc_sockets/soc_bind.c
1313
ogc_sockets/soc_listen.c
1414
ogc_sockets/soc_send.c
15+
ogc_sockets/soc_recv.c
1516

1617
console.c
1718
lwp_queue.c

libogc/ogc_sockets/soc_recv.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "soc_common.h"
2+
#include <errno.h>
3+
#include <sys/socket.h>
4+
5+
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen)
6+
{
7+
sockfd = soc_get_fd(sockfd);
8+
if(sockfd < 0) {
9+
errno = -sockfd;
10+
return -1;
11+
}
12+
13+
int ret = net_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
14+
15+
if (ret < 0 ) {
16+
errno = -ret;
17+
ret = -1;
18+
}
19+
return ret;
20+
}
21+
22+
ssize_t recv(int sockfd, void *buf, size_t len, int flags)
23+
{
24+
sockfd = soc_get_fd(sockfd);
25+
if(sockfd < 0) {
26+
errno = -sockfd;
27+
return -1;
28+
}
29+
30+
int ret = net_recv(sockfd, buf, len, flags);
31+
32+
if (ret < 0 ) {
33+
errno = -ret;
34+
ret = -1;
35+
}
36+
37+
return ret;
38+
}

0 commit comments

Comments
 (0)