Skip to content
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

add a new function recv_at_least() to socket stream #224

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

lihuiba
Copy link
Collaborator

@lihuiba lihuiba commented Oct 28, 2023

to recv at least a number of bytes from socket stream, so as to reduce the # of syscalls

@beef9999
Copy link
Collaborator

Merge to release/0.7 ?

net/socket.h Outdated
@@ -216,6 +216,23 @@ namespace net {
// may block once at most, when there's no data yet in the socket;
virtual ssize_t recv(void *buf, size_t count, int flags = 0) = 0;
virtual ssize_t recv(const struct iovec *iov, int iovcnt, int flags = 0) = 0;
virtual ssize_t recv_mutable(struct iovec *iov, int iovcnt, int flags = 0) {
return recv(iov, iovcnt, flags);
}
Copy link
Collaborator

@beef9999 beef9999 Oct 28, 2023

Choose a reason for hiding this comment

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

Any chance we need to modify the iovec pointer?

Copy link
Collaborator Author

@lihuiba lihuiba Oct 28, 2023

Choose a reason for hiding this comment

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

Because const iovec* is a convention, just like readv/preadv/writev/pwritev ...

Obeying the convention can avoid unnecessary errors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using another function name is also for obeying the convention, despite C++ has function overloading.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I made a mistake. In fact recv/send usually makes a single I/O action that doesn't need to modify the iovec[]. Only recv_at_least needs so.

@lihuiba lihuiba changed the base branch from main to release/0.7 October 28, 2023 13:39
@beef9999
Copy link
Collaborator

LGTM

@lihuiba lihuiba merged commit 2f547d2 into alibaba:release/0.7 Oct 30, 2023
1 check passed
beef9999 pushed a commit that referenced this pull request Nov 2, 2023
add new functions recv_at_least() and recv_at_least_mutable() to socket stream
wsgeek pushed a commit to wsgeek/PhotonLibOS that referenced this pull request Nov 12, 2023
add new functions recv_at_least() and recv_at_least_mutable() to socket stream
@lihuiba lihuiba deleted the recv_at_least branch January 3, 2024 04:20
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.

Can you provide an interface that reads at least n bytes and reads as many as possible?
2 participants