Search code examples
databaseservletsg-wan

GWAN servlet life cycle


I am using C servlets, and Kyoto cabinet to store a database.

My question is, how does G-wan call servlets ?

when compare to java servlet they have init and service destroy life cycle ? how gwan work ?

int main(int argc, char *argv[])
{    
   KCDB *db = kcdbnew();

   if(!kcdbopen(db, "casket.kch",KCOREADER)) {
   fprintf(stderr, "open error: %s\n", kcecodename(kcdbecode(db)));
  }

Is it possible to open a database connection first and share it with multiple http requests ?


Solution

  • G-WAN compiles servlets on the fly and runs them when their addresses requested. For example: runs hello.c when /?hello.c or /?hello requested etc... So your servlet-wide variables freed when request ended. So you have to use server, virtual host or handler wide pointers to persist your variables. To setting global pointers, you can look at that basic example:
    http://gwan.com/source/persistence.c

    You can also look at these links:
    - GWAN Key-Value persistent multiple store
    - GWAN Key-Value persistent store
    - How to hold data structures in memory G-wan with Java / Scala
    - https://stackoverflow.com/a/16278305/1576270
    - http://gwan.com/source/mysql.c