Skip to content

Commit d6c77cd

Browse files
fix check on other platforms
1 parent f090e8d commit d6c77cd

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Lib/asyncio/selector_events.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
HAVE_SENDMSG = hasattr(socket.socket, 'sendmsg')
3434

3535
if HAVE_SENDMSG:
36-
SC_IOV_MAX = os.sysconf('SC_IOV_MAX')
36+
try:
37+
SC_IOV_MAX = os.sysconf('SC_IOV_MAX')
38+
except OSError:
39+
# Fallback to send
40+
HAVE_SENDMSG = False
3741

3842
def _test_selector_event(selector, fd, event):
3943
# Test if the selector is monitoring 'event' events

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
"""Tests for selector_events.py"""
22

33
import collections
4-
import sys
54
import selectors
65
import socket
6+
import sys
77
import unittest
8+
from asyncio import selector_events
89
from unittest import mock
10+
911
try:
1012
import ssl
1113
except ImportError:
1214
ssl = None
1315

1416
import asyncio
15-
from asyncio.selector_events import BaseSelectorEventLoop
16-
from asyncio.selector_events import _SelectorTransport
17-
from asyncio.selector_events import _SelectorSocketTransport
18-
from asyncio.selector_events import _SelectorDatagramTransport
17+
from asyncio.selector_events import (BaseSelectorEventLoop,
18+
_SelectorDatagramTransport,
19+
_SelectorSocketTransport,
20+
_SelectorTransport)
1921
from test.test_asyncio import utils as test_utils
2022

21-
2223
MOCK_ANY = mock.ANY
2324

2425

@@ -746,7 +747,7 @@ def test_write_sendmsg_no_data(self):
746747
self.assertFalse(self.sock.sendmsg.called)
747748
self.assertEqual(list_to_buffer([b'data']), transport._buffer)
748749

749-
@unittest.skipUnless(hasattr(socket.socket, 'sendmsg'), 'no sendmsg')
750+
@unittest.skipUnless(selector_events.HAVE_SENDMSG, 'no sendmsg')
750751
def test_write_sendmsg_full(self):
751752
data = memoryview(b'data')
752753
self.sock.sendmsg = mock.Mock()
@@ -759,7 +760,7 @@ def test_write_sendmsg_full(self):
759760
self.assertTrue(self.sock.sendmsg.called)
760761
self.assertFalse(self.loop.writers)
761762

762-
@unittest.skipUnless(hasattr(socket.socket, 'sendmsg'), 'no sendmsg')
763+
@unittest.skipUnless(selector_events.HAVE_SENDMSG, 'no sendmsg')
763764
def test_write_sendmsg_partial(self):
764765

765766
data = memoryview(b'data')

0 commit comments

Comments
 (0)