|
89 | 89 | SNSR_SOCK_ESTABLISHED = const(0x17)
|
90 | 90 | SNSR_SOCK_FIN_WAIT = const(0x18)
|
91 | 91 | _SNSR_SOCK_CLOSING = const(0x1A)
|
92 |
| -_SNSR_SOCK_TIME_WAIT = const(0x1B) |
93 |
| -_SNSR_SOCK_CLOSE_WAIT = const(0x1C) |
| 92 | +SNSR_SOCK_TIME_WAIT = const(0x1B) |
| 93 | +SNSR_SOCK_CLOSE_WAIT = const(0x1C) |
94 | 94 | _SNSR_SOCK_LAST_ACK = const(0x1D)
|
95 | 95 | _SNSR_SOCK_UDP = const(0x22)
|
96 | 96 | _SNSR_SOCK_IPRAW = const(0x32)
|
@@ -260,7 +260,9 @@ def get_host_by_name(self, hostname: str) -> bytes:
|
260 | 260 | if isinstance(hostname, str):
|
261 | 261 | hostname = bytes(hostname, "utf-8")
|
262 | 262 | # Return IP assigned by DHCP
|
263 |
| - _dns_client = dns.DNS(self, self._dns, debug=self._debug) |
| 263 | + _dns_client = dns.DNS( |
| 264 | + self, self.pretty_ip(bytearray(self._dns)), debug=self._debug |
| 265 | + ) |
264 | 266 | ret = _dns_client.gethostbyname(hostname)
|
265 | 267 | debug_msg("* Resolved IP: {}".format(ret), self._debug)
|
266 | 268 | if ret == -1:
|
@@ -817,9 +819,9 @@ def socket_open(self, socket_num: int, conn_mode: int = _SNMR_TCP) -> int:
|
817 | 819 | status = self.read_snsr(socket_num)[0]
|
818 | 820 | if status in (
|
819 | 821 | SNSR_SOCK_CLOSED,
|
820 |
| - _SNSR_SOCK_TIME_WAIT, |
| 822 | + SNSR_SOCK_TIME_WAIT, |
821 | 823 | SNSR_SOCK_FIN_WAIT,
|
822 |
| - _SNSR_SOCK_CLOSE_WAIT, |
| 824 | + SNSR_SOCK_CLOSE_WAIT, |
823 | 825 | _SNSR_SOCK_CLOSING,
|
824 | 826 | _SNSR_SOCK_UDP,
|
825 | 827 | ):
|
@@ -897,7 +899,7 @@ def socket_read(self, socket_num: int, length: int) -> Tuple[int, bytes]:
|
897 | 899 | if ret == 0:
|
898 | 900 | # no data on socket?
|
899 | 901 | status = self._read_snmr(socket_num)
|
900 |
| - if status in (SNSR_SOCK_LISTEN, SNSR_SOCK_CLOSED, _SNSR_SOCK_CLOSE_WAIT): |
| 902 | + if status in (SNSR_SOCK_LISTEN, SNSR_SOCK_CLOSED, SNSR_SOCK_CLOSE_WAIT): |
901 | 903 | # remote end closed its side of the connection, EOF state
|
902 | 904 | raise RuntimeError("Lost connection to peer.")
|
903 | 905 | # connection is alive, no data waiting to be read
|
@@ -993,7 +995,7 @@ def socket_write(
|
993 | 995 | while free_size < ret:
|
994 | 996 | free_size = self._get_tx_free_size(socket_num)
|
995 | 997 | status = self.socket_status(socket_num)[0]
|
996 |
| - if status not in (SNSR_SOCK_ESTABLISHED, _SNSR_SOCK_CLOSE_WAIT) or ( |
| 998 | + if status not in (SNSR_SOCK_ESTABLISHED, SNSR_SOCK_CLOSE_WAIT) or ( |
997 | 999 | timeout and time.monotonic() - stamp > timeout
|
998 | 1000 | ):
|
999 | 1001 | ret = 0
|
@@ -1032,18 +1034,18 @@ def socket_write(
|
1032 | 1034 | time.sleep(0.001)
|
1033 | 1035 |
|
1034 | 1036 | # check data was transferred correctly
|
1035 |
| - while not self._read_snir(socket_num)[0] & _SNIR_SEND_OK: |
| 1037 | + while not self.read_snir(socket_num)[0] & _SNIR_SEND_OK: |
1036 | 1038 | if self.socket_status(socket_num)[0] in (
|
1037 | 1039 | SNSR_SOCK_CLOSED,
|
1038 |
| - _SNSR_SOCK_TIME_WAIT, |
| 1040 | + SNSR_SOCK_TIME_WAIT, |
1039 | 1041 | SNSR_SOCK_FIN_WAIT,
|
1040 |
| - _SNSR_SOCK_CLOSE_WAIT, |
| 1042 | + SNSR_SOCK_CLOSE_WAIT, |
1041 | 1043 | _SNSR_SOCK_CLOSING,
|
1042 | 1044 | ):
|
1043 | 1045 | raise RuntimeError("Socket closed before data was sent.")
|
1044 | 1046 | if timeout and time.monotonic() - stamp > timeout:
|
1045 | 1047 | raise RuntimeError("Operation timed out. No data sent.")
|
1046 |
| - if self._read_snir(socket_num)[0] & _SNIR_TIMEOUT: |
| 1048 | + if self.read_snir(socket_num)[0] & _SNIR_TIMEOUT: |
1047 | 1049 | raise TimeoutError(
|
1048 | 1050 | "Hardware timeout while sending on socket {}.".format(socket_num)
|
1049 | 1051 | )
|
@@ -1127,7 +1129,7 @@ def read_snsr(self, sock: int) -> Optional[bytearray]:
|
1127 | 1129 | """Read Socket n Status Register."""
|
1128 | 1130 | return self._read_socket(sock, _REG_SNSR)
|
1129 | 1131 |
|
1130 |
| - def _read_snir(self, sock: int) -> Optional[bytearray]: |
| 1132 | + def read_snir(self, sock: int) -> Optional[bytearray]: |
1131 | 1133 | """Read Socket n Interrupt Register."""
|
1132 | 1134 | return self._read_socket(sock, _REG_SNIR)
|
1133 | 1135 |
|
|
0 commit comments