Skip to content

nsa_select/nsa_socketpair is not working correctly #427

Open
@ThuyThTruong

Description

@ThuyThTruong

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions