-
Notifications
You must be signed in to change notification settings - Fork 95
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
[k2] add file functions in runtime light #1161
Conversation
ec11160
to
27888ed
Compare
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.
General comment: please apply clang-format to runtime-light
and runtime-common
directories (files you modified).
5c2db15
to
95cdd8a
Compare
e9b2935
to
b3150bb
Compare
runtime-light/k2-platform/k2-api.h
Outdated
@@ -165,4 +165,26 @@ inline auto arg_fetch(uint32_t arg_num) noexcept { | |||
std::unique_ptr<char, decltype(std::addressof(k2::free))>{value_buffer, std::addressof(k2::free)}); | |||
} | |||
|
|||
inline int32_t udp_connect(uint64_t *socket_d, const char *host, size_t host_len) { |
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.
Missing noexcept
modifier. Please, apply it to all the functions you' added
runtime-light/k2-platform/k2-api.h
Outdated
} | ||
|
||
|
||
inline int32_t lookup_host(const char *host, size_t host_len, struct SockAddr *result_buf, size_t *result_buf_len) { |
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.
We should not depend on raw k2 primitives in our code. Please, use a simple using SockAddr = SockAddr;
. It should be applied to all k2 types you use.
runtime-light/k2-platform/k2-api.h
Outdated
return k2_lookup_host(host, host_len, result_buf, result_buf_len); | ||
} | ||
|
||
inline int32_t socket(uint64_t *socket_d, int32_t domain, int32_t type, int protocol) { |
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.
Please, don't use int
. Use int32_t
instead.
runtime-light/state/instance-state.h
Outdated
@@ -100,6 +100,8 @@ struct InstanceState final : vk::not_copyable { | |||
return open_stream(std::string_view{component_name.c_str(), static_cast<size_t>(component_name.size())}); | |||
} | |||
|
|||
std::pair<uint64_t, int32_t> connect_to(const string &host, bool reliable) noexcept; |
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.
I don't think that it's necessary to return low-level cerrno
-like objects from this function
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.
Also, I don't like the naming here: reliable
?
const int32_t error_number{reliable ? k2::tcp_connect(std::addressof(stream_d), host.c_str(), host.size()) | ||
: k2::udp_connect(std::addressof(stream_d), host.c_str(), host.size())}; | ||
|
||
if (error_number != 0) { |
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.
There is a special k2::errno_ok
value for that purpose
return false; | ||
} | ||
|
||
return {string(static_cast<int64_t>(type)).append(":").append(static_cast<int64_t>(stream_d))}; |
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.
Can you please explain the idea behind these streams? As far as I understand, the user now has access to the internals of the runtime, e.g. internal stream descriptors.
php_warning("try to fclose wrong resource %s", stream.to_string().c_str()); | ||
return false; | ||
} | ||
if (InstanceState::get().standard_stream() == stream_d) { |
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.
That is consecutive of your decision to operate on internal stream descriptors
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.
I don't see any reason to create a distinct directory for that
|
||
namespace { | ||
|
||
constexpr std::string_view STDERR_NAME{"stderr"}; |
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.
Let's initialise globals with =
. It's just how we started doing it... Also, as I can see, you also use it in another file.
} // namespace | ||
|
||
uint64_t open_php_stream(const string &stream_name) noexcept { | ||
if (strcmp(stream_name.c_str(), STDERR_NAME.data()) == 0) { |
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.
You do have std::string_view
here, why not just create another one and compare string views instead of raw pointers?
if (std::string_view{stream_name.c_str(), stream_name.size()} == STDERR_NAME)
d2b3e5c
to
97cc8aa
Compare
e612f28
to
5690961
Compare
5690961
to
61e42a7
Compare
todo