diff -Nurp Python-3.2.2/Doc/library/socket.rst Python-3.2.2_new/Doc/library/socket.rst --- Python-3.2.2/Doc/library/socket.rst 2011-09-03 20:16:39.000000000 +0400 +++ Python-3.2.2_new/Doc/library/socket.rst 2011-09-25 20:33:30.000000000 +0400 @@ -618,16 +618,18 @@ correspond to Unix system calls applicab the address family --- see above.) -.. method:: socket.getsockopt(level, optname[, buflen]) +.. method:: socket.getsockopt(level, optname[, optarg]) Return the value of the given socket option (see the Unix man page :manpage:`getsockopt(2)`). The needed symbolic constants (:const:`SO_\*` etc.) are defined in this module. If *buflen* is absent, an integer option is assumed - and its integer value is returned by the function. If *buflen* is present, it - specifies the maximum length of the buffer used to receive the option in, and - this buffer is returned as a bytes object. It is up to the caller to decode the - contents of the buffer (see the optional built-in module :mod:`struct` for a way - to decode C structures encoded as byte strings). + and its integer value is returned by the function. If *buflen* is present and + is a bytes object, it is passed to getsockopt and the return value is a bytes + object of the same length. If *buflen* is an integer, it specifies the maximum + length of the buffer used to receive the option in, and this buffer is returned + as a bytes object. It is up to the caller to decode the contents of the buffer + (see the optional built-in module :mod:`struct` for a way to decode C structures + encoded as byte strings). .. method:: socket.gettimeout() diff -Nurp Python-3.2.2/Modules/socketmodule.c Python-3.2.2_new/Modules/socketmodule.c --- Python-3.2.2/Modules/socketmodule.c 2011-09-03 20:16:47.000000000 +0400 +++ Python-3.2.2_new/Modules/socketmodule.c 2011-09-25 20:38:18.000000000 +0400 @@ -118,7 +118,7 @@ _dup() -- return a new socket fd duplica fileno() -- return underlying file descriptor\n\ getpeername() -- return remote address [*]\n\ getsockname() -- return local address\n\ -getsockopt(level, optname[, buflen]) -- get socket options\n\ +getsockopt(level, optname[, optarg]) -- get socket options\n\ gettimeout() -- return timeout or None\n\ listen(n) -- start listening for incoming connections\n\ recv(buflen[, flags]) -- receive data\n\ @@ -1854,7 +1854,9 @@ The value argument can either be an inte /* s.getsockopt() method. With two arguments, retrieves an integer option. - With a third integer argument, retrieves a string buffer of that size; + With a third integer argument, retrieves a string buffer of that size. + With a third argument as a bytes object, retrieves a buffer of the same + size, using the argument as an input; use optional built-in module 'struct' to decode the string. */ static PyObject * @@ -1865,10 +1867,15 @@ sock_getsockopt(PySocketSockObject *s, P int res; PyObject *buf; socklen_t buflen = 0; + char *inputbuf = (char *)NULL; if (!PyArg_ParseTuple(args, "ii|i:getsockopt", - &level, &optname, &buflen)) - return NULL; + &level, &optname, &buflen)) { + PyErr_Clear(); + if (!PyArg_ParseTuple(args, "iiy#:setsockopt", + &level, &optname, &inputbuf, &buflen)) + return NULL; + } if (buflen == 0) { int flag = 0; @@ -1890,7 +1897,7 @@ sock_getsockopt(PySocketSockObject *s, P "getsockopt buflen out of range"); return NULL; } - buf = PyBytes_FromStringAndSize((char *)NULL, buflen); + buf = PyBytes_FromStringAndSize(inputbuf, buflen); if (buf == NULL) return NULL; res = getsockopt(s->sock_fd, level, optname, @@ -1904,10 +1911,12 @@ sock_getsockopt(PySocketSockObject *s, P } PyDoc_STRVAR(getsockopt_doc, -"getsockopt(level, option[, buffersize]) -> value\n\ +"getsockopt(level, option[, optarg]) -> value\n\ \n\ Get a socket option. See the Unix manual for level and option.\n\ -If a nonzero buffersize argument is given, the return value is a\n\ +If optarg argument is given and is a bytes object, it is passed\n\ +to getsockopt and the return value is a bytes object of the same length.\n\ +If a nonzero integer optarg argument is given, the return value is a\n\ string of that length; otherwise it is an integer.");