Socket: Connection closed before sending all data

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Socket: Connection closed before sending all data

ricardoschoof
When making a basic http server (listen -> accept -> send basic html
repsonse), I get an error when receiving a lot of data (~100k).

Firefox "The connection was reset"
Edge just show the data partially
Telnet won't show all the data, and get a "Connection to host
lost."-message.

I expect the application (since BSD style sockets are blocking) to send the
data before returning, and thereafter close the connection.
When sending smaller amounts of data (~70 bytes) this won't happen. It looks
like the socket are closed before sending the last data / receiving the last
ack. I have attached the wireshark capture.

My set up: STM32H7, FreeRTOS 10.2.0, LWIP 2.1.2

Ricardo Schoof

Code:
static void http_handler( void* pvParams ){
  const unsigned char* HTTP_RESPONSE="HTTP/1.0 200 OK\r\nContent-Type:
text/html\r\n\r\n<div id='lipsum'><p>Lorem[...]"; [extended to 101321 bytes
of data]
  const size_t send_length = strlen ((const char*)HTTP_RESPONSE) + 1;
 
  int list_sock = 0, client_sock = 0;
  struct sockaddr_in sLocalAddr;

  list_sock = socket(AF_INET, SOCK_STREAM, 0);
 
  sLocalAddr.sin_family = AF_INET;
  sLocalAddr.sin_len = sizeof(sLocalAddr);
  sLocalAddr.sin_addr.s_addr = 0;
  sLocalAddr.sin_port = ntohs((int) pvParams);
 
 
  if (bind (list_sock, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) <
0)
    http_err();
 
  if ( lwip_listen(list_sock, 5) != 0 ){
    lwip_close(list_sock);
    http_err();
  }
 
  for (;;)
  {
    struct sockaddr_in client_addr;
    int addrlen=sizeof(client_addr);
   
    client_sock =   lwip_accept(list_sock, (struct sockaddr*)&client_addr,
(socklen_t*)&addrlen);
    if (client_sock>0){
      lwip_send(client_sock, HTTP_RESPONSE, send_length, 0);
      lwip_close(client_sock);
    }
  }




--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Socket: Connection closed before sending all data

goldsimon@gmx.de
Am 21.05.2019 um 08:59 schrieb ricardoschoof:

> When making a basic http server (listen -> accept -> send basic html
> repsonse), I get an error when receiving a lot of data (~100k).
>
> Firefox "The connection was reset"
> Edge just show the data partially
> Telnet won't show all the data, and get a "Connection to host
> lost."-message.
>
> I expect the application (since BSD style sockets are blocking) to send the
> data before returning, and thereafter close the connection.

Send data before returning from *what*? Because the default is that it
doesn't wait. You can make it wait by enbling SO_LINGER, I think. Have
you cross-checked the behaviour of Linux or another stack?

 > [..]

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: Socket: Connection closed before sending all data

ricardoschoof
[hidden email] wrote
> Send data before returning from *what*?

Returning out of the lwip_send function. I have read on several sources that
the bsd sockets were blocking (for instance here:
https://lwip.fandom.com/wiki/Application_API_layers )


[hidden email] wrote
> Send data before returning from *what*? Because the default is that it
> doesn't wait. You can make it wait by enbling SO_LINGER, I think. Have
> you cross-checked the behaviour of Linux or another stack?

When enabling linger (and adding shutdown), I get the page fully loaded.

It appears to be a wrong expectation of my side once again, write() seems to
be blocking untill all data was queued, instead of sent.



--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users