pysock: call disable read/write only when needed

This commit is contained in:
Joris Vink 2019-03-14 09:27:13 +01:00
parent d41054bd26
commit 2217c7a2c8
1 changed files with 9 additions and 1 deletions

View File

@ -1657,7 +1657,7 @@ pysocket_alloc(void)
static void
pysocket_dealloc(struct pysocket *sock)
{
if (sock->scheduled) {
if (sock->scheduled && sock->fd == -1) {
kore_platform_disable_read(sock->fd);
#if !defined(__linux__)
kore_platform_disable_write(sock->fd);
@ -1838,6 +1838,14 @@ pysocket_connect(struct pysocket *sock, PyObject *args)
static PyObject *
pysocket_close(struct pysocket *sock, PyObject *args)
{
if (sock->scheduled) {
sock->scheduled = 0;
kore_platform_disable_read(sock->fd);
#if !defined(__linux__)
kore_platform_disable_write(sock->fd);
#endif
}
if (sock->socket != NULL) {
Py_DECREF(sock->socket);
sock->socket = NULL;