Skip to content

Commit 08e1cdb

Browse files
authored
Merge pull request #7079 from jepler/picow-2xmss
Pico W grab bag
2 parents b56d5d9 + de0dda9 commit 08e1cdb

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

ports/raspberrypi/common-hal/socketpool/Socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ STATIC mp_uint_t lwip_tcp_send(socketpool_socket_obj_t *socket, const byte *buf,
504504
if (err != ERR_MEM) {
505505
break;
506506
}
507+
if (err == ERR_MEM && write_len > TCP_MSS) {
508+
// Decreasing the amount sent to the next lower number of MSS
509+
write_len = (write_len - 1) / TCP_MSS * TCP_MSS;
510+
continue;
511+
}
507512
err = tcp_output(socket->pcb.tcp);
508513
if (err != ERR_OK) {
509514
break;

ports/raspberrypi/common-hal/wifi/Radio.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) {
158158
}
159159

160160
void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) {
161+
cyw43_wifi_leave(&cyw43_state, CYW43_ITF_STA);
162+
// This is wrong, but without this call the state of ITF_STA is still
163+
// reported as CYW43_LINK_JOIN (by wifi_link_status) and CYW43_LINK_UP
164+
// (by tcpip_link_status). Until AP support is added, we can ignore the
165+
// problem.
166+
cyw43_wifi_leave(&cyw43_state, CYW43_ITF_AP);
167+
bindings_cyw43_wifi_enforce_pm();
161168
}
162169

163170
void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode, uint8_t max_connections) {

ports/raspberrypi/lwip_inc/lwipopts.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define LWIP_TCP 1
4848
#define LWIP_UDP 1
4949
#define LWIP_DNS 1
50+
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
5051
#define LWIP_TCP_KEEPALIVE 1
5152
#define LWIP_NETIF_TX_SINGLE_PBUF 1
5253
#define DHCP_DOES_ARP_CHECK 0
@@ -91,4 +92,13 @@
9192

9293
#define LWIP_NO_CTYPE_H 1
9394

95+
#define X8_F "02x"
96+
#define U16_F "u"
97+
#define U32_F "lu"
98+
#define S32_F "ld"
99+
#define X32_F "lx"
100+
101+
#define S16_F "d"
102+
#define X16_F "x"
103+
#define SZT_F "u"
94104
#endif /* __LWIPOPTS_H__ */

shared-bindings/socketpool/Socket.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "py/mperrno.h"
3838

3939
#include "shared/netutils/netutils.h"
40+
#include "shared/runtime/interrupt_char.h"
4041

4142
//| class Socket:
4243
//| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call
@@ -255,6 +256,46 @@ STATIC mp_obj_t _socketpool_socket_send(mp_obj_t self_in, mp_obj_t buf_in) {
255256
}
256257
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_send_obj, _socketpool_socket_send);
257258

259+
//| def sendall(self, bytes: ReadableBuffer) -> None:
260+
//| """Send some bytes to the connected remote address.
261+
//| Suits sockets of type SOCK_STREAM
262+
//|
263+
//| This calls send() repeatedly until all the data is sent or an error
264+
//| occurs. If an error occurs, it's impossible to tell how much data
265+
//| has been sent.
266+
//|
267+
//| :param ~bytes bytes: some bytes to send"""
268+
//| ...
269+
STATIC mp_obj_t _socketpool_socket_sendall(mp_obj_t self_in, mp_obj_t buf_in) {
270+
socketpool_socket_obj_t *self = MP_OBJ_TO_PTR(self_in);
271+
if (common_hal_socketpool_socket_get_closed(self)) {
272+
// Bad file number.
273+
mp_raise_OSError(MP_EBADF);
274+
}
275+
if (!common_hal_socketpool_socket_get_connected(self)) {
276+
mp_raise_BrokenPipeError();
277+
}
278+
mp_buffer_info_t bufinfo;
279+
mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ);
280+
while (bufinfo.len > 0) {
281+
mp_int_t ret = common_hal_socketpool_socket_send(self, bufinfo.buf, bufinfo.len);
282+
if (ret == -1) {
283+
mp_raise_BrokenPipeError();
284+
}
285+
bufinfo.len -= ret;
286+
bufinfo.buf += ret;
287+
if (bufinfo.len > 0) {
288+
RUN_BACKGROUND_TASKS;
289+
// Allow user to break out of sendall with a KeyboardInterrupt.
290+
if (mp_hal_is_interrupted()) {
291+
return 0;
292+
}
293+
}
294+
}
295+
return mp_const_none;
296+
}
297+
STATIC MP_DEFINE_CONST_FUN_OBJ_2(socketpool_socket_sendall_obj, _socketpool_socket_sendall);
298+
258299
//| def sendto(self, bytes: ReadableBuffer, address: Tuple[str, int]) -> int:
259300
//| """Send some bytes to a specific address.
260301
//| Suits sockets of type SOCK_DGRAM
@@ -372,6 +413,7 @@ STATIC const mp_rom_map_elem_t socketpool_socket_locals_dict_table[] = {
372413
{ MP_ROM_QSTR(MP_QSTR_recvfrom_into), MP_ROM_PTR(&socketpool_socket_recvfrom_into_obj) },
373414
{ MP_ROM_QSTR(MP_QSTR_recv_into), MP_ROM_PTR(&socketpool_socket_recv_into_obj) },
374415
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&socketpool_socket_send_obj) },
416+
{ MP_ROM_QSTR(MP_QSTR_sendall), MP_ROM_PTR(&socketpool_socket_sendall_obj) },
375417
{ MP_ROM_QSTR(MP_QSTR_sendto), MP_ROM_PTR(&socketpool_socket_sendto_obj) },
376418
{ MP_ROM_QSTR(MP_QSTR_setblocking), MP_ROM_PTR(&socketpool_socket_setblocking_obj) },
377419
// { MP_ROM_QSTR(MP_QSTR_setsockopt), MP_ROM_PTR(&socketpool_socket_setsockopt_obj) },

0 commit comments

Comments
 (0)