Skip to content

Commit f64a5bd

Browse files
committed
implement sent and sendto
1 parent 95419ad commit f64a5bd

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

libogc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_library(ogc STATIC
1111
ogc_sockets/soc_socket.c
1212
ogc_sockets/soc_bind.c
1313
ogc_sockets/soc_listen.c
14+
ogc_sockets/soc_send.c
1415

1516
console.c
1617
lwp_queue.c

libogc/ogc_sockets/soc_send.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "soc_common.h"
2+
#include <sys/socket.h>
3+
4+
5+
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_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_sendto(sockfd, buf, len, flags, (struct sockaddr *)dest_addr, addrlen);
14+
if (ret < 0 ) {
15+
errno = -ret;
16+
ret = -1;
17+
}
18+
return ret;
19+
}
20+
21+
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
22+
{
23+
sockfd = soc_get_fd(sockfd);
24+
if(sockfd < 0) {
25+
errno = -sockfd;
26+
return -1;
27+
}
28+
29+
int ret = net_send(sockfd, buf, len, flags);
30+
31+
if (ret < 0 ) {
32+
errno = -ret;
33+
ret = -1;
34+
}
35+
return ret;
36+
}

0 commit comments

Comments
 (0)