[ANet-devel] Re: File Management questions
Status: Abandoned
Brought to you by:
benad
From: Benoit N. <be...@ma...> - 2001-12-18 18:31:28
|
>1. ANetGetSetFilePath(ANetFile * f, ANetMemoryTag path, UInt8 set) > >If the 'set' variable is set ie. it's non zero, then I understand that I >have to set the path of the file 'f' ie. f->path to the string pointed >to by variable path. One can malloc the memory required for storing the >string pointed to by path and copy the path. So far, so good. Now, if >the set variable is not set, ie, the function is used to get the file's >path in the memory location pointed to by path variable. > >Here do I assume that the path will be pre-malloc'ed or do I malloc the >memory required for storing the path? An ANetMemoryTag implies that: - The memory was already allocated - You can get the size of the allocated memory with GetMemoryBlockSize I'll do the docs for memory management this week. >When do I actually create the file? I can't do that in ANetInitFile(), >since that time, the path of the file is not decided upon. I can do that >in ANetGetSetFilePath(). This I'm doing currently. If there are any other >thoughts on this, please let me know. There's another option of >``creating'' the file in ANetOpenFile(). To be on the safer side, I'm >opening the files in O_RDWR | O_APPEND mode (ie. read, write and append >mode). (I think that opening in O_APPEND mode, will cause the file pointer >to be at the end of the file, which would need to be reset to the >beginning so that it can read stuff correctly). You should actually open the file only in ANetOpenFile and in ANetRead/WriteFile if the file was not already open. You create the file on the Write operation if it does not already exist. Look at: http://anet.sourceforge.net/docs/devel/lowdesign/html/group__files.html#a0 There's no acutal "seek position" to remember for reads. Look at the description of ANetReadFile, which is the only function you can use to read from a file. The "startPos" has to be given explitely each time. >2. ANetGetSetFileAsync(ANetFile *f, UInt8 *async, UInt8 set) > >I don't think ANSI C has any function call which will have this >functionality. By default, the native open() on Linux, opens the file >for asynchronous writing. For setting it to synchronous writing, ie. >subsequent writes will block the calling piece of code, until the data >is written to the disk, the file will have to be closed and reopened >with different mode. Let me know if this is ok. Your code has to work on Linux *only*. This means that you're not forced to use ANSI C functions. You can use any "Linux-native" function you want. So, this means that instead of using ANSI stuff (FILE *), you can use Linux stuff ("fd": file descriptors, if I'm correct). On most OS, including Linux, anync I/O is determined when you open the file. So, what you can do is this: - ANetOpenFile() correctly opens the file in the proper async state. - ANetGetSetFileAsync(), with the set flag, checks to see if the file is already open and if the async flag should change. If this is the case, close the file and re-open it in the new async mode. - ANetRead/WriteFile assume the actual async state of the file is already the same as the flag in the ANetFile structure. I cleaned up your code, formated the comments and checked it in. I made some small changes to your code to "merge" it correctly; check out "Linux/Files.c" and "Linux/FilesSpecific.h" to see what I did. BTW, we should always use "-Wall" with gcc; I saw some weird errors. About symonds.net: Am I dreaming? Wow! - Benad |