Skip to content

Commit baf6532

Browse files
authored
Merge branch 'micropython:master' into master
2 parents 9ef5766 + ea21cb3 commit baf6532

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

python-ecosys/iperf3/iperf3.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@
1212
iperf3.client('192.168.1.5', udp=True, reverse=True)
1313
"""
1414

15-
import sys, os, struct
15+
import sys, struct
1616
import time, select, socket
1717
import json
1818

19+
# Provide a urandom() function, supporting devices without os.urandom().
20+
try:
21+
from os import urandom
22+
except ImportError:
23+
from random import randint
24+
25+
def urandom(n):
26+
return bytes(randint(0, 255) for _ in range(n))
27+
28+
1929
DEBUG = False
2030

2131
# iperf3 cookie size, last byte is null byte
@@ -177,7 +187,7 @@ def recvninto(s, buf):
177187
def make_cookie():
178188
cookie_chars = b"abcdefghijklmnopqrstuvwxyz234567"
179189
cookie = bytearray(COOKIE_SIZE)
180-
for i, x in enumerate(os.urandom(COOKIE_SIZE - 1)):
190+
for i, x in enumerate(urandom(COOKIE_SIZE - 1)):
181191
cookie[i] = cookie_chars[x & 31]
182192
return cookie
183193

@@ -243,7 +253,7 @@ def server_once():
243253
stats = Stats(param)
244254
stats.start()
245255
running = True
246-
data_buf = bytearray(os.urandom(param["len"]))
256+
data_buf = bytearray(urandom(param["len"]))
247257
while running:
248258
for pollable in poll.poll(stats.max_dt_ms()):
249259
if pollable_is_sock(pollable, s_ctrl):
@@ -445,7 +455,7 @@ def client(host, udp=False, reverse=False, bandwidth=10 * 1024 * 1024):
445455
s_data = socket.socket(ai[0], socket.SOCK_STREAM)
446456
s_data.connect(ai[-1])
447457
s_data.sendall(cookie)
448-
buf = bytearray(os.urandom(param["len"]))
458+
buf = bytearray(urandom(param["len"]))
449459
elif cmd == EXCHANGE_RESULTS:
450460
# Close data socket now that server knows we are finished, to prevent it flooding us
451461
poll.unregister(s_data)

python-ecosys/iperf3/manifest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
metadata(version="0.1.3")
2+
13
module("iperf3.py")

0 commit comments

Comments
 (0)