client.connect() causing watch dog trip.

I am using a due and an ethernet shield to connect to an SMTP server and send email. My program makes the connection quite easily and sends email when a valid domain name is entered. When an invalid domain name is entered such as "mail.inbox.com" it halts and eventually trips the watchdog.
It's hundreds of lines of code long but the part that hangs up is:

EthernetClient SMTP;

if (SMTP.connect("mail.inbox.com", 25)) {
Serial.println("Connected");
// code to send email
return true;
}
else{
Serial.println("failed to connect")
return false;
}

I have a working DNS configured and like I said it works with a valid smpt server domain name. I guess I am wondering if there is any way to modify this of some library to time out when it cant make a connection.
Cheers

I guess I am wondering if there is any way to modify this of some library to time out when it cant make a connection.

Modify "this" what? The EthernetClient::connect() method DOES time out if a connection can not be made. It may not time out soon enough for you. In which case, I advise not hard-coding a bad domain name. 8)

PaulS:

I guess I am wondering if there is any way to modify this of some library to time out when it cant make a connection.

Modify "this" what? The EthernetClient::connect() method DOES time out if a connection can not be made. It may not time out soon enough for you. In which case, I advise not hard-coding a bad domain name. 8)

The domain name string is passed to this function and it's entered through a web interface among other variables...Therefor I can't control what is fed to it. This example is hard coded yes but this was my trial subroutine. Is there a way to modify the time out for connect()? its clearly greater then the watchdog if it's causing this..

Is there a way to modify the time out for connect()?

The code for the connect method that actually gets used:

int EthernetClient::connect(IPAddress ip, uint16_t port) {
  if (_sock != MAX_SOCK_NUM)
    return 0;

  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = W5100.readSnSR(i);
    if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
      _sock = i;
      break;
    }
  }

  if (_sock == MAX_SOCK_NUM)
    return 0;

  _srcport++;
  if (_srcport == 0) _srcport = 1024;
  socket(_sock, SnMR::TCP, _srcport, 0);

  if (!::connect(_sock, rawIPAddress(ip), port)) {
    _sock = MAX_SOCK_NUM;
    return 0;
  }

  while (status() != SnSR::ESTABLISHED) {
    delay(1);
    if (status() == SnSR::CLOSED) {
      _sock = MAX_SOCK_NUM;
      return 0;
    }
  }

  return 1;
}

You'd need to add a timeout to the last while loop to not block forever.

PaulS:

Is there a way to modify the time out for connect()?

The code for the connect method that actually gets used:

int EthernetClient::connect(IPAddress ip, uint16_t port) {

if (_sock != MAX_SOCK_NUM)
   return 0;

for (int i = 0; i < MAX_SOCK_NUM; i++) {
   uint8_t s = W5100.readSnSR(i);
   if (s == SnSR::CLOSED || s == SnSR::FIN_WAIT || s == SnSR::CLOSE_WAIT) {
     _sock = i;
     break;
   }
 }

if (_sock == MAX_SOCK_NUM)
   return 0;

_srcport++;
 if (_srcport == 0) _srcport = 1024;
 socket(_sock, SnMR::TCP, _srcport, 0);

if (!::connect(_sock, rawIPAddress(ip), port)) {
   _sock = MAX_SOCK_NUM;
   return 0;
 }

while (status() != SnSR::ESTABLISHED) {
   delay(1);
   if (status() == SnSR::CLOSED) {
     _sock = MAX_SOCK_NUM;
     return 0;
   }
 }

return 1;
}



You'd need to add a timeout to the last while loop to not block forever.

Can I reference millis() in this section of code? I've never changed the pre-written code before..

I was thinking

unsigned int timeStamp=millis();
while((millis()-timeStamp<10000)&&(status() != SnSR::ESTABLISHED)){
// The above code
}
return 1;

edit: I realize I would have to return 0 if it timed out, that's just pseudo code

Can I reference millis() in this section of code?

Yes. Typically, if you are adding a condition to a while statement, the addition goes on the end, not the beginning.

 unsigned int tStamp = millis();
  while (status() != SnSR::ESTABLISHED) {
    delay(1);
  if ((status() == SnSR::CLOSED)or(millis()-tStamp>10000)) {
      _sock = MAX_SOCK_NUM;
      return 0;
    }
  }

This did it and I no longer get watchdog trips with the cell modem and/or incorrect info, thanks for the help