Thread: [ANet-devel] Low-Level Design!
Status: Abandoned
Brought to you by:
benad
From: Benoit N. <be...@ma...> - 2001-12-04 00:56:41
|
Look at: http://anet.sourceforge.net/docs/devel/lowdesign/ So, what do you think of it? I will do that for *all* functions in the daemon right before they are finalized. So this should help everyone when merging some "sample code" to the daemon itself. Chirag: You can start working now on the File Management Wrappers. Place the "Files.c" in ANet_Daemon/Linux. The two headers you need are Common/Files.h and Linux/FilesSpecific.h. There are still some functions to add (especially for directory stuff), but at least you can know exactly what to do for now. - Benad |
From: Chirag K. <ch...@ya...> - 2001-12-11 08:39:54
|
On Tue, Dec 04, 2001 at 11:34:36AM +0530, Chirag Kantharia wrote: | On Mon, Dec 03, 2001 at 07:56:32PM -0500, Benoit Nadeau wrote: | | Chirag: You can start working now on the File Management Wrappers. Place | | the "Files.c" in ANet_Daemon/Linux. The two headers you need are | | Common/Files.h and Linux/FilesSpecific.h. There are still some functions to | | add (especially for directory stuff), but at least you can know exactly | | what to do for now. | Got it. Please ignore my previous mail. Hi! I'm still working on the above. Meanwhile, I'd a suggestion: the comments in the code could be suitably formatted so that the documentation for the code can be automatically generated. For example, javadoc, can be used to generate documentation for java class files. There's something called doxygen which is javadoc equivalent for C/C++, but I haven't used it personally. Has anybody on the list used it? Any other suggestions for generating the documentation is welcome. chyrag. -- Chirag Kantharia, chyrag.dhs.org/ |
From: Benoit N. <be...@ma...> - 2001-12-12 15:29:41
|
>On Tue, Dec 04, 2001 at 11:34:36AM +0530, Chirag Kantharia wrote: >| On Mon, Dec 03, 2001 at 07:56:32PM -0500, Benoit Nadeau wrote: >| | Chirag: You can start working now on the File Management Wrappers. Place >| | the "Files.c" in ANet_Daemon/Linux. The two headers you need are >| | Common/Files.h and Linux/FilesSpecific.h. There are still some >functions to >| | add (especially for directory stuff), but at least you can know exactly >| | what to do for now. >| Got it. Please ignore my previous mail. > >Hi! > >I'm still working on the above. Meanwhile, I'd a suggestion: the >comments in the code could be suitably formatted so that the >documentation for the code can be automatically generated. For example, >javadoc, can be used to generate documentation for java class files. > >There's something called doxygen which is javadoc equivalent for C/C++, >but I haven't used it personally. Has anybody on the list used it? Any >other suggestions for generating the documentation is welcome. OK. So I looked a bit at doxygen, and it seems to be good. Look at http://www.stack.nl/~dimitri/doxygen/index.html Here's an example: //! A normal member taking two arguments and returning an integer value. /*! \param a An integer argument. \param s A constant character pointer. \return The test results \see Test(), ~Test(), testMeToo() and publicVar() */ int testMe(int a,const char *s); So, it's still readable. Anyways, I "toyed" a bit with the code, and here's the result: http://anet.sourceforge.net/doc.tar.gz HTML starts in html/index.html PDF is in latex/refman.pdf Just for fun, look at the graph for the "main.c File Reference". Wow. At any rate, it's good enough for me. javadoc used to get on my nerve, but doxygen's format is good enough for me. You can still make "plain" comments: I'll be in charge of re-formatting them to doxygen. Translation: I'll be using doxygen from now on, but you don't have to learn it. - Benad |
From: Chirag K. <ch...@ya...> - 2001-12-13 13:13:47
|
On Wed, Dec 12, 2001 at 10:29:32AM -0500, Benoit Nadeau wrote: | //! A normal member taking two arguments and returning an integer value. | /*! | \param a An integer argument. | \param s A constant character pointer. | \return The test results | \see Test(), ~Test(), testMeToo() and publicVar() | */ | int testMe(int a,const char *s); <snip> | Anyways, I "toyed" a bit with the code, and here's the result: | http://anet.sourceforge.net/doc.tar.gz | HTML starts in html/index.html | PDF is in latex/refman.pdf This is just great. If not the graphs and extensive documentation, I think, everybody can at least do the above: \param, \return and \see, if applicable, to their code. It shouldn't be much. In process of writing code for the fileI/O stuff, I've got lot of doubts but I'm saving it all up. I'll send in a huge mail soon, after I finish most of it or the mail gets very big. chyrag. -- Chirag Kantharia, chyrag.dhs.org/ |
From: Chirag K. <ch...@ya...> - 2001-12-17 14:25:08
|
On Thu, Dec 13, 2001 at 12:26:01PM +0530, Chirag Kantharia wrote: | In process of writing code for the fileI/O stuff, I've got lot of doubts | but I'm saving it all up. I'll send in a huge mail soon, after I finish | most of it or the mail gets very big. Hi Benad, I've taken liberty of defining few things which, hopefully, will not clash with anything else. typedef char boolean; typedef unsigned int UInt32; typedef unsigned char UInt8; typedef char * ANetMemoryTag; #define FALSE 0 #define TRUE 1 typedef struct { /* busy flag */ boolean busy; /* open flag */ boolean open; /* async flag */ boolean async; /* path to the file */ unsigned char * path; /* file descriptor */ int fd; } ANetFile; /* this is for time being; as I proceed with coding, I would be adding more members */ I've got a few doubts: 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? I need to return 3, if `path is invalid or not big enough'. This indicates that the path is pre-allocated. There is no way to find out size of a malloc'ed pointer in ANSI C, AFAIK. Under the circumstances, I am not sure, how would I be able to return error, if the path is not big enough. I suggest, that we malloc the memory required for path variable in the function itself. 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). 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. Actually, I thought this might turn out to be a long mail. But the succeeding functions (all are not done), I didn't find much problem. The attached is file.h and file.c (and Makefile). The code isn't documented doxygen style - I'm sorry for that. Felt very lazy to rewrite the comments. I haven't implemented all the functions as yet. Just thought of sending whatever I've done so far, to keep -devel list busy. PS: benad, can you change my homepage in CONTRIB to symonds.net/~chyrag/? chyrag. -- Chirag Kantharia, symonds.net/~chyrag/ |
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 |
From: Chirag K. <ch...@ya...> - 2001-12-19 06:09:41
|
On Tue, Dec 18, 2001 at 01:31:19PM -0500, Benoit Nadeau wrote: | >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 am not sure how ANetMemoryTag works. I don't think it's possible to GetMemoryBlockSize() on a pointer and find out, how much memory was allocated to it. If ANetMemoryTag was a struct of type: { void *ptr; int size; }, then it would work; ie. storing the size of the memory block along with the location where it is stored. I might be wrong. Let me know what you have thought. | 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 Fine. I had another suggestion: instead of return 1, 2 or 60, it would be great if we have an error.h with either #define ERROR_FILE_BUSY 60 or a typedef enum { ERROR_FILE_BUSY = 60 } ErrorCode; for the errors. | 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. Fine. I didn't see that then. | 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. Cool! | So, this means that instead of using ANSI stuff (FILE *), you can use Linux | stuff ("fd": file descriptors, if I'm correct). 'fd' are the usual variable names. The data type is 'int'. | 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. All ok. | what I did. BTW, we should always use "-Wall" with gcc; I saw | some weird errors. Oh! I'll take care. | About symonds.net: Am I dreaming? Wow! Thanx! :) chyrag. -- Chirag Kantharia, symonds.net/~chyrag/ |
From: Benoit N. <be...@ma...> - 2001-12-19 15:10:11
|
>I am not sure how ANetMemoryTag works. I don't think it's possible to >GetMemoryBlockSize() on a pointer and find out, how much memory was >allocated to it. If ANetMemoryTag was a struct of type: >{ void *ptr; int size; }, then it would work; ie. storing the size of >the memory block along with the location where it is stored. > >I might be wrong. Let me know what you have thought. ANetMemoryTag is an "opaque" type. It's not _always_ a pointer. To use it, don't use the "*" operator. Use ResolveMemoryTag. If you look at Memory.c, you'll see the "trick" that I did to store the size, and why you MUST use ResolveMemoryTag. Look at Linux/main.c for an example. >Fine. I had another suggestion: instead of return 1, 2 or 60, it would >be great if we have an error.h with either #define ERROR_FILE_BUSY 60 or >a typedef enum { ERROR_FILE_BUSY = 60 } ErrorCode; for the errors. Go ahead and change Common/Files.h. I'll update the docs. But I prefer that you use "kANetFileBusy" in the enums to avoid conflics in some operating systems. And I prefer enums, but don't use typedefs, as I _think_ that this is not allowed in C. "ANET_FILE_BUSY": Macro "kAnetFileBusy" : Constant Remember: even if I have the "final word" on the code, don't be affraid to "make up" stuff. The worst thing is that I'll do some clean up, but hey, that's one of my tasks in ANet anyways. >| So, this means that instead of using ANSI stuff (FILE *), you can use Linux >| stuff ("fd": file descriptors, if I'm correct). > >'fd' are the usual variable names. The data type is 'int'. That's what I though. All code I've seen used "fd" for the variable name, but I had no idea of the type. An "int"? Simple... >| what I did. BTW, we should always use "-Wall" with gcc; I saw >| some weird errors. > >Oh! I'll take care. A good idea is to work from what is in CVS, making the checking easier. You can checkout anonymously all the stuff from CVS if ssh doesn't work for you. Just follow the instructions from SourceForge (but don't forget to add the "-P" flag). Or, if the only thing you have is HTTP access, you can download the full CVS archive here: http://cvs.sourceforge.net/cvstarballs/anet-cvsroot.tar.gz Dump it somewhere, and change your "CVSROOT" to the dumped directory: cd ~ # download the .tar.gz in your home directory tar -zxf anet-cvsroot.tar.gz #not sure about the following line... do "man cvs"... setenv CVSROOT ~/anet mkdir ANet_CVS cd ANet_CVS cvs co ANet >| About symonds.net: Am I dreaming? Wow! > >Thanx! :) Uh... I was talking about the site http://symonds.net/ , not your homepage... "Wow! That's the _coolest_ home page in the WORLD!"... That doesn't sound like me... ;-) I mean, free, banner-free, no strings attached web space? It's been a while since I've seen that! - Benad |