]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
mode and optional bufsize for makefile()
authorGuido van Rossum <guido@python.org>
Tue, 14 Mar 1995 15:05:13 +0000 (15:05 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 14 Mar 1995 15:05:13 +0000 (15:05 +0000)
Modules/socketmodule.c

index a361ca9b33456291da741c1067322f5d4dd158f9..1830fd6e95d52d1293f1246ef10683079e3d7a94 100644 (file)
@@ -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},