28.09.2011, 22:05
This is a THREADED Fread / Fwrite plugin.
When you use fread / fwrite in pawn directly, if a file is being read by another external program, or hdd writing is slow or file IO is under a strain, you will end up losing some miliseconds in server sync due to file system locking to accomodate the underlying safety mechanisms in order to ensure a stable file transaction.
This can become painfully obvious if you still use text files to store accounts. I know that on a few very popular servers this problem can take whole seconds to finish - imagine a random up to 1 second ini file reading lag on the server whenever a player joins - same can happen during leaving & writing data to account.
This plugin allows you to write data to file without this waiting delay, so you can "shove" out large amouts of data without any problems.
Reading is also done without any locking - the thread will load the data you desire and pass it to your callback.
The main purpose of the plugin is basically.. outputing a lot of data to text files without lagging the script.
Natives:
Download .inc, win32 dll and linux 32bit .so:
http://www.mathpudding.com/temp/rwthread.rar
Download source code:
http://www.mathpudding.com/temp/rwthread_src.rar
Example usage:
NOTE that this is still a very untested plugin, if you intend to use it make sure you understand what it is for and that it might screw things up for you - i cannot and will not take any responsibility for lost data because of this plugin.
Additionally - thanks to BlueG for his work on threads in his mysql plugin. This plugin is based on his work.
When you use fread / fwrite in pawn directly, if a file is being read by another external program, or hdd writing is slow or file IO is under a strain, you will end up losing some miliseconds in server sync due to file system locking to accomodate the underlying safety mechanisms in order to ensure a stable file transaction.
This can become painfully obvious if you still use text files to store accounts. I know that on a few very popular servers this problem can take whole seconds to finish - imagine a random up to 1 second ini file reading lag on the server whenever a player joins - same can happen during leaving & writing data to account.
This plugin allows you to write data to file without this waiting delay, so you can "shove" out large amouts of data without any problems.
Reading is also done without any locking - the thread will load the data you desire and pass it to your callback.
The main purpose of the plugin is basically.. outputing a lot of data to text files without lagging the script.
Natives:
pawn Код:
native ThreadW(file[], text[]);
native ThreadR(file[], callback[], beginoffset = 0, extraid = -1);
http://www.mathpudding.com/temp/rwthread.rar
Download source code:
http://www.mathpudding.com/temp/rwthread_src.rar
Example usage:
Quote:
forward readwholetext(texts[], extraid); public readwholetext(texts[], extraid) { printf("received from thread: \"%s\" extraid: %d.", texts, extraid); } ThreadW("scriptfiles/test.txt", "TEXT MEEEEEE\n"); ThreadW("scriptfiles/test.txt", "LINE 2\n"); ThreadW("scriptfiles/test.txt", "MOAR LINES\n"); ThreadR("scriptfiles/test.txt", "readwholetext", 5); // read everything in this file starting at 5 bytes offset. |
Additionally - thanks to BlueG for his work on threads in his mysql plugin. This plugin is based on his work.