Does HTTP func hang the server waiting for a response?
#1

Hello people, i recently released an include (ip locator). On my home server everything seems fine, it takes less than 1ms to respond. Michael@Belgium (http://forum.sa-mp.com/showpost.php?...6&postcount=26) reported in the thread that it takes time before he can login and go to class selection. Obviously it's no good me releasing an include that will mess peoples modes up. So i might have to remove it, if it is causing server hang.

Heres the include.
pawn Код:
#if !defined _samp_included
    #tryinclude <a_samp>

    #if !defined _samp_included
        #error "Can't find file "a_samp". Are your includes in the correct directory?"
    #endif
#endif


#if !defined HTTP
    #tryinclude <a_http>

    #if !defined HTTP
        #error "Can't find file "a_http". Are your includes in the correct directory?"
    #endif
#endif

#define MAX_COUNTRY_NAME                    (64)
#define MAX_CITY_NAME                       (64)

#define HTTP_REQUEST_IP                     ("api.hostip.info/get_html.php?ip=")

new g_HasORIL = 1;

forward hostip_Response(playerid, response_code, data[]);
forward OnRetrieveIpLocation(playerid, country[]);

public hostip_Response(playerid, response_code, data[])
{

    if( g_HasORIL != -1 )
    {
        if( response_code == 200 )
        {
            new
                _itr=9,
                _citr,
                szCountryBuff[ MAX_COUNTRY_NAME ];
               
            while( data[ _itr ] != EOS )
            {
                if( _itr == MAX_COUNTRY_NAME -1)
                {
               
                    szCountryBuff[ _itr ] = EOS;
                    break;
               
                }
               
                if( data[ _itr ] == '\n')
                {
                    szCountryBuff[ _itr ] = EOS;
                    break;
                }

                szCountryBuff[ _citr++ ] = data[ _itr++ ];

            }
            if( szCountryBuff[0] == '(' )
            {

                strdel( szCountryBuff, 0, sizeof(szCountryBuff) );
                strcat( szCountryBuff, "private country" );
               
            }
           
            CallLocalFunction( "OnRetrieveIpLocation", "ds", playerid, szCountryBuff );

        }
        else printf("<IPLocator Error> HTTP response code: %d", response_code );
       
    }
    else printf("<IPLocator Error> iploc included but the function OnRetrieveIpLocation was not found.");
}




////////////////////////////////////////////////////////////////////////////////
// CALLBACK HOOKS //////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#if defined FILTERSCRIPT

    public OnFilterScriptInit()
    {
        print("\n--------------------------------------");
        print(" Iggys Ip Locator Loaded.");
        print("--------------------------------------\n");

        g_HasORIL = funcidx("OnRetrieveIpLocation");

        if(funcidx("iploc_OnFilterScriptInit") != -1)
        {
            return CallLocalFunction("iploc_OnFilterScriptInit", "");
        }

        return 1;
    }

    #if defined _ALS_OnFilterScriptInit
        #undef OnFilterScriptInit
    #else
        #define _ALS_OnFilterScriptInit
    #endif
    #define OnFilterScriptInit iploc_OnFilterScriptInit

    forward iploc_OnFilterScriptInit();

#else

    public OnGameModeInit()
    {
        print("\n--------------------------------------");
        print(" Iggys Ip Locator Loaded.");
        print("--------------------------------------\n");

        g_HasORIL = funcidx("OnRetrieveIpLocation");

        if (funcidx("iploc_OnGameModeInit") != -1)
        {
            return CallLocalFunction("iploc_OnGameModeInit", "");
        }
        return 1;
    }

    #if defined _ALS_OnGameModeInit
        #undef OnGameModeInit
    #else
        #define _ALS_OnGameModeInit
    #endif
    #define OnGameModeInit iploc_OnGameModeInit
    forward iploc_OnGameModeInit();

#endif

public OnPlayerConnect(playerid)
{
    if( g_HasORIL != -1 )
    {

        new
            _szIP[ 16 ],
            _szTmpStr[ 128 ];

        GetPlayerIp( playerid, _szIP, 16 );

        strcat( _szTmpStr, HTTP_REQUEST_IP );
        strcat( _szTmpStr, _szIP );

        HTTP( playerid, HTTP_GET, _szTmpStr, "", "hostip_Response");//request location of ip and send it to hostip_Response
    }

    if(funcidx("iploc_OnPlayerConnect") != -1)
    {
        return CallLocalFunction("iploc_OnPlayerConnect", "i", playerid) != -1;
    }
    return 1;

}

#if defined _ALS_OnPlayerConnect
    #undef OnPlayerConnect
#else
    #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect iploc_OnPlayerConnect

forward iploc_OnPlayerConnect(playerid);

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
There are a few pointless array assignments there which i have removed from the next version. But i don't think that's the problem.

Any help or advice will be most welcome and appreciated.
Reply
#2

I'm not completely certain but since the code in SA:MP is single threaded (1 thing at an once), it will perform actions and leave the other actions under a queue.
Reply
#3

I don't think threads have anything to do with it i may be wrong. I thought after HTTP was used, control would be passed back to the calling function. And when the server (website) responds, the callback would be put in the queue. There's an easy way for me to test anyway.

Thanks for the reply.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)