diff options
author | Fraser Adams <fraser.adams@blueyonder.co.uk> | 2014-06-06 18:04:33 +0100 |
---|---|---|
committer | Fraser Adams <fraser.adams@blueyonder.co.uk> | 2014-06-06 18:04:33 +0100 |
commit | 5c6e30b71624cd8eaac730ae3202c67006f565c8 (patch) | |
tree | 5f0671c39f347454c1c2b9171eb9e0929389a0dc | |
parent | 4e691c70549f3deead0fe4d6ba6fa4b95f31655d (diff) |
Improve error handling on getsockopt when a level other than SOL_SOCKET or an optname other than SO_ERROR is supplied as per the conversation with juj
-rw-r--r-- | src/library.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/library.js b/src/library.js index 22616335..e71c10a5 100644 --- a/src/library.js +++ b/src/library.js @@ -8319,13 +8319,24 @@ LibraryManager.library = { return -1; } - if (level === {{{ cDefine('SOL_SOCKET') }}} && optname === {{{ cDefine('SO_ERROR') }}}) { - {{{ makeSetValue('optval', 0, 'sock.error', 'i32') }}}; - {{{ makeSetValue('optlen', 0, 4, 'i32') }}}; - sock.error = null; // Clear the error (The SO_ERROR option obtains and then clears this field). - return 0; + if (level === {{{ cDefine('SOL_SOCKET') }}}) { + if (optname === {{{ cDefine('SO_ERROR') }}}) { + {{{ makeSetValue('optval', 0, 'sock.error', 'i32') }}}; + {{{ makeSetValue('optlen', 0, 4, 'i32') }}}; + sock.error = null; // Clear the error (The SO_ERROR option obtains and then clears this field). + return 0; + } else { + ___setErrNo(ERRNO_CODES.ENOPROTOOPT); // The option is unknown at the level indicated. +#if ASSERTIONS + Runtime.warnOnce('getsockopt() returning an error as we currently only support optname SO_ERROR'); +#endif + return -1; + } } else { - ___setErrNo(ERRNO_CODES.EINVAL); + ___setErrNo(ERRNO_CODES.ENOPROTOOPT); //The option is unknown at the level indicated. +#if ASSERTIONS + Runtime.warnOnce('getsockopt() returning an error as we only support level SOL_SOCKET'); +#endif return -1; } }, |