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

nsa_select/nsa_socketpair is not working correctly #427

Open
ThuyThTruong opened this issue Jan 16, 2018 · 0 comments
Open

nsa_select/nsa_socketpair is not working correctly #427

ThuyThTruong opened this issue Jan 16, 2018 · 0 comments
Assignees

Comments

@ThuyThTruong
Copy link

neat nsa_poll (called by nsa_select) on this nsa_socketpair not able to detect writable/readable events on nsa_socketpair.

main.c
int main(int argc,char *argv[])
{


    int fd[2];
    pid_t pid;
    int cnt = 0;
    fd_set r_fds, e_fds, w_fds;

            FD_ZERO(&r_fds);
            FD_ZERO(&e_fds);
            FD_ZERO(&w_fds);

            struct timeval tv;
            tv.tv_sec = 5;
            tv.tv_usec = 0;

    nsa_socketpair(AF_UNIX, SOCK_STREAM, 0, fd, NULL);

    pid = fork();
    if (pid == 0) {
        close(fd[0]);
                const char hello[] = "hello parent, I am child";

                while(1)
                {
                            nsa_select(fd[1] + 1, 0, &w_fds, 0, &tv);   -> this does not detect the writable event to put on w_fds.

                            if (FD_ISSET(fd[1], &w_fds))
                            {
                                        nsa_write(socket, hello, sizeof(hello));
                                        printf("done nsa_write\n");
                                        break;
                            }
                }


    } else {
        close(fd[1]);
                char buf[1024];

                while (1)
                {
                            nsa_select(fd[0] + 1, &r_fds, 0, &e_fds, &tv);

                            if (FD_ISSET(fd[0], &r_fds))
                            {
                                        int n = nsa_read(socket, buf, sizeof(buf));
                                        printf("parent received '%.*s'\n", n, buf);
                                        break;
                            }
                }

    }
    return 0;
}

It seems that nsa_select on the child could not see the writable event to trigger the nsa_write.
I had a look into nsa_socketpair, there is no flow created and I’m wondering how the events (on_writable/readable/etc.) can be trigger in this nsa_sockepair case.

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

No branches or pull requests

2 participants