fread - read lines with time gap
#5

Quote:
Originally Posted by Spmn
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/Fseek

A more simplier way is to open the file outside the timer function and pass the file handle to read timer. Then you close the file when it is completely read (i.e fread returns 0)
Doing so, you won't have to open&seek&close the file at every timer call.


Pseudo code example:
Код:
ProcessFile(filename[], interval)
{
    new File: handle = fopen(filename, io_read);
    if(handle) SetTimerEx("ReadLines", interval, 0, "dd", handle, interval);
}

ReadLines(File: handle, interval)
{
    new string[128];
    if(fread(handle, string))
    {
        // do whatever

        SetTimerEx("ReadLines", interval, 0, "dd", handle, interval); // continue reading
    }
    else // nothing left unread
    {
        fclose(handle);
    }
}
Pretty sure this will hang the server.
Reply


Messages In This Thread
fread - read lines with time gap - by ranme15 - 16.09.2016, 21:42
Re: fread - read lines with time gap - by Nero_3D - 16.09.2016, 21:52
Re: fread - read lines with time gap - by ranme15 - 16.09.2016, 21:59
Re: fread - read lines with time gap - by Spmn - 16.09.2016, 22:37
Re: fread - read lines with time gap - by PrawkC - 16.09.2016, 23:12
Re: fread - read lines with time gap - by ranme15 - 16.09.2016, 23:18

Forum Jump:


Users browsing this thread: 2 Guest(s)