[Python-Dev] Re: [Python-checkins] python/dist/src/Modules socketmodule.c, 1.298, 1.299 (original) (raw)
Neal Norwitz neal at metaslash.com
Fri Aug 20 04:09:19 CEST 2004
- Previous message: [Python-Dev] Re: PEP 318 has ReST errors
- Next message: [Python-Dev] Re: [Python-checkins] python/dist/src/Modules socketmodule.c, 1.298, 1.299
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message: Patch #1003700: Add socketpair function to socket module.
Index: socketmodule.c
+ #ifdef HAVESOCKETPAIR + /* Create a pair of sockets using the socketpair() function. + Arguments as for socket(). */ + + /ARGSUSED/ + static PyObject * + socketsocketpair(PyObject *self, PyObject *args) + { + PySocketSockObject *s0 = NULL, *s1 = NULL; + SOCKETT sv[2]; + int family, type = SOCKSTREAM, proto = 0; + PyObject *res = NULL; + + #if defined(AFUNIX) + family = AFUNIX; + #else + family = AFINET; + #endif
The docstring (below) states the arguments are the same as socket(). However, in sock_initobj() line 2496, the family is initialized to AF_INET. I think the #if defined(AF_UNIX) code above should be removed and family should be initialized to AF_INET.
I didn't look to see if the documentation agrees with the docstring.
+ if (!PyArgParseTuple(args, "|iii:socketpair", + &family, &type, &proto)) + return NULL; + /* Create a pair of socket fds */ + if (socketpair(family, type, proto, sv) < 0) + return seterror(); + #ifdef SIGPIPE + (void) signal(SIGPIPE, SIGIGN); + #endif
I don't think the #ifdef SIGPIPE code is correct. If the user installed a signal handler calling signal() will remove it. I think the call to signal() should be removed.
Neal
+ s0 = newsockobject(sv[0], family, type, proto); + if (s0 == NULL) + goto finally; + s1 = newsockobject(sv[1], family, type, proto); + if (s1 == NULL) + goto finally; + res = PyTuplePack(2, s0, s1); + + finally: + if (res == NULL) { + if (s0 == NULL) + SOCKETCLOSE(sv[0]); + if (s1 == NULL) + SOCKETCLOSE(sv[1]); + } + PyXDECREF(s0); + PyXDECREF(s1); + return res; + } + + PyDocSTRVAR(socketpairdoc, _+ "socketpair([family[, type[, proto]]]) -> (socket object, socket object)\n_ _+ \n_ _+ Create a pair of socket objects from the sockets returned by the platform\n_ _+ socketpair() function.\n_ + The arguments are the same as for socket()."); + + #endif /* HAVESOCKETPAIR */
- Previous message: [Python-Dev] Re: PEP 318 has ReST errors
- Next message: [Python-Dev] Re: [Python-checkins] python/dist/src/Modules socketmodule.c, 1.298, 1.299
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]