-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 utils to create and prepare socket for tcp client #31009
Changes from 9 commits
6ff4b03
75981f2
43a7f28
b604e01
240620b
7ea0191
7ee17e8
295f07a
a238ec1
35333a1
8d999aa
6775530
3939c11
1bdb259
55b1e3f
4e6775d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,6 +301,22 @@ class PosixSocketWrapper { | |
const experimental::EventEngine::ResolvedAddress& addr, int type, | ||
int protocol, DSMode& dsmode); | ||
|
||
// Return a PosixSocketWrapper which manages a configured, unbound, | ||
// unconnected TCP client fd. | ||
// options: may contain custom tcp settings for the fd. | ||
// target_addr: the destination address. | ||
// output_mapped_target_addr: A out parameter. It is target_addr mapped to an | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to keep the memory footprint of PosixSocketWrapper very small - currently it has only one member variable i.e the socket descriptor and all the operations it supports are stateless. This allows creating socket wrappers at will and using them to manipulate socket flags. The peer address is requested only once and I dont think we should be storing it in the socket wrapper. We can store it in the endpoint code that requests for it. Shall I modify this to return an absl::StatusOr<std::tuple<PosixSocketWrapper, ResolvedAddress>> instead ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. In that case, I'd suggest a return struct, per https://abseil.io/tips/176 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
// address appropriate to the type of socket FD created. For example, if | ||
// target_addr is IPv4 and dual stack sockets are available, | ||
// output_mapped_target_addr will be an IPv4-mapped IPv6 address. | ||
// | ||
// Returns: Not-OK status on error. Out parameters are not set on error. | ||
// | ||
static absl::StatusOr<PosixSocketWrapper> CreateAndPrepareTcpClientSocket( | ||
const PosixTcpOptions& options, | ||
const EventEngine::ResolvedAddress& target_addr, | ||
EventEngine::ResolvedAddress& output_mapped_target_addr); | ||
|
||
private: | ||
int fd_; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The single-argument version is more general. I'd recommend keeping the absl::cleanup as you had it before, and standardizing on a general solution that works across gRPC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it to src/core/lib/gprpp/status_helper.h file now.