3434
3535namespace arduino {
3636
37+ #define ETHERNET_DEFAULT_READ_TIMEOUT 200
38+
3739typedef enum {
3840 WL_NO_SHIELD = 255 ,
3941 WL_IDLE_STATUS = 0 ,
@@ -139,14 +141,14 @@ class EthernetClient : public Client {
139141
140142 public:
141143 EthernetClient () {
142- setTimeout (2000 );
144+ setTimeout (ETHERNET_DEFAULT_READ_TIMEOUT );
143145 p_sock = std::make_shared<SocketImpl>();
144146 readBuffer = RingBufferExt (bufferSize);
145147 writeBuffer = RingBufferExt (bufferSize);
146148 registerCleanup ();
147149 active_clients ().push_back (this );
148150 }
149- EthernetClient (std::shared_ptr<SocketImpl> sock, int bufferSize = 256 , long timeout = 2000 ) {
151+ EthernetClient (std::shared_ptr<SocketImpl> sock, int bufferSize = 256 , long timeout = ETHERNET_DEFAULT_READ_TIMEOUT ) {
150152 if (sock) {
151153 setTimeout (timeout);
152154 this ->bufferSize = bufferSize;
@@ -159,7 +161,7 @@ class EthernetClient : public Client {
159161 }
160162 }
161163 EthernetClient (int socket) {
162- setTimeout (2000 );
164+ setTimeout (ETHERNET_DEFAULT_READ_TIMEOUT );
163165 readBuffer = RingBufferExt (bufferSize);
164166 writeBuffer = RingBufferExt (bufferSize);
165167 p_sock = std::make_shared<SocketImpl>(socket);
@@ -170,7 +172,7 @@ class EthernetClient : public Client {
170172 virtual uint8_t connected () override {
171173 if (!is_connected) return false ; // connect has failed
172174 if (p_sock->connected ()) return true ; // check socket
173- long timeout = millis () + getTimeout ();
175+ long timeout = millis () + getConnectionTimeout ();
174176 uint8_t result = p_sock->connected ();
175177 while (result <= 0 && millis () < timeout) {
176178 delay (200 );
@@ -313,8 +315,17 @@ class EthernetClient : public Client {
313315 Logger.error (WIFICLIENT, " setCACert not supported" );
314316 }
315317
318+ void setConnectionTimeout (int32_t timeout) {
319+ connectTimeout = timeout;
320+ }
321+
322+ int32_t getConnectionTimeout () {
323+ return connectTimeout;
324+ }
325+
316326 protected:
317327 const char * WIFICLIENT = " EthernetClient" ;
328+ int32_t connectTimeout = 5000 ; // default timeout 5 seconds
318329 std::shared_ptr<SocketImpl> p_sock = nullptr ;
319330 int bufferSize = 256 ;
320331 RingBufferExt readBuffer;
0 commit comments