Commit 55d8cba2 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Undo e46c0597, "socket: workaround socket close problem"

ie a commit that worked around our (previous) lack of refcounting.
parent 63668105
......@@ -168,12 +168,6 @@ class _closedsocket(object):
__slots__ = []
def _dummy(*args):
raise error(EBADF, 'Bad file descriptor')
# Pyston change: socket close: add refcounting similar to pypy approach
def _reuse(self):
pass
def _drop(self):
pass
# All _delegate_methods must also be initialized here.
send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy
__getattr__ = _dummy
......@@ -182,9 +176,6 @@ class _closedsocket(object):
# a platform-independent dup() functionality. The
# implementation currently relies on reference counting
# to close the underlying socket object.
# Pyston change: socket close: we workaround the socket closing problem similar to pypy
# by manually keeping track of the ref count.
# When we switch to ref counting we should remove this changes!
class _socketobject(object):
__doc__ = _realsocket.__doc__
......@@ -194,11 +185,6 @@ class _socketobject(object):
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
if _sock is None:
_sock = _realsocket(family, type, proto)
# Pyston change: socket close: add refcounting similar to pypys approach
else:
_sock._reuse()
self._sock = _sock
for method in _delegate_methods:
setattr(self, method, getattr(_sock, method))
......@@ -206,10 +192,6 @@ class _socketobject(object):
def close(self, _closedsocket=_closedsocket,
_delegate_methods=_delegate_methods, setattr=setattr):
# This function should not reference any globals. See issue #808164.
# Pyston change: socket close: add refcounting similar to pypys approach
self._sock._drop()
self._sock = _closedsocket()
dummy = self._sock._dummy
for method in _delegate_methods:
......@@ -218,13 +200,7 @@ class _socketobject(object):
def accept(self):
sock, addr = self._sock.accept()
# Pyston change: socket close: add refcounting similar to pypys approach
# return _socketobject(_sock=sock), addr
sockcopy = _socketobject(_sock=sock)
sock._drop()
return sockcopy, addr
return _socketobject(_sock=sock), addr
accept.__doc__ = _realsocket.accept.__doc__
def dup(self):
......@@ -269,10 +245,6 @@ class _fileobject(object):
def __init__(self, sock, mode='rb', bufsize=-1, close=False):
self._sock = sock
# Pyston change: socket close: add refcounting similar to pypys approach
sock._reuse()
self.mode = mode # Not actually used in this version
if bufsize < 0:
bufsize = self.default_bufsize
......@@ -308,11 +280,6 @@ class _fileobject(object):
finally:
if self._close:
self._sock.close()
# Pyston change: socket close: add refcounting similar to pypys approach
else:
self._sock._drop()
self._sock = None
def __del__(self):
......
......@@ -156,9 +156,6 @@ class SSLSocket(socket):
self.suppress_ragged_eofs = suppress_ragged_eofs
self._makefile_refs = 0
# Pyston change: socket close: we have to decrease the socket refcount by calling close (pypy does the same)
sock.close()
def read(self, len=1024):
"""Read up to LEN bytes and return them.
......@@ -374,21 +371,11 @@ class SSLSocket(socket):
works with the SSL connection. Just use the code
from the socket module."""
# Pyston change: socket close: we increase the refcount inside _fileobject.__init__
# self._makefile_refs += 1
self._makefile_refs += 1
# close=True so as to decrement the reference count when done with
# the file-like object.
return _fileobject(self, mode, bufsize, close=True)
# Pyston change: socket close: add refcounting similar to pypys approach
def _reuse(self):
self._makefile_refs += 1
def _drop(self):
if self._makefile_refs < 1:
self.close()
else:
self._makefile_refs -= 1
def wrap_socket(sock, keyfile=None, certfile=None,
......
......@@ -1200,11 +1200,6 @@ class AbstractHTTPHandler(BaseHandler):
# out of socket._fileobject() and into a base class.
r.recv = r.read
# Pyston change: socket close: add refcounting similar to pypys approach
r._reuse = lambda: None
r._drop = lambda: None
fp = socket._fileobject(r, close=True)
resp = addinfourl(fp, r.msg, req.get_full_url())
......
......@@ -789,9 +789,6 @@ init_sockobject(PySocketSockObject *s,
s->errorhandler = &set_error;
// Pyston change: socket close: add refcounting similar to pypys approach
s->close_ref_count = 1;
if (defaulttimeout >= 0.0)
internal_setblocking(s, 0);
......@@ -2986,21 +2983,6 @@ sock_shutdown(PySocketSockObject *s, PyObject *arg)
return Py_None;
}
// Pyston change: socket close: add refcounting similar to pypys approach
static PyObject *
sock_reuse(PySocketSockObject *s) {
assert(s->close_ref_count > 0);
++s->close_ref_count;
return Py_None;
}
static PyObject *
sock_drop(PySocketSockObject *s) {
--s->close_ref_count;
if (s->close_ref_count <= 0)
sock_close(s);
return Py_None;
}
PyDoc_STRVAR(shutdown_doc,
"shutdown(flag)\n\
\n\
......@@ -3117,11 +3099,6 @@ static PyMethodDef sock_methods[] = {
{"sleeptaskw", (PyCFunction)sock_sleeptaskw, METH_O,
sleeptaskw_doc},
#endif
// Pyston change: socket close: add refcounting similar to pypys approach
{"_reuse", (PyCFunction)sock_reuse, METH_NOARGS, NULL},
{"_drop", (PyCFunction)sock_drop, METH_NOARGS, NULL},
{NULL, NULL} /* sentinel */
};
......
......@@ -132,9 +132,6 @@ typedef struct {
sets a Python exception */
double sock_timeout; /* Operation timeout in seconds;
0.0 means non-blocking */
// Pyston change: socket close: add refcounting similar to pypys approach
int close_ref_count;
} PySocketSockObject;
/* --- C API ----------------------------------------------------*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment