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

Blocking connection timeout/failure gives wrong error message #3

Open
Lexikos opened this issue Oct 6, 2023 · 7 comments
Open

Blocking connection timeout/failure gives wrong error message #3

Lexikos opened this issue Oct 6, 2023 · 7 comments

Comments

@Lexikos
Copy link

Lexikos commented Oct 6, 2023

sock := winsock("client", , "IPV4")
sock.Connect("192.168.20.12", 23, true)

When this eventually times out (due to nothing listening at that address/port), it gives a misleading/incorrect error message:

Error: Invalid family for sockaddr creation: 0

@TheArkive
Copy link
Owner

Thanks for the post, I'll fix this.

@TheArkive
Copy link
Owner

TheArkive commented Nov 28, 2023

@Lexikos

sorry for the delay on this, the more I read the MS-docs site, the more I wonder if this lib needs a rewrite, or at least deeper changes for better error handling.

Some of my old examples, that I thought were simple, aren't actually working anymore (ie. connecting to google).

Is that error msg the only issue in your opinion? Does this lib work sufficiently apart from that error msg?

@TheArkive
Copy link
Owner

TheArkive commented Dec 20, 2023

@Lexikos

Sorry to prompt you again,

I finally traced the logic I was using for how that error to come about. I actually have a function that records the last error code, and it's descriptor (this.WsaLastErr()). The intent was to have the user check the error codes after issuing a command, so that the script could continue functioning.

Socket error info is recorded here:

this.errnum
this.LastOp (ie. connect, accept, etc.)
this.err    (ie. WSAETIMEDOUT)

These properties are updated after every method call that would return a winsock error code.

I figured that if an error were thrown for every Winsock error, then the lib would be less useful for a robust application. I actually intended for the user to check the errors after an operation and handle them accordingly.

Should I instead throw an error for every winsock error? Or simply take this throw out?

Which do you think would be more useful?

Incidentally, I of course didn't intend this particular error to be thrown on connect fail. It seems I was overzealous in this case, and the actual error, in the case of a timeout, has little or no relation to this particular error being thrown. I'm leaning toward just taking this instance of throw out.

@Lexikos
Copy link
Author

Lexikos commented May 31, 2024

My only care was that the misleading message caused some time to be wasted while I was troubleshooting. So far I've only used the script to send a short string of commands over telnet. Once I got it working, I have used it very frequently (to turn my AV receiver on/off) and have not encountered any issues.

I would suggest throwing for any failure by default, but doing it via a method which the user can override. If a user wants to use v1-style error checking, they can implement it by overriding the method (or setting a callback, or whatever mechanism you choose).

Sorry to prompt you again,

It matters not to me; I only go through my GitHub notifications on rare occasions. I have them automatically filed away to eliminate unwanted distractions.

@TheArkive
Copy link
Owner

Ok, maybe something like this then?

variadic method

sock.LastErr(list, errors, to, skip, ...)

@Lexikos
Copy link
Author

Lexikos commented Jun 8, 2024

I don't know what you mean.

My suggestion is to simply define a method which throws; e.g. usage like sock.RaiseError(errnum), with the parameter being optional and defaulting to WSAGetLastError if you would need that often. The user can redefine RaiseError or subclass and override.

@TheArkive
Copy link
Owner

TheArkive commented Jun 8, 2024

Ok, I'll add that as well as the ability to specify a callback for error handling.

Edit: I'll leave the callback for the coder as you suggested earlier.

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