diff options
author | Guido van Rossum <guido@python.org> | 1997-11-19 18:57:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-11-19 18:57:13 (GMT) |
commit | fc4255db750bf5387fef62e0446e7d3aebad05f8 (patch) | |
tree | 502be213c074ebd92204f9d8816afae23e556b11 /Modules/socketmodule.c | |
parent | aec7497f6fbd3402507bdf7ec8036aabd7966225 (diff) | |
download | cpython-fc4255db750bf5387fef62e0446e7d3aebad05f8.zip cpython-fc4255db750bf5387fef62e0446e7d3aebad05f8.tar.gz cpython-fc4255db750bf5387fef62e0446e7d3aebad05f8.tar.bz2 |
Add s.connect_ex() which returns errno instead of raising an exception.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r-- | Modules/socketmodule.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 77cf5d1..a225047 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -66,6 +66,7 @@ Socket methods: - s.bind(sockaddr) --> None - s.close() --> None - s.connect(sockaddr) --> None +- s.connect_ex(sockaddr) --> 0 or errno (handy for e.g. async connect) - s.fileno() --> file descriptor - s.dup() --> same as socket.fromfd(os.dup(s.fileno(), ...) - s.getpeername() --> sockaddr @@ -681,6 +682,25 @@ BUILD_FUNC_DEF_2(PySocketSock_connect,PySocketSockObject *,s, PyObject *,args) } +/* s.connect_ex(sockaddr) method */ + +static PyObject * +BUILD_FUNC_DEF_2(PySocketSock_connect_ex,PySocketSockObject *,s, PyObject *,args) +{ + struct sockaddr *addr; + int addrlen; + int res; + if (!getsockaddrarg(s, args, &addr, &addrlen)) + return NULL; + Py_BEGIN_ALLOW_THREADS + res = connect(s->sock_fd, addr, addrlen); + Py_END_ALLOW_THREADS + if (res != 0) + res = errno; + return PyInt_FromLong((long) res); +} + + /* s.fileno() method */ static PyObject * |