1

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 ?

Gil
  • 3,279
  • 1
  • 15
  • 25
Bui Dinh Ngoc
  • 447
  • 4
  • 10

1 Answers1

1

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

Community
  • 1
  • 1
fatihky
  • 116
  • 3
  • 3
  • 1
    *"your servlet-wide variables [are] freed when [a] request ended"* it only happens when the script has been edited and therefore automatically reloaded by G-WAN. The rest of the time, servlet variables are **static** (limited to the scope of the servlet), hence the need for "global" (sharable) pointers. – Gil Oct 14 '14 at 07:05
  • It'mean with one request gwan will start a java process to handle it . So it may be bad way , java cold start it very slow . – Bui Dinh Ngoc Oct 20 '14 at 02:03