diff --git a/include/ZeroTierSockets.h b/include/ZeroTierSockets.h index ec196a6..fe01d43 100644 --- a/include/ZeroTierSockets.h +++ b/include/ZeroTierSockets.h @@ -200,7 +200,7 @@ typedef enum { extern int zts_errno; typedef enum { - /** Operation not permitted (`zts_errno` value) */ + /** Operation not permitted */ ZTS_EPERM = 1, /** No such file or directory */ ZTS_ENOENT = 2, @@ -278,6 +278,8 @@ typedef enum { ZTS_ENOTCONN = 107, /** Connection timed out */ ZTS_ETIMEDOUT = 110, + /* Connection refused */ + ZTS_ECONNREFUSED = 111, /** No route to host */ ZTS_EHOSTUNREACH = 113, /** Operation already in progress */ diff --git a/src/bindings/python/libzt.py b/src/bindings/python/libzt.py index 57f2376..6f027ea 100755 --- a/src/bindings/python/libzt.py +++ b/src/bindings/python/libzt.py @@ -158,6 +158,7 @@ ZTS_ENOBUFS = _libzt.ZTS_ENOBUFS ZTS_EISCONN = _libzt.ZTS_EISCONN ZTS_ENOTCONN = _libzt.ZTS_ENOTCONN ZTS_ETIMEDOUT = _libzt.ZTS_ETIMEDOUT +ZTS_ECONNREFUSED = _libzt.ZTS_ECONNREFUSED ZTS_EHOSTUNREACH = _libzt.ZTS_EHOSTUNREACH ZTS_EALREADY = _libzt.ZTS_EALREADY ZTS_EINPROGRESS = _libzt.ZTS_EINPROGRESS diff --git a/src/bindings/python/sockets.py b/src/bindings/python/sockets.py index dd655c8..5f51591 100755 --- a/src/bindings/python/sockets.py +++ b/src/bindings/python/sockets.py @@ -6,6 +6,27 @@ import libzt def handle_error(err): """Convert libzt error code to exception""" if err == libzt.ZTS_ERR_SOCKET: + if errno() == libzt.ZTS_EAGAIN: + raise BlockingIOError() + return + if errno() == libzt.ZTS_EINPROGRESS: + raise BlockingIOError() + return + if errno() == libzt.ZTS_EALREADY: + raise BlockingIOError() + return + if errno() == libzt.ZTS_ECONNABORTED: + raise ConnectionAbortedError() + return + if errno() == libzt.ZTS_ECONNREFUSED: + raise ConnectionRefusedError() + return + if errno() == libzt.ZTS_ECONNRESET: + raise ConnectionResetError() + return + if errno() == libzt.ZTS_ETIMEDOUT: + raise TimeoutError() + return raise Exception("ZTS_ERR_SOCKET (" + str(err) + ")") if err == libzt.ZTS_ERR_SERVICE: raise Exception("ZTS_ERR_SERVICE (" + str(err) + ")")