[Prev][Next][Index][Thread]
Crash in HTDoConnect
Hi,
I'm writting a robot using libwww5.0a and I got the following problem.
My compiler is the last Sun C++ compiler (release SC4.0). I'm
interested in putting timeout on my requests. So,
I'm using non preemptive requests and I issue new requests from the
terminate after callback. The robot works fine for the first n requests
but a crash happens in some cases in the HTDoConnect function:
signal PIPE (Broken Pipe) in sigprocmask at 0xef5b7f98
sigprocmask+0x8: bgeu sigprocmask+0x30
Current function is HTDoConnect
at the line:
case TCP_NEED_CONNECT:
status = connect(net->sockfd, (struct sockaddr *)
&net->sock_addr,sizeof(net->sock_addr));
Any help is welcomed: what's wrong with my code ? Are there
any simpliest means to do non preemptive request or to
put a timeout one requests.
Here are the main functions I'm using. Basically, the successive calls
are:
1- Initialisation
2- First request
3- Loop ---> 4- NextRequest in Terminate callbacks
Initialisation:
---------------
MHTTPConnection::MHTTPConnection()
{
HTProfile_newRobot(APP_NAME,APP_VERSION);
HTAlert_setInteractive(NO);
HTUserProfile* aProfile=HTLib_userProfile();
if (aProfile)
{
if ((HTUserProfile_setEmail(aProfile,DEFAULT_EMAIL)==NO)
|| (HTLib_setUserProfile(aProfile)==NO))
{
if (SHOW_MSG) HTTrace("Can't set Email in user
profile\n");
}
}
#ifdef CATCH_SIG
SetSignal();
#endif
HTNet_addAfter(ErrorHandler,NULL,NULL,HT_ERROR,HT_FILTER_LAST);
HTNet_addAfter(TerminateHandler,NULL,NULL,HT_ALL,HT_FILTER_LAST);
}
First request:
--------------
void MHTTPConnection::FirstRequest(const RWCString& anUrl,int aTimeout)
{
cout << "Accessing " << anUrl << " in max " << aTimeout << "
seconds." << endl;
theInitialRequest=HTRequest_new();
HTRequest_setOutputFormat(theInitialRequest,DEFAULT_FORMAT);
HTRequest_setPreemptive(theInitialRequest,NO);
HTRequest_setOutputStream(theInitialRequest,HTContentCounter(HTBlackHole(),theInitialRequest,0x2000));
HTRequest_setContext(theInitialRequest,this);
char* theCurrentDirectory=HTGetCurrentDirectoryURL();
char* theAbsoluteUrl=HTParse(anUrl,theCurrentDirectory,PARSE_ALL);
theAnchor=(HTParentAnchor*)HTAnchor_findAddress(theAbsoluteUrl);
HT_FREE(theAbsoluteUrl);
HT_FREE(theCurrentDirectory);
theTimeout.tv_sec=(aTimeout) ? aTimeout : DEFAULT_TIMEOUT;
HTEventrg_registerTimeout((struct
timeval*)&theTimeout,theInitialRequest,TimeoutHandler,YES);
if (theAnchor)
theText=HTLoadAnchorToChunk((HTAnchor*)theAnchor,theInitialRequest);
}
Next request:
-------------
void MHTTPConnection::NextRequest(const RWCString& anUrl)
{
cout << "Accessing " << anUrl << " in max " << theTimeout.tv_sec
<< " seconds." << endl;
if (theText) HTChunk_delete(theText);
theInitialRequest=HTRequest_new();
HTRequest_setOutputFormat(theInitialRequest,DEFAULT_FORMAT);
HTRequest_setPreemptive(theInitialRequest,NO);
HTRequest_setOutputStream(theInitialRequest,HTContentCounter(HTBlackHole(),theInitialRequest,0x2000));
HTRequest_setContext(theInitialRequest,this);
char* theCurrentDirectory=HTGetCurrentDirectoryURL();
char* theAbsoluteUrl=HTParse(anUrl,theCurrentDirectory,PARSE_ALL);
theAnchor=(HTParentAnchor*)HTAnchor_findAddress(theAbsoluteUrl);
HT_FREE(theAbsoluteUrl);
HT_FREE(theCurrentDirectory);
HTEventrg_registerTimeout((struct
timeval*)&theTimeout,theInitialRequest,TimeoutHandler,YES);
if (theAnchor)
theText=HTLoadAnchorToChunk((HTAnchor*)theAnchor,theInitialRequest);
}
Terminate and Timeout callbacks (static callbacks call these
methods from the pointer passed in the request context member).
---------------------------------------------------------------
int MHTTPConnection::Terminate(HTRequest* aRequest,HTResponse*
aResponse,void* aParameter,int aStatus)
{
if (aStatus==HT_LOADED)
{
if (theAnchor)
{
SetDate(HTAnchor_date(theAnchor));
SetLastDate(HTAnchor_lastModified(theAnchor));
SetType(HTAnchor_format(theAnchor));
SetLength(HTAnchor_length(theAnchor));
SetInputStream(theText);
try {
theStatus=aStatus;
ProcessDocument(theStatus);
cout << "Document Indexed." << endl;
}
catch (MParseUrlException* anException)
{
if (aRequest) HTRequest_delete(aRequest);
cout << "Exception in
MHTTPConnection::Terminate-->" << anException->GetMessage() << endl;
delete anException;
}
}
}
try {
MAccess::Close();
MAccess::Open();
RWCString anUrl;
if (NextUrl(anUrl)) NextRequest(anUrl);
else Cleanup(0,aRequest);
}
catch (MParseUrlException* anException)
{
cout << "Exception in MHTTPConnection::Terminate-->" <<
anException->GetMessage() << endl;
delete anException;
Cleanup(0,aRequest);
}
if (aRequest) HTRequest_delete(aRequest);
return HT_OK;
}
int MHTTPConnection::Timeout(HTRequest* aRequest)
{
try {
cout << "Request timeout...\n" << endl;
theStatus=-1;
ProcessError(theStatus);
}
catch (MException* anException)
{
cout << "Exception in MHTTPConnection::Timeout-->" <<
anException->GetMessage() << endl;
delete anException;
}
HTRequest_kill(aRequest);
return HT_OK;
}
--
--------------------------------------------------------------------
* Olivier Baujard Ph.D. / UIN-CIH Geneva Hospital *
* Tel : (41 22) 372 62 72 *
* Fax : (41 22) 372 61 98 *
* Email : Olivier.Baujard@dim.hcuge.ch / Olivier.Baujard@imag.fr *
* URL: http://expasy.hcuge.ch/sgaico/html/olb/baujard.html *
* Interests : DAI, Vision, Classification, Artificial Life *
--------------------------------------------------------------------
Follow-Ups: