Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 1099:3dd7b8255619 legacy-trunk
socketmodule.c: added socket.fromfd(fd, family, type, [proto]);
converted socket() to use of getargs().
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 08 Dec 1992 13:38:24 +0000 |
| parents | d2af6bdcb6d0 |
| children | 6461dac9a9f2 |
line wrap: on
line diff
--- a/Modules/socketmodule.c Fri Nov 27 22:54:49 1992 +0000 +++ b/Modules/socketmodule.c Tue Dec 08 13:38:24 1992 +0000 @@ -933,16 +933,13 @@ object *args; { sockobject *s; - int family, type, proto, fd; - if (args != NULL && is_tupleobject(args) && gettuplesize(args) == 3) { - if (!getintintintarg(args, &family, &type, &proto)) + int fd, family, type, proto; + proto = 0; + if (!getargs(args, "(ii)", &family, &type)) { + err_clear(); + if (!getargs(args, "(iii)", &family, &type, &proto)) return NULL; } - else { - if (!getintintarg(args, &family, &type)) - return NULL; - proto = 0; - } BGN_SAVE fd = socket(family, type, proto); END_SAVE @@ -960,6 +957,32 @@ } +/* Create a socket object from a numeric file description. + Useful e.g. if stdin is a socket. + Additional arguments as for socket(). */ + +/*ARGSUSED*/ +static object * +socket_fromfd(self, args) + object *self; + object *args; +{ + sockobject *s; + int fd, family, type, proto; + proto = 0; + if (!getargs(args, "(iii)", &fd, &family, &type)) { + err_clear(); + if (!getargs(args, "(iiii)", &fd, &family, &type, &proto)) + return NULL; + } + s = newsockobject(fd, family, type, proto); + /* From now on, ignore SIGPIPE and let the error checking + do the work. */ + (void) signal(SIGPIPE, SIG_IGN); + return (object *) s; +} + + /* List of functions exported by this module. */ static struct methodlist socket_methods[] = { @@ -967,6 +990,7 @@ {"gethostname", socket_gethostname}, {"getservbyname", socket_getservbyname}, {"socket", socket_socket}, + {"fromfd", socket_fromfd}, {NULL, NULL} /* Sentinel */ };
