Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6e451df8
Kaydet (Commit)
6e451df8
authored
Agu 09, 2010
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
and make it return the file descriptor.
üst
30e86a47
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
24 deletions
+29
-24
socket.rst
Doc/library/socket.rst
+9
-8
3.2.rst
Doc/whatsnew/3.2.rst
+1
-1
ssl.py
Lib/ssl.py
+1
-1
test_socket.py
Lib/test/test_socket.py
+9
-5
NEWS
Misc/NEWS
+1
-1
socketmodule.c
Modules/socketmodule.c
+8
-8
No files found.
Doc/library/socket.rst
Dosyayı görüntüle @
6e451df8
...
...
@@ -538,6 +538,15 @@ correspond to Unix system calls applicable to sockets.
connects.
.. method:: socket.detach()
Put the socket object into closed state without actually closing the
underlying file descriptor. The file descriptor is returned, and can
be reused for other purposes.
.. versionadded:: 3.2
.. method:: socket.fileno()
Return the socket's file descriptor (a small integer). This is useful with
...
...
@@ -548,14 +557,6 @@ correspond to Unix system calls applicable to sockets.
this limitation.
.. method:: socket.forget()
Put the socket object into closed state without actually closing the
underlying file descriptor. This allows the latter to be reused.
.. versionadded:: 3.2
.. method:: socket.getpeername()
Return the remote address to which the socket is connected. This is useful to
...
...
Doc/whatsnew/3.2.rst
Dosyayı görüntüle @
6e451df8
...
...
@@ -136,7 +136,7 @@ New, Improved, and Deprecated Modules
(Contributed by Tarek Ziadé.)
* Socket objects now have a :meth:`~socket.socket.
forget
()` method which
* Socket objects now have a :meth:`~socket.socket.
detach
()` method which
puts the socket into closed state without actually closing the underlying
file descriptor. The latter can then be reused for other purposes.
...
...
Lib/ssl.py
Dosyayı görüntüle @
6e451df8
...
...
@@ -157,7 +157,7 @@ class SSLSocket(socket):
raise
else
:
connected
=
True
sock
.
forget
()
sock
.
detach
()
elif
fileno
is
not
None
:
socket
.
__init__
(
self
,
fileno
=
fileno
)
else
:
...
...
Lib/test/test_socket.py
Dosyayı görüntüle @
6e451df8
...
...
@@ -655,17 +655,21 @@ class BasicTCPTest(SocketConnectedTest):
self
.
serv_conn
.
send
(
MSG
)
self
.
serv_conn
.
shutdown
(
2
)
def
testForget
(
self
):
# Testing forget()
f
=
self
.
cli_conn
.
fileno
()
self
.
cli_conn
.
forget
()
def
testDetach
(
self
):
# Testing detach()
fileno
=
self
.
cli_conn
.
fileno
()
f
=
self
.
cli_conn
.
detach
()
self
.
assertEqual
(
f
,
fileno
)
# cli_conn cannot be used anymore...
self
.
assertRaises
(
socket
.
error
,
self
.
cli_conn
.
recv
,
1024
)
self
.
cli_conn
.
close
()
# ...but we can create another socket using the (still open)
# file descriptor
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
fileno
=
f
)
msg
=
sock
.
recv
(
1024
)
self
.
assertEqual
(
msg
,
MSG
)
def
_test
Forget
(
self
):
def
_test
Detach
(
self
):
self
.
serv_conn
.
send
(
MSG
)
@unittest.skipUnless
(
thread
,
'Threading required for this test.'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
6e451df8
...
...
@@ -30,7 +30,7 @@ Core and Builtins
Extensions
----------
- Issue #8524: Add a
forget
() method to socket objects, so as to put the
- Issue #8524: Add a
detach
() method to socket objects, so as to put the
socket into the closed state without closing the underlying file
descriptor.
...
...
Modules/socketmodule.c
Dosyayı görüntüle @
6e451df8
...
...
@@ -1870,19 +1870,19 @@ PyDoc_STRVAR(close_doc,
Close the socket. It cannot be used after this call."
);
static
PyObject
*
sock_
forget
(
PySocketSockObject
*
s
)
sock_
detach
(
PySocketSockObject
*
s
)
{
SOCKET_T
fd
=
s
->
sock_fd
;
s
->
sock_fd
=
-
1
;
Py_INCREF
(
Py_None
);
return
Py_None
;
return
PyLong_FromSocket_t
(
fd
);
}
PyDoc_STRVAR
(
forget
_doc
,
"
forget
()
\n
\
PyDoc_STRVAR
(
detach
_doc
,
"
detach
()
\n
\
\n
\
Close the socket object without closing the underlying file descriptor.\
The object cannot be used after this call, but the file descriptor\
can be reused for other purposes."
);
can be reused for other purposes.
The file descriptor is returned.
"
);
static
int
internal_connect
(
PySocketSockObject
*
s
,
struct
sockaddr
*
addr
,
int
addrlen
,
...
...
@@ -2772,10 +2772,10 @@ static PyMethodDef sock_methods[] = {
connect_doc
},
{
"connect_ex"
,
(
PyCFunction
)
sock_connect_ex
,
METH_O
,
connect_ex_doc
},
{
"detach"
,
(
PyCFunction
)
sock_detach
,
METH_NOARGS
,
detach_doc
},
{
"fileno"
,
(
PyCFunction
)
sock_fileno
,
METH_NOARGS
,
fileno_doc
},
{
"forget"
,
(
PyCFunction
)
sock_forget
,
METH_NOARGS
,
forget_doc
},
#ifdef HAVE_GETPEERNAME
{
"getpeername"
,
(
PyCFunction
)
sock_getpeername
,
METH_NOARGS
,
getpeername_doc
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment