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

fixing select usage #283

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

fixing select usage #283

wants to merge 3 commits into from

Conversation

kojo1
Copy link
Contributor

@kojo1 kojo1 commented Jan 17, 2022

  • Set timeout in tcp_select
    timeout.tv_sec = to_sec;

  • Set non-blocking to "connd", as well.
    fcntl(connd, F_SETFL, O_NONBLOCK)

  • tcp_select(connd,...) for wolfSSL_accept, read, write

  • make all 3 args non-NULL for select. NULL arg derives error on MacOS.

====

Totally changed to a single polling point.

SV_CTX *sv_poll() {
        poll();
        return next_ctx;
}

int main() {
    while(1) {
        switch (sv_main(sv_ctx = sv_poll())) {
        case NB_CONTINUE:
            break;
    }
}

@@ -52,36 +52,34 @@ enum {

static int tcp_select(SOCKET_T socketfd, int to_sec, int rx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do not check the return of tcp_select, it would be better to change the return to a void. Alternatively, the return of this function should be checked in the main loop.

Copy link
Contributor Author

@kojo1 kojo1 Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to poll() version as Daniele suggested. It looks like behaving as expected.

Will eliminate the return value as soon as debugging is completed.

@kojo1 kojo1 force-pushed the nonblocking branch 4 times, most recently from 2b4bc1d to 8c178cd Compare January 23, 2022 07:28
Copy link
Member

@danielinux danielinux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example looks clear now.
I like the idea of a state machine with a switch-case with these FALL_THROUGH, however sv_main is a bit too long, perhaps it could be split into more functions for readability.

Please fix the spelling of macros NB_FATAL and SV_VERBOSE.

break;
case NB_FAITAL:
sv_free(sv_ctx);
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be return 1 so that execution is stopped?

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

Successfully merging this pull request may close these issues.

None yet

3 participants