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
always use the passed fd in generated saferead() and safewrite() functions #272
base: main
Are you sure you want to change the base?
Conversation
@@ -5,11 +5,11 @@ | |||
|
|||
extern ssize_t timeoutwrite(int t, int fd, const void *buf, size_t len); | |||
|
|||
#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,writefd,doexit) \ | |||
#define GEN_SAFE_TIMEOUTWRITE(funcname,tout,doexit) \ | |||
ssize_t funcname(int fd, const void *buf, size_t 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.
The fd
argument was never used there. Maybe an omission or a change of mind mid-way...
This sounds like pursuing some work, makes sense to me.
Thank you!
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.
Not entirely. Some callers passed "fd" as the "writefd" macro argument, so they actually used the fd passed to the function. And now just all do.
The "to" and "from" substdios are initialized with fd -1 because the socket is dynamically allocated at runtime. That is why the passed fd in the saferead() and safewrite() functions was ignored and the socket descriptor was always used. Update the fd in the substdios once the socket is allocated and then use the provided fd.
The "to" and "from" substdios are initialized with fd -1 because the socket is dynamically allocated at runtime. That is why the passed fd in the saferead() and safewrite() functions was ignored and the socket descriptor was always used. Update the fd in the substdios once the socket is allocated and then use the provided fd.
…ator macros All instances now use the fd that is passed through the interface, so this can be removed from the macro.
8aeb025
to
adf7662
Compare
Fixes #270.
There were situations where the generated functions would ignore the fd that was passed as their argument because if was always "-1". This happened when the substdio was statically initialized but a socket was dynamically allocated at runtime and was actually used for communication. Update the substdio when the socket is known, and then just use the passed fd.