Function size_t EthernetClient::write(const uint8_t *buf, size_t size) always returns 0. Even in case that it should return size.
http://www.stm32duino.com/viewtopic.php?t=692
but I had thought the issues were resolved. I have personally not run Ethernet on the STM32 Maple Mini, so maybe someone else will step-up and advise with deeper insight.
Ray
But because function size_t EthernetClient::write(const uint8_t *buf, size_t size) always returns 0 I cannot make chunks…
Only I can send bigger package at once. But it is not right solution…
any other way of detecting an incorrect or bad write?
stephen
while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
size_t sent = _currentClient.write(send_start, will_send);
// if (sent == 0) {
// break;
// }
// size_to_send -= sent;
// send_start += sent;
size_to_send -= will_send;
send_start += will_send;
}
It works.
Anyway webserver is more slugish than those from ESP8266.
zmemw16: no word undertand
void stm32WebServer::sendContent(const String& content) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;//HTTP_DOWNLOAD_UNIT_SIZE = 1460, tested with different size
size_t size_to_send = content.length();
const char* send_start = content.c_str();
while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
size_t sent = _currentClient.write(send_start, will_send);
// if (sent == 0) {
// break;
// }
// size_to_send -= sent;
// send_start += sent;
size_to_send -= will_send;
send_start += will_send;
}
}
<cringe></cringe> is me waiting for the torrent of ‘that’s naughty’ comments
stephen
Are you using the W5x00 implementation from Serasidis under F1 ?
Problem is somewhere deeper:
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
if (_sock == MAX_SOCK_NUM) {
setWriteError();
return 0;
}
if (!send(_sock, buf, size)) {
setWriteError();
return 0;
}
return size;
}
It should be in function send(…). Chunks have been sent but function returns 0.
Also looking at the EthernetClient.cpp that you provide code, I don’t think the call to send(), it still handling it as boolean.
if (!send(_sock, buf, size)) {
extern int sudaint,sudaint1;//global variables iniatialiset to -1
void stm32WebServer::sendContent(const String& content) {
const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
size_t size_to_send = content.length();
const char* send_start = content.c_str();
while (size_to_send) {
size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
sudaint=sudaint>(int)will_send?sudaint:(int)will_send;
size_t sent = _currentClient.write(send_start, will_send);
sudaint1=sudaint1>(int)sent?sudaint1:(int)sent;
if (sent == 0) {
break;
}
size_to_send -= sent;
send_start += sent;
}
}
After one WEB request (in my case it is 7 calls of write function) result:
sudaint = 1980
sudaint1 = 0
The same request with tracking variables in EthernetClient.cpp (hardware\Arduino_STM32\STM32F1\libraries\Ethernet_STM\src\)
extern int sudaint;
size_t EthernetClient::write(const uint8_t *buf, size_t size) {
sudaint=sudaint>(int)size?sudaint:(int)size;
if (_sock == MAX_SOCK_NUM) {
setWriteError();
return 0;
}
if (send(_sock, buf, size) == 0) {//this is already corrected – see communication above!!!!!
setWriteError();
return 0;
}
return size;
}
result:
sudaint = 1
It seems like there exists more EthernetClient sources.
EthernetClient::write(const uint8_t *buf, size_t size) is not the same function like i call in my stm32WebServer::sendContent(const String& content) function…correction with
if (send(_sock, buf, size) == 0) {//this is already corrected – see communication above!!!!!
setWriteError();
return 0;
}
I made only on EthernetClient.cpp (hardware\Arduino_STM32\STM32F1\libraries\Ethernet_STM\src\)
It seems like there exists more EthernetClient sources.
extern int sudaint,sudaint1;//global variables iniatialiset to -1

Content of these sudaint and sudaint1 variables I am reading from ETHERNET already through just developed stm32WebServer

Why are you using those if the STM3 has already a virtual SerialUSB class.