diff options
author | Guido van Rossum <guido@python.org> | 1995-03-14 15:05:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-03-14 15:05:13 (GMT) |
commit | 6b14491bb4d0ef0ec7e7dbc8ec60356fae564177 (patch) | |
tree | 327c31449937c7202e4d6291083f6dbe1c8922ed | |
parent | b045afc711e39242603f169ec948b60ba52840c0 (diff) | |
download | cpython-6b14491bb4d0ef0ec7e7dbc8ec60356fae564177.zip cpython-6b14491bb4d0ef0ec7e7dbc8ec60356fae564177.tar.gz cpython-6b14491bb4d0ef0ec7e7dbc8ec60356fae564177.tar.bz2 |
mode and optional bufsize for makefile()
-rw-r--r-- | Modules/socketmodule.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index a361ca9..1830fd6 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -59,7 +59,7 @@ Socket methods: - s.getsockname() --> sockaddr - s.getpeername() --> sockaddr - s.listen(n) --> Py_None -- s.makefile(mode) --> file object +- s.makefile([mode[, bufsize]]) --> file object - s.recv(nbytes [,flags]) --> string - s.recvfrom(nbytes [,flags]) --> string, sockaddr - s.send(string [,flags]) --> nbytes @@ -733,15 +733,24 @@ static PyObject * BUILD_FUNC_DEF_2(PySocketSock_makefile,PySocketSockObject *,s, PyObject *,args) { extern int fclose Py_PROTO((FILE *)); - char *mode; + char *mode = "r"; + int bufsize = -1; int fd; FILE *fp; - if (!PyArg_Parse(args, "s", &mode)) + PyObject *f; + + if (!PyArg_ParseTuple(args, "|si", &mode, &bufsize)) return NULL; if ((fd = dup(s->sock_fd)) < 0 || - (fp = fdopen(fd, mode)) == NULL) + (fp = fdopen(fd, mode)) == NULL) { + if (fd >= 0) + close(fd); return PySocket_Err(); - return PyFile_FromFile(fp, "<socket>", mode, fclose); + } + f = PyFile_FromFile(fp, "<socket>", mode, fclose); + if (f != NULL) + PyFile_SetBufSize(f, bufsize); + return f; } #endif /* NO_DUP */ @@ -900,7 +909,7 @@ static PyMethodDef PySocketSock_methods[] = { #endif {"listen", (PyCFunction)PySocketSock_listen}, #ifndef NO_DUP - {"makefile", (PyCFunction)PySocketSock_makefile}, + {"makefile", (PyCFunction)PySocketSock_makefile, 1}, #endif {"recv", (PyCFunction)PySocketSock_recv}, {"recvfrom", (PyCFunction)PySocketSock_recvfrom}, |