Overview
Features
Download
Documentation
Community
Add-Ons & Services

Crashing with form writing

Please post support and help requests here.

Crashing with form writing

Postby chriso » 26 Nov 2008, 16:06

I am trying to post some form data to a web server php script. However it crashes my program under a few conditions...
1. if my internet connection is off (when trying online)
2. if my local server is turned off

I thought this might be caught in the try catch condition, but unfortunately not.

I put in some debug messages, and found it always crashes here...

__pocoForm.write(session.sendRequest(req));__

Any ideas? Code below.

Many thanks

Code: Select all

try{
   URI uri( form.action.c_str() );
   std::string path(uri.getPathAndQuery());
   if (path.empty()) path = "/";

   HTTPClientSession session(uri.getHost(), uri.getPort());
   HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
   session.setTimeout(Poco::Timespan(10,0));

   // create the form data to send
   HTMLForm pocoForm(HTMLForm::ENCODING_URL);

   // form values
   pocoForm.set("nameOne", "valOne");
   pocoForm.set("nameTwo", "valTwo");

   pocoForm.prepareSubmit(req);
   pocoForm.write(session.sendRequest(req));

}catch (Exception& exc){
   if(verbose) std::cerr << exc.displayText() << std::endl;
}
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Crashing with form writing

Postby chriso » 30 Nov 2008, 14:18

I've narrowed the crash down to be either

pocoForm.write(session.sendRequest(req));

or...

HTTPResponse res;
istream& rs = session.receiveResponse(res);


No-one have any ideas?
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Crashing with form writing

Postby chriso » 05 Dec 2008, 15:00

Anyone have any thoughts?
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Crashing with form writing

Postby chriso » 07 Dec 2008, 12:19

Sometimes for this line of code:
__pocoForm.write(session.sendRequest(req));__

The debugger brings up an alert saying
__Program received signal SIGSEGV, Segmentation fault.__

Here is a screenshot of the output. Any ideas?

{img src=http://www.chrisoshea.org/storage/ofw/pocofault.gif width=788 height=273 align= desc= link= }

chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Re: Crashing with form writing

Postby alex » 07 Dec 2008, 14:45

> Here is a screenshot of the output. Any ideas?

Not really. There is nothing obviously wrong with the code you have posted but you can't win war with air force only. I recommend you put a boot on the ground, step in with debugger and find out where exactly your problem occurs. I just ran your code without a hiccup.
alex
 
Posts: 1142
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Crashing with form writing

Postby chriso » 07 Dec 2008, 15:55

(sorry, posted reply in wrong place)
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Re: Re: Crashing with form writing

Postby chriso » 07 Dec 2008, 15:56

alex,

thanks for the reply.

here are some samples from the call stack output from the debugger (codeblocks, windows)

http://www.chrisoshea.org/storage/ofw/try1.txt

http://www.chrisoshea.org/storage/ofw/try2.txt

http://www.chrisoshea.org/storage/ofw/try3.txt

http://www.chrisoshea.org/storage/ofw/try4.txt
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Re: Re: Re: Crashing with form writing

Postby alex » 07 Dec 2008, 17:57

> here are some samples from the call stack output from the debugger (codeblocks, windows)

SocketImpl::connect is where things break. You should set breakpoint and examine what you have there.
alex
 
Posts: 1142
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: Re: Re: Re: Re: Crashing with form writing

Postby chriso » 08 Dec 2008, 12:41

in src/SocketImpl.cpp around line 137 is the connection function. Line 137 is a throw; call

Code: Select all


void SocketImpl::connect(const SocketAddress& address, const Poco::Timespan& timeout)
{
   poco_assert (_sockfd == POCO_INVALID_SOCKET);

   init(address.af());
   setBlocking(false);
   try
   {
      int rc = ::connect(_sockfd, address.addr(), address.length());
      if (rc != 0)
      {
         if (lastError() != POCO_EINPROGRESS && lastError() != POCO_EWOULDBLOCK)
            error(address.toString());
         if (!poll(timeout, SELECT_READ | SELECT_WRITE))
            throw Poco::TimeoutException("connect timed out", address.toString());
         int err = socketError();
         if (err != 0) error(err);
      }
   }
   catch (Poco::Exception&)
   {
      setBlocking(true);
      throw;
   }
   setBlocking(true);
}



Shouldn't it be throwing something, rather than just throw on its own?

Are there any members of the Poco team who can see what could be going wrong?

Many thanks
chriso
 
Posts: 16
Joined: 28 Sep 2008, 17:42

Re: Re: Re: Re: Re: Re: Crashing with form writing

Postby alex » 08 Dec 2008, 13:32

> Shouldn't it be throwing something, rather than just throw on its own?

It is throwing something - the same exception that was caught.

> Are there any members of the Poco team who can see what could be going wrong?

You need to step through your code in debugger, find out where does the exception originate (very likely from error() ) and which exception it is. Nobody can see that remotely for you because the problem appears to be somewhere in your settings, not the framework.
alex
 
Posts: 1142
Joined: 11 Jul 2006, 16:27
Location: United_States

Next

Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests