9 years, 11 months ago.

polling blocks the main loop

I use this testsample:

while (true) {
        pc.printf("\nWait for new connection...\n");
        TCPSocketConnection client;
        server.accept(client);
        client.set_blocking(false, 1500); // Timeout after (1.5)s
 
        pc.printf("Connection from: %s\n", client.get_address());
        char buffer[256];
        while (true) {
            int n = client.receive(buffer, sizeof(buffer));
            if (n <= 0) break;
 
            client.send_all(buffer, n);
            if (n <= 0) break;
        }
 
        client.close();
    }
}

In this line ( server.accept(client); , it waits until the client sends data. Serial output:

StartInitialized, MAC: 00:02:F7:F0:00:00
IP: 192.168.0.120, MASK: 255.255.255.0, GW: 192.168.0.200
Wait for new connection...

This is not usefull, because the cpu is still doing other things It would be better to query whether data are to be collected. This is the code template with the arduino lib with non blocking:

// listen for incoming clients
  EthernetClient client = server.available();

  if (client) {
    
    //Serial.println("new client");

        while (client.connected()) {
      if (client.available()) {
        char c = client.read();
       ....  

Question relating to:

This is WIZnet Ethernet Interface using Hardware TCP/IP chip, W5500, W5200 and W5100. One of them can be selected by enabling it in wiznet.h. ethernet, tcp/ip, w5100, W5200, W5500, Wiznet
Be the first to answer this question.