Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Poco::Net::FTPClientSession hangs for 129 seconds on open() method , if the ftp host does not exist

Ask Question

I am using poco libraries to access ftp server, on yocto linux (hw is a microcontroller). If I specify a valid address (ftp host) all works properly, if I use a non-existing ftp address , the "open" method hangs for 129 seconds! Afterward it throws the following Poco::Exception..

displayText->"N4Poco9ExceptionE"
what->"Exception"
message->""
name->"Exception"
code->"110"

here the code..

Poco::Net::FTPClientSession ftp;
    ftp.open(host,port);     <<<<<<<<<  hangs here   
    ftp.login(userName,password);
    ftp.logout();
    ftp.close();
catch(Poco::Exception exc)

The setTimeout() methods works only after calling the open() method (otherwise it throws an exception). However ,if I set the internal _timeout variable with a c++ pointer hack, no luck..seems not related to ftp timeout.

If I break the debugger this is the stack..

1 __libc_connect connect.c 26 0xffffbe68bb8c 
2 ??                          0xffffbf1b1ab0 

(connect.c)

#include <sys/socket.h>
#include <sysdep-cancel.h>
#include <socketcall.h>
int    __libc_connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
#ifdef __ASSUME_CONNECT_SYSCALL
  return SYSCALL_CANCEL (connect, fd, addr.__sockaddr__, len);    <<< THE DEBUGGER BREAKS HERE
#else
  return SOCKETCALL_CANCEL (connect, fd, addr.__sockaddr__, len);
#endif

Thanks in advance for your help. Best regards,

@HongOoi TImes out waiting for the SYN-ACK response. The DNS timeout is only a few seconds, not two minutes. – user207421 Jun 19, 2020 at 8:02 See if you can set a connect timeout. The timeout method you tried is for a read timeout. – user207421 Jun 19, 2020 at 8:03 Hi Ooi, thanks for your answer. The problem is that Poco::Net::FTPClientSession does not allow to set a timeout (to reduce the two minutes).. For example the wget command by default waits two minutes, but using -T parameter I can reduce the timeout..for example 10 seconds (that is reasonable for the human interface) – agiuliani Jun 19, 2020 at 8:09 @ Marquis of Lorne , (thanks for your answers!) the Poco::Net::FTPClientSession have only one timeout setter, it work only once the connection is enstablished (after the open())..otherwise it throws an exception. Do you mean to call some linux low-level function? – agiuliani Jun 19, 2020 at 8:20

If nobody know how to solve using poco FTPClientSession object, I can try to precede the FTPClientSession::open() by this call (QT lib)..

QTcpSocket socket;
socket.connectToHost("xxx.xxx.xxx.198",21);
bool bConnected = socket.waitForConnected(10*1000); //ms
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.