Skip to content

Feature/sendmsg #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2021
Merged

Feature/sendmsg #148

merged 6 commits into from
Apr 8, 2021

Conversation

fabriziobertocci
Copy link
Contributor

Added implementation and unit test for sendmsg() and recvmsg().
Tested on Linux, Mac and Windows.

…32_t (the original type is socklen_t and is not signed). Added implementation of recvmsg
…ng the function to return EINVAL on BSD/MacOS for non-connected sockets
Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, with two minor nits. Very happy to see the unit test. Thank you for sending this!

/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2021 │
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please edit this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I copied the header from the socketpair test tha Allison wrote... I removed her name but I forgot to add your...
changed.

msg.msg_iovlen = 1;
ASSERT_EQ(hwLen, recvmsg(fd[1], &msg, 0));

ASSERT_EQ(0, memcmp(&(((char *)(msg.msg_iov[0].iov_base))[0]), hello, strlen(hello)));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try changing malloc(20) to gc(xcalloc(20)). In that case, you can delete the null check and these two lines can simply be EXPECT_STREQ("helloworld", msg.msg_iov[0].iov_base);. You'll need these too of course:

#include "libc/runtime/gc.internal.h"
#include "libc/x/x.h"

Copy link
Owner

@jart jart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jart jart merged commit 24d7959 into jart:master Apr 8, 2021
jart added a commit that referenced this pull request Apr 8, 2021
The send{,to,msg} and recv{,from,msg} functions have been updated to
delegate to WriteFile and ReadFile when appropriate, due to the fact
that socketpair(AF_UNIX) is implemented using kFdFile.

Thanks @fabriziobertocci for writing the test that caught this.

See #148 and #122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants