Curl_global_cleanup() GPFs

178 views
Skip to first unread message

Reinaldo

unread,
Mar 9, 2021, 9:50:54 AM3/9/21
to Harbour Users
Hello everyone;

I'm using hb_Curl to consume Twilio's API to send SMS.  It is running as a Windows service and it works well except it GPFs at odd times always on instruction curl_global_cleanup().

Any ideas where to look?

Thank you, 


Reinaldo.

Gerald Drouillard

unread,
Mar 9, 2021, 10:12:18 AM3/9/21
to harbou...@googlegroups.com
In your loop throw in a hb_gcall(.t.) once in a while.

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/b7e663d8-a1ad-47d1-ab42-ca8bd019df1dn%40googlegroups.com.

Reinaldo

unread,
Mar 9, 2021, 12:26:15 PM3/9/21
to Harbour Users
Thank you.  I added that but still get GPFs at odd times on the same line:  curl_global_cleanup().  Here is my code:


METHOD SendOtherTxts() CLASS TService
   Local oQ       := TAdsQuery():New()    //ADS Sql class 
   Local oQ2      := TAdsQuery():New() 
   Local cUrl     := "https://api.twilio.com/2010-04-01/Accounts/" + ACCOUNT_SID + "/Messages.json"
   Local Line, hCurl, nError, cResponse, httpcode, cPostFields, cTel, aData 

   oQ2:cSql:= "UPDATE SMSMessages SET DTSent = now() WHERE celnumber = '$1$'\n"
   oQ:cSql := "SELECT celnumber, text FROM SMSMessages WHERE DTSent IS NULL \n"
   oQ:Run() 

   if oQ:nRows > 0      //messages in queue pending to be sent

      LogData( ::cLogFile, { "Sending other texts from SMSMessages table:", oQ:nRows }, ::nMaxLogSize )
      curl_global_init()

      if !empty( hCurl := curl_easy_init() )

         FOR EACH LINE IN oQ:aResultSet

            cTel := OnlyDigits( Line[ 1 ] )

            cPostFields := 'To='    + '1' + cTel +;      //1 prefix for US numbers
                           '&From=' + TEL_FROM +;
                           '&Body=' + Line[ 2 ]          //text message to be sent


            LogData( ::cLogFile, { cPostFields }, ::nMaxLogSize )

            curl_easy_setopt( hCurl, HB_CURLOPT_POST, 1 )
            curl_easy_setopt( hCurl, HB_CURLOPT_URL, cUrl )
            curl_easy_setopt( hCurl, HB_CURLOPT_USERPWD, ACCOUNT_SID + ':' + AUTH_TOKEN )
            curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )
            curl_easy_setopt( hCurl, HB_CURLOPT_SSL_VERIFYPEER, .F. )
            curl_easy_setopt( hcurl, HB_CURLOPT_POSTFIELDS, cPostFields )

            nError := curl_easy_perform( hCurl )
            curl_easy_getinfo( hCurl, HB_CURLINFO_RESPONSE_CODE, @httpcode )

            IF nError = HB_CURLE_OK

               cResponse = curl_easy_dl_buff_get( hCurl ) 

               IF ! empty( cResponse )

                  oQ2:aSubstitutes := { Line[ 1 ] }   //Telephnoe number where SMS is to be sent
                  oQ2:Run()                           //updates SMSMessages table record with timestamp

                  hb_jsonDecode( cResponse, @aData )
                  //TODO find if message was queued by checking "Status:" returned in cResponse JSON
                  LogData( ::cLogfile, aData, ::nMaxLogSize )

               ENDIF 

            ELSE 

               LogData( ::cLogFile, { "Error Sending Other SMS Texts.  Details below:" }, ::nMaxLogSize )
               LogData( ::cLogFile, Line, ::nMaxLogSize )   //Write current query record to logfile 
               LogData( ::cLogFile, { "Error Num:", nError, "Httpcode:", httpcode }, ::nMaxLogSize )
               LogData( ::cLogFile, curl_easy_strerror( nError ) )
            
            ENDIF 

            curl_easy_reset( hCurl )

         NEXT //next appointment in table

         curl_easy_cleanup( hCurl )
         hCurl := Nil 
         hb_gcAll( .t. )

      endif 

      curl_global_cleanup()     //GPF happens here at odd moments.  Not every time.

   endif 

   oQ2:End() 
   oQ:End() 

RETURN NIL 

Ajtim Kinrogdop

unread,
Mar 9, 2021, 11:59:43 PM3/9/21
to Harbour Users
Reinaldo,

curl_global_init() and curl_global_cleanup() should be called only once in the program. Throw them away from the Method.

Regards,
Mitja

torek, 09. marec 2021 ob 18:26:15 UTC+1 je oseba Reinaldo napisala:

Reinaldo

unread,
Mar 11, 2021, 9:25:02 AM3/11/21
to Harbour Users
Thank you sir.  I removed the calls to *_global_* out of the method as suggested and it seems to be working.  So far no GPFs.

Reinaldo.

Reply all
Reply to author
Forward
0 new messages