INIT/DONE API

1. wbSvrInit

wbSvrInit initializes the server. The application’s separate 'main' function, provided by the WebtoB system, calls wbSvrInit() as an initialization process. This routine is called after the process is executed, but before any service requests are processed. Therefore, transactions can be defined in the wbSvrInit() routine. If the application does not provide a wbSvrInit() routine, the default routine provided by WebtoB is called instead.

Application-specific command line options (CLOPT) can be passed to the server and processed in wbSvrInit().

For more information, refer to the CLOPT entry in the SERVER section of Configuration in the WebtoB Administrator’s Guide.

Options are passed through argc and argv. If an error occurs during execution of wbSvrInit(), the server exits by returning -1 and does not accept any service requests afterwards.

  • Prototype

    #include <wbapi.h>
    #include <atmi.h>
    int wbSvrInit(int argc, char *argv[])
  • Return value

    The wbSvrInit() function defines the initialization process of the WBAPI server. After the initialization process is complete, it must explicitly return a value greater than or equal to 0. If the returned value is negative, the server will terminate with a svrinit fail.

  • Example

    <wbsvrinit.m>

    *DOMAIN
    webtob1
    
    *NODE
     tmaxh1          WEBTOBDIR="/user2/haninho/webtob",
                     SHMKEY = 54777,
                     DOCROOT="/user2/haninho/webtob/docs",
                     APPDIR="/user2/haninho/webtob/ap",
                     PORT = "7654"
    
    *SVRGROUP
     htmlg           NODENAME = "tmaxh1", SvrType = HTML
     webapg          NODENAME = "tmaxh1", SVRTYPE = WEBSTD
    
    *SERVER
     html            SVGNAME = htmlg, MinProc = 1, MaxProc =2
     wbsvrinit       SVGNAME = webapg, MinProc = 1, MaxProc = 2, 
    
    *SERVICE
     test            SVRNAME = wbsvrinit
    
    *URI
     wbapi           Uri = "/svct/", Svrtype = WEBSTD
    
    *EXT
     htm             MimeType = "text/html", SvrType = HTML
    1. Compile the configuration file.

      $wscfl –I wbsvrinit.m
    2. Create a service table.

      $wsgst
    3. Generate a source file. The following is an example WBAPI program that processes requests, named wbsvrinit.c.

       #include        <stdio.h>
       #include        <usrinc/atmi.h>
       #include        <usrinc/wbapi.h>
       wbSvrInit(int argc, char *argv[]){
              fprintf(stdout, "SERVER Start!\n");
              return 0;
       }
       wbSvrDone(){
              fprintf(stdout, "SVR DONE!\n");
       }
       test(WBSVCINFO *rqst)
       {
              wbPrint(rqst,"<HTML>\n");
              wbPrint(rqst,"<HEAD> <TITLE> wbSvrInit test </TITLE> <HEAD>\n\n");
              wbPrint(rqst,"<BODY>\n");
              wbPrint(rqst,"<H2>wbSvrInit test");
              wbPrint(rqst,"</BODY>\n");
              wbPrint(rqst,"</HTML>\n");
              wbreturn(rqst, WBSUCCESS);
       }

      Compile the c file created with .wbapi using the Makefile file.

      $compile c wbsvrinit
    4. The following is an example of the resulting output.

      When starting the web server, the string “SERVER Start!” is printed to the standard output device, just as written in wbsvrinit().

       $ wsboot
      
       WSBOOT for node(tmaxh1) is starting:
       Welcome to WebtoB demo system: it will expire 2001/12/31
       Today: 2001/10/29
              WSBOOT: WSM is starting: Mon Oct 29 21:15:33 2001
              WSBOOT: HTL is starting: Mon Oct 29 21:15:33 2001
              WSBOOT: HTH is starting: Mon Oct 29 21:15:33 2001
               Current WebtoB Configuration:
                      Number of client handler(HTH) = 1
                      Supported maximum user per node = 2025
                      Supported maximum user per handler = 2025
              WSBOOT: SVR(htmls) is starting: Mon Oct 29 21:15:33 2001
              WSBOOT: SVR(wbsvrinit) is starting: Mon Oct 29 21:15:33 2001
       $ SERVER Start!
  • Related functions

    wbSvrDone()

2. wbSvrDone

wbSvrDone performs necessary tasks when the server is shut down.

The application’s separate 'main' function, provided by the WebtoB system, calls wbSvrDone() before completing all service requests and terminating the process.

When this routine is executed, the server process is still part of the system but no longer supports any services. Therefore, a transaction may be defined within the wbSvrDone() routine. If wbSvrDone() returns while maintaining an interactive connection, awaiting still an asynchronous response, or operating in transaction mode, WebtoB will terminate the interactive connection, ignore any pending asynchronous responses, and abort the transaction. The server process will then terminate immediately.

If the application does not provide a custom wbSvrDone() routine, the default routine provided by WebtoB is called instead.

  • Prototype

    #include <wbapi.h>
    #include <atmi.h>
    int wbSvrDone(void)
  • Return value

    wbSvrDone() is used so that any necessary tasks are performed before terminating the server process, and is executed normally regardless of the return value.

  • Example

    <wbsvrdone.m>

    *DOMAIN
    webtob1
    
    *NODE
     tmaxh1         WEBTOBDIR="/user2/haninho/webtob",
                    SHMKEY = 54777,
                    DOCROOT="/user2/haninho/webtob/docs",
                    APPDIR="/user2/haninho/webtob/ap",
                    PORT = “7654”
    
    *SVRGROUP
     htmlg          NODENAME = "tmaxh1", SvrType = HTML
     webapg         NODENAME = "tmaxh1", SVRTYPE = WEBSTD
    
    *SERVER
     html           SVGNAME = htmlg, MinProc = 1, MaxProc =2
     wbsvrdone      SVGNAME = webapg, MinProc = 1, MaxProc = 2, 
    
    *SERVICE
     test           SVRNAME = wbsvrdone
    
    *URI
     wbapi          Uri = "/svct/", Svrtype = WEBSTD
    
    *EXT
     htm            MimeType = "text/html", SvrType = HTML
    1. Compile the environment file (Config-file).

      $wscfl –i wbsvrdone.m
    2. Create a service table.

      $wsgst
    3. Write a WBAPI program that handles the request. The following is an example for wbsvrdone.c.

       #include        <stdio.h>
       #include        <usrinc/atmi.h>
       #include        <usrinc/wbapi.h>
       wbSvrInit(int argc, char *argv[]){
              fprintf(stdout, "SERVER Start!\n");
       }
       wbSvrDone(){
               fprintf(stdout, "SVR DONE!\n");
       }
       test1(WBSVCINFO *rqst)
       {
              wbPrint(rqst,"<HTML>\n");
              wbPrint(rqst,"<HEAD> <TITLE> wbSvrInit test </TITLE> <HEAD>\n\n");
              wbPrint(rqst,"<BODY>\n");
              wbPrint(rqst,"<H2>wbSvrdone test");
              wbPrint(rqst,"</BODY>\n");
              wbPrint(rqst,"</HTML>\n");
              wbreturn(rqst, WBSUCCESS);
       }

      Compile the c file created with .wbapi using the Makefile file.

      $compile c wbsvrdone
    4. The following is an example of the resulting output.

      When the web server starts, the string “SVR DONE” is printed to the standard output device, as written in wbSvrDone().

       $ wsdown
       Do you really want to down whole Webtob? (y : n): y
      
       WSDOWN for node(tmaxh1) is starting:
       SVR DONE!
              WSDOWN: SERVER(wbsvrinit:2) downed: Tue Oct 30 09:56:12 2001
              WSDOWN: SERVER(html:0) downed: Tue Oct 30 09:56:12 2001
              WSDOWN: HTL downed: Tue Oct 30 09:56:12 2001
              WSDOWN: HTH downed: Tue Oct 30 09:56:12 2001
              WSDOWN: WSM downed: Tue Oct 30 09:56:12 2001
              WSDOWN: WEBTOB is down
  • Related functions

    wbSvrInit()