How to make a G-WAN servlet close its connection silently without sending any reply

StackOverflow https://stackoverflow.com/questions/13281795

  •  27-11-2021
  •  | 
  •  

Question

How to have gwan send no reply to some requests, i.e. make a servlet closed silently without building and sending a reply?

It is useful to reduce the out-going bandwidth from the server side.

For collecting data only, there's no need to respond anything to the client.

Was it helpful?

Solution

You can also close the connection from the servlet by doing something like (untested):

#include <sys/socket.h>

char buf[1024];
int s = (int)get_env(argv, CLIENT_SOCKET);
shutdown(s, SHUT_WR);
while(read(s, buf, sizeof(buf)) > 0);
close(s);
return 500;

Then return something like 500 like above so you don't have to build a reply.

OTHER TIPS

You can do that with a gwan connection handler.

I think this is the event that you need to catch on the handler. Since you want the servlet to run then close the connection after.

HDL_BEFORE_WRITE, // after a reply was built, but before it is sent

Here is a sample code for the connection handler. You still need to add your filter. This code will close all requests after the reply was built.

int init(int argc, char *argv[])
{ 
   u32 *states = (u32*)get_env(argv, US_HANDLER_STATES);
   *states =  (1 << HDL_BEFORE_WRITE)
}

int main(int argc, char *argv[])
{
    long state = (long)argv[0];
    if(state == HDL_BEFORE_WRITE)
    {
        return 0; // Close connection
    }
    return(255); // continue G-WAN's default execution path
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top