-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Custom mg_set_non_blocking_mode() implementation #1411
Comments
@dmitry-kandiner thank you! Do you get a build error about it? If yes, could you share it please? |
@cpq sure, here is the snippet from the build log:
Actually, my solution for this was like this:
Plus the following code in mongoose_cusom.h:
Best regards, |
Thank you. Maybe a way to go is to create your own custom #define fcntl sys_fcntl
.....includes....
// Here make our own fcntl()
#define F_SETFD 12345
#define FD_CLOEXEC 0
#undef fcntl
static inline int fcntl(int fd, int cmd, ...) {
if (cmd == F_GETFL) return sys_fcntl(fd, cmd);
if (cmd == F_SETFL) {
va_list ap;
va_start(ap, cmd);
uint32_t opt = va_arg(ap, int);
int result = sys_fcntl(fd, cmd, &opt);
va_end(ap);
return result;
}
return 0;
}
|
Unfortunately, it didn't work for me. I tried to add the following code to the mogoose_custom.h, but was not able to link it. #define fcntl sys_fcntl
#include <core/bsd_socket.h>
static inline int_t mg_fcntl(int_t fd, int_t cmd, void* opt)
{
return sys_fcntl(fd, cmd, opt);
}
#define F_SETFD 12345
#define FD_CLOEXEC 0
#undef fcntl
static inline int fcntl(int fd, int cmd, ...) {
if (cmd == F_GETFL)
{
uint32_t opt;
mg_fcntl(fd, cmd, &opt);
return opt;
}
if (cmd == F_SETFL)
{
va_list ap;
va_start(ap, cmd);
uint32_t opt = va_arg(ap, int);
int result = mg_fcntl(fd, cmd, &opt);
va_end(ap);
return result;
}
return 0;
} Unfortunately linker fails with |
Maybe the best way will be to use |
I still think it is possible to inject a custom #include <core/bsd_socket.h>
#define F_SETFD 12345
#define FD_CLOEXEC 0
static inline int mg_fcntl(int fd, int cmd, ...) {
if (cmd == F_GETFL) { uint32_t opt; fcntl(fd, cmd, &opt); return opt; }
...
}
#define fcntl mg_fcntl |
Thank you, @cpq , this solution worked for me! |
It would be nice to have an option for custom mg_set_non_blocking_mode() implementation - some architectures have non-standard way for doing so. For instance, Cyclone TCP stack implementation of fcntl() requires three parameters: a socket, a command and a pointer to the command parameters.
The text was updated successfully, but these errors were encountered: