title: G-WAN and persistent MySQL connexion
body: <p>me again with a little question about G-WAN and MySQL.</p>
  
  <p>This script below works fine ... 
  My only problem is when MySQL went down. G-WAN script crash and G-WAN as well.</p>
  
  <p>What is the nest way to keep a persistent MySQL connexion and handle MySQL downtime? </p>
  
  <pre><code>typedef struct { 
     MYSQL *conn;
  } data_t;
  
  int main(int argc, char *argv[])
  {
    u64 start = getus();
    data_t **data = (data_t**)get_env(argv, US_SERVER_DATA);
    xbuf_t *reply = get_reply(argv);
  
    if(!data[0]) // first time: persistent pointer is uninitialized
    {
      data[0] = (data_t*)calloc(1, sizeof(data_t));
      if(!data[0])
          return 500; // out of memory
      data[0]-&gt;conn = (MYSQL *)mysql_init(data[0]-&gt;conn);
  
      if(! data[0]-&gt;conn) {
        xbuf_xcat(reply, "MySQL Error");
        return(200);
      }
  
      if(! mysql_real_connect(data[0]-&gt;conn, "localhost", "root", "willow", "test", NULL, NULL, 0)) {
        return 500;
      }
      xbuf_cat(reply, "initialized data&lt;br&gt;");
    }
  
    // Do what we want here ...
  </code></pre>