Skip to content

lwip - Fixed error codes for failed TCP connect #3403

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

Merged
merged 1 commit into from
Jan 10, 2017

Conversation

geky
Copy link
Contributor

@geky geky commented Dec 8, 2016

Some error codes in TCP connect were being remapped incorrectly

condition               posix error     mbed error
good host, closed port  ECONNREFUSED    NSAPI_ERROR_NO_CONNECTION
bad host                EHOSTUNREACH    NSAPI_ERROR_NO_CONNECTION
bad network             ENETUNREACH     NSAPI_ERROR_NO_CONNECTION

Thanks to @infinnovation for finding this, verified with their test program in #3246

cc @infinnovation, @c1728p9
should resolve #3246

condition               posix error     mbed error
good host, closed port  ECONNREFUSED    NSAPI_ERROR_NO_CONNECTION
bad host                EHOSTUNREACH    NSAPI_ERROR_NO_CONNECTION
bad network             ENETUNREACH     NSAPI_ERROR_NO_CONNECTION
Copy link
Contributor

@bridadan bridadan left a comment

Choose a reason for hiding this comment

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

Nice!

@bridadan
Copy link
Contributor

bridadan commented Dec 8, 2016

/morph test-nightly

@mbed-bot
Copy link

mbed-bot commented Dec 9, 2016

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 1232

All builds and test passed!

@kjbracey
Copy link
Contributor

Seems correct, but as I've just been working in the area with Nanostack's TCP and been studying this...

There are two more common fatal error conditions to consider:

condition                            posix error     mbed error
remote host not responding           ETIMEDOUT       NSAPI_ERROR_NO_CONNECTION
we or remote host aborted            ECONNRESET      NSAPI_ERROR_NO_CONNECTION

Presumably ECONNRESET and ECONNREFUSED are both ERR_RST, but not sure if timeout falls in there too.

@adbridge
Copy link
Contributor

@geky Hi Chris there are a couple of things here. Firstly could this be a breaking change as one of the return codes has a different value now. Secondly do you want to address Kevin's comments? Currently postponing this to 5.4 in the meantime.

@geky
Copy link
Contributor Author

geky commented Dec 19, 2016

The change is to return an error instead of succeeding when a connection fails. Later usage of the socket would result in (hopefully) an error anyways. I'm not sure how this could break backwards compatibility short of applications intentionally creating invalid connections.

@kjbracey-arm, I haven't had the chance to test the conditions you point out. Do you think we should add the additionally error codes for better granularity as to what went wrong in a connection? My concern is that it's unlikely the small devices (esp8266, mx, c027...) will return anything more than "connection failed". Do you think having the option for granularity is still worthwhile?

@kjbracey
Copy link
Contributor

See also my comments on #3457 with regard to error codes. I don't see any particular need to distinguish between all the errors listed here, but I am a bit wary about the lack of a distinction between "not connected [yet] (ENOTCONN)" and all the failure codes once we have non-blocking connect.

Separate issue from this patch, and any splitting of error codes is a potential backwards compatibility break, so would need more thought. I think this patch is fine.

All the problem-type codes are "event"/"sticky" ones generally returned only once by the stack via SO_ERROR, and then calls will revert back to the base ENOTCONN. It's certainly possible that some implementations couldn't provide them at all and just give ENOTCONN. But maybe stacks that can could return new ones before falling back to NO_CONNECTION.

@sg-
Copy link
Contributor

sg- commented Jan 9, 2017

@adbridge did you forget to merge or is something else needed here?

@adbridge
Copy link
Contributor

Looks like a 'missed the merge step' !

@adbridge adbridge merged commit 9e24117 into ARMmbed:master Jan 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lwip] Zero or wrong error returned from failed TCPSocket.connect()
8 participants