summaryrefslogtreecommitdiff
path: root/unix/modsocket.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-21 23:58:39 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-22 00:02:51 +0300
commit5d3a83017125175ef82d6f7a5c969f528e8f748a (patch)
tree030229443f9b4ae999420e77da8a4a23f7504011 /unix/modsocket.c
parentacb13886fc837a1bb950d6298c666d29eb2891fc (diff)
modsocket: Clean up OSError-like exception a bit.
Some BSD socket functions don't return error numbers in errno namespace, but rather in other error namespaces. CPython resolves this by using OSError subclasses for them. We don't do that so far, so there's ambiguity here.
Diffstat (limited to 'unix/modsocket.c')
-rw-r--r--unix/modsocket.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/unix/modsocket.c b/unix/modsocket.c
index 0d4511165..567bf5c9b 100644
--- a/unix/modsocket.c
+++ b/unix/modsocket.c
@@ -269,7 +269,7 @@ STATIC mp_obj_t mod_socket_inet_aton(mp_obj_t arg) {
const char *s = mp_obj_str_get_str(arg);
struct in_addr addr;
if (!inet_aton(s, &addr)) {
- nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Invalid IP address"));
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(EINVAL)));
}
return mp_obj_new_int(addr.s_addr);
@@ -282,7 +282,8 @@ STATIC mp_obj_t mod_socket_gethostbyname(mp_obj_t arg) {
const char *s = mp_obj_str_get_str(arg);
struct hostent *h = gethostbyname(s);
if (h == NULL) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[Errno %d]", errno));
+ // CPython: socket.herror
+ nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(h_errno)));
}
assert(h->h_length == 4);
return mp_obj_new_int(*(int*)*h->h_addr_list);
@@ -314,6 +315,7 @@ STATIC mp_obj_t mod_socket_getaddrinfo(uint n_args, const mp_obj_t *args) {
int res = getaddrinfo(host, serv, NULL/*&hints*/, &addr);
if (res != 0) {
+ // CPython: socket.gaierror
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, "[addrinfo error %d]", res));
}
assert(addr);