g wan - How to read, write file over gwan -


i new gwan, , coding read/write static file on gwan, however, found when try open file (corresponding parameter pass gwan), run main() twice (or infinite looping), 1 ? thanks!

here getanddelivery.c

int main(int argc, char *argv[]) {     global_count = 1;     printf("global count : %d\n", global_count);      xbuf_t *reply = get_reply(argv);     char *name = 0;      while(global_count<argc){             get_arg("zoneid=", &name, global_count, argv);            if(hadcache(name)){                     printf("have file\n");           }else{                     printf("no file found!\n");           }             global_count++;     }      xbuf_xcat(reply, "work!");      return 200;  } 

function hadcache check whether static file exist or not! again!!


thank gil answering question! had modified code , work now! however, try use own header file , function file on gwan under gwan/include/myownfunction.h & hadcache.c, found getanddelivery.c cannot call hadcache() function

#include "myownfunction.h"  int main(){ ... } 

myownfunction.h

#include <stdio.h> #include <stdbool.h>  bool hadcache(char* zoneid); 

hadcache.c

#include "myownfunction.h"  bool hadcache(char* zoneid){...} 

however, work if replace on getanddelivery file:

replace #include "myownfunction.h"           #include "hadcache.c" 

could please me ? thank v !

your problem comes thread-unsafe global_count++; variable increment cause havock under concurrency.

you should rather read atomicity , use atomic incrementation. see other question: feature request: atomicadd() function included in gwan.h.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -