move iovec to go

This commit is contained in:
Josh Bleecher Snyder
2021-06-01 16:03:51 -07:00
parent 53117d9761
commit 56ece41326
2 changed files with 5 additions and 12 deletions

View File

@@ -16,6 +16,7 @@
typedef struct io_uring go_uring;
typedef struct msghdr go_msghdr;
typedef struct iovec go_iovec;
// Wait for a completion to be available, fetch the data
static int receive_into(int sock, struct io_uring *ring, char *ip, uint16_t *port) {
@@ -49,7 +50,6 @@ again:;
memcpy(ip, &sa.sin_addr, 4);
*port = ntohs(sa.sin_port);
free(mhdr->msg_iov);
free(mhdr->msg_name);
io_uring_cqe_seen(ring, cqe);
@@ -58,21 +58,12 @@ again:;
// submit a recvmsg request via liburing
// TODO: What recvfrom support arrives, maybe use that instead?
static int submit_recvmsg_request(int sock, struct io_uring *ring, struct msghdr *mhdr, char *buf, int buflen) {
struct iovec *iov = malloc(sizeof(struct iovec));
if (!iov) {
perror("malloc(iov)");
return 1;
}
static int submit_recvmsg_request(int sock, struct io_uring *ring, struct msghdr *mhdr, struct iovec *iov, char *buf, int buflen) {
char *sender = malloc(sizeof(struct sockaddr_in));
if (!sender) {
perror("malloc(sender)");
free(iov);
return 1;
}
memset(iov, 0, sizeof(*iov));
iov->iov_base = buf;
iov->iov_len = buflen;

View File

@@ -71,8 +71,9 @@ func (u *UDPConn) ReadFromNetaddr(buf []byte) (int, netaddr.IPPort, error) {
return 0, netaddr.IPPort{}, errors.New("invalid uring.UDPConn")
}
mhdr := new(C.go_msghdr)
iov := new(C.go_iovec)
// TODO: eventually separate submitting the request and waiting for the response.
errno := C.submit_recvmsg_request(u.fd, u.ptr, mhdr, (*C.char)(unsafe.Pointer(&buf[0])), C.int(len(buf)))
errno := C.submit_recvmsg_request(u.fd, u.ptr, mhdr, iov, (*C.char)(unsafe.Pointer(&buf[0])), C.int(len(buf)))
if errno < 0 {
return 0, netaddr.IPPort{}, fmt.Errorf("uring.UDPConn recv failed: %v", errno) // TODO: Improve errno
}
@@ -85,6 +86,7 @@ func (u *UDPConn) ReadFromNetaddr(buf []byte) (int, netaddr.IPPort, error) {
}
ipp := netaddr.IPPortFrom(netaddr.IPFrom4(*a), uint16(port))
runtime.KeepAlive(mhdr)
runtime.KeepAlive(iov)
return int(n), ipp, nil
}