AcornSSL parameter error
Chris Mahoney (1684) 2165 posts |
I’ve just had my first go at using AcornSSL directly (usually I let AcornHTTP do all the work so this is new to me). I can create a socket, but when I try to use setsockopt to set the host name, I get “Parameter error (code 22)”. I’ve trimmed it down to the minimal code to make it fail:
What am I doing wrong here? I imagine that I’ve overlooked something simple, as usual :) |
Simon Willcocks (1499) 513 posts |
I’ve never tried this, but isn’t the last argument to setsockopt the size of the preceding value (host)? It won’t be the size of the pointer, but the thing it’s pointing to. |
Chris Mahoney (1684) 2165 posts |
The docs say to use 4.
I did try |
Simon Willcocks (1499) 513 posts |
It’s based on mbedTLS, so maybe their documentation will be helpful. https://os.mbed.com/docs/mbed-os/v6.15/apis/tlssocket.html https://os.mbed.com/docs/mbed-os/v6.15/mbed-os-api-doxy/class_t_l_s_socket.html Perhaps the socket has to be connected to the host before passing it to setsockopt? |
Jon Abbott (1421) 2651 posts |
R4 should be the length of the thing R3 points to, which I’m assuming is a string. It’s not the best documentation! |
Chris Mahoney (1684) 2165 posts |
I don’t mean to be argumentative, but are you sure? Side note: It’s a real pity that so many different things return the same error code.
Per the docs (my emphasis): “A session can be configured by calling the Getsockopt or Setsockopt SWIs (after Creat or CreateSession, and before Connect) to alter parameters relating to this specific session.” |
Simon Willcocks (1499) 513 posts |
Are you in a position to re-build the module from source? You could put some different error codes in, temporarily, to narrow down exactly where the error’s coming from. (That code for the length check is odd. I’d have expected it to be checking for a pointer to a const char * pointing at the string, but that’s not the case, either. I’d say it’s a bug.) |
Chris Mahoney (1684) 2165 posts |
I was thinking about that, but decided that asking the question would be easier :)
If so, it’s probably an old bug that’s had to be retained for API compatibility. |
Sprow (202) 1158 posts |
I think you’re trying to be too smart and inlining with Take a look at the first bullet point in the section In-line SWI Functions in the Acorn C/C++ manual, then count how many arguments your
Yes, the optval is a pointer to a string, therefore optlen is the size of a pointer to a string, which is 4 currently. |
Chris Mahoney (1684) 2165 posts |
AHA! Thanks :) Next is to figure out why I’m getting a handshake error, but that can keep until later. (Edit: Resolved). |