[Klone-users] Klone using server push

Andre Puschmann ap4lists at sp-ss.de
Mon Jul 28 11:56:54 EDT 2008


Hi Stefano,

once again, sorry for the delay :-)

I am writing a klone-powered Linux packet capture application using
libpcap, which updates a web-interface as soon as a new network packet
arrives, i.e. live trace.

I use a shared memory concept to access shared data within different
processes. Furthermore, I use sessions to map a certain client
connection to a certain part of the shared memory. However, after
a session expires I need to do some memory cleanups in the shared
area, i.e. free reserved slots for further client connection.

I am not sure about the desired way to do so. The only thing I could
find was a private term function in each session object.

Best regards,
	Andre



Stefano Barbato wrote:
> Hi Andre,
> 
> the method to use really depends on what you need to accomplish.
> 
> If you need to share per-client data you can use sessions (url [1]).
> 
> If you want to share data between server processes you can use any
> facility the operating system offer (which one do you use btw?) like
> shared memory objects ([2]), memory mapped file [3], external file-based
> database like sqlite [4], etc.
> 
> If you want more then bare data sharing you can use an external daemon
> that centralizes klone daemons calls and that accept requests on tcp/ip
> or unix sockets. Even a shell script called by inetd may be enough for
> example. It really depends on your requiremets.
> 
> The "iterative" model you tried allow just one connection at a time so
> may not be suitable for your particular need. If you need multiple
> concurrent access to the same KLone application you need to use the
> "fork" or "prefork" model type.
> 
> So there are many options but I need more info to point you to the right
> direction :)
> 
> bye,
> s
> 
> 
> [1] sessions: http://www.koanlogic.com/klone/api/html/group__session.html
> [2] man shm_open
> [3] mmap
> [4] www.sqlite.org
> 
> 
> On 16/lug/08, at 23:10, Andre Puschmann wrote:
> 
>> Hi Stefano,
>>
>> thanks for your quick reply.
>> It worked as you described, thank you very much. However, I now got
>> another problem/question.
>>
>> I've read that klone runs multiple processes to serve client connections
>> (prefork pattern).
>>
>> Is it possible to have shared resources for all processes?
>>
>> Lets say I want to have just _one_ socket descriptor (singleton) that
>> I want to use.
>> I tried to use the iterative model to do so. But if that single
>> descriptor does a blocking read, the server hangs. So this is no
>> solution. Would you recommend using pthread for this?
>>
>> I am not sure if I get something wrong :-)
>>
>> Regards,
>> Andre
>>
>>
>>
>>
>>
>>
>> Stefano Barbato wrote:
>>> Hi Andre,
>>>
>>> KLone buffers the first 4096 bytes to give users the opportunity to
>>> modify header fields even after a few bytes have been written out with
>>> io_printf or io_write. You can for example use the response_redirect
>>> even after io_prints:
>>>
>>> <%
>>>    io_printf(out, "result 1");
>>>    io_printf(out, "result 2");
>>>    io_printf(out, "result 3");
>>>
>>>    /* then if an error occurred you can still modify http header */
>>>        if(error_condition)
>>>        response_redirect(response, "/error.kl1");
>>> %>
>>>
>>> The buffer is implemented as a filter attached to the response_t I/O
>>> object so you can avoid such buffer removing such filter and explicitly
>>> call the response_print_header() function (if you want an HTTP header at
>>> least). Here's the code:
>>>
>>>
>>> <%
>>>    ...
>>>    response_set_field(response, "Expires:","Mon, 26 Jul 1997 05:00:00
>>> GMT");
>>>
>>>    io_codecs_remove(response_io(rs));
>>>    response_print_header(response);
>>>
>>>    io_printf(out, "---ThisRandomString---\n");
>>>    ...
>>> %>
>>>
>>> Take a look to the "Message Channel" KLone demo application that opens
>>> and keep opened a bidirectional channel between client and server:
>>>
>>> http://koanlogic.com/download/klapp-msgchan-1.2.2.tar.gz
>>>
>>> It's built on Flash XmlSocket component and a custom easy library we
>>> wrote (see msgchan.h).
>>>
>>> bye!
>>>
>>> s
>>>
>>>
>>>
>>>
>>> On 08/lug/08, at 19:32, Andre Puschmann wrote:
>>>
>>>> Hi all,
>>>>
>>>> I am trying to use a server push technique to avoid client side polling
>>>> for data.
>>>> I am not sure if I am doing something wrong. For some reason Klone
>>>> sends
>>>> all 4 "packets" in one single bunch. Well, at least wireshark reports
>>>> this!
>>>> Seems like io_flush doesn't work?!
>>>>
>>>> Here is my sample code:
>>>>
>>>> <code>
>>>> <%!
>>>>  #include <stdio.h>
>>>> %><%
>>>>  int i;
>>>>
>>>>  response_set_content_type(response,
>>>> "multipart/x-mixed-replace;boundary=---ThisRandomString---");
>>>>  response_set_field(response, "Pragma:", "no-cache");
>>>>  response_set_field(response, "Cache-Control", "no-cache, no-store,
>>>> must-revalidate");
>>>>  response_set_field(response, "Expires:", "Mon, 26 Jul 1997 05:00:00
>>>> GMT");
>>>>
>>>>
>>>>  io_printf(out, "---ThisRandomString---\n");
>>>>
>>>>  for (i = 1; i < 5; i++)
>>>>  {
>>>>     io_printf(out, "Content-type: text/html\n\n");
>>>>     io_printf(out, "<h2>part %d</h2>\n", i);
>>>>     io_printf(out, "---ThisRandomString---\n");
>>>>     io_flush(out);
>>>>     sleep(1);
>>>>  }
>>>> %>
>>>> </code>
>>>>
>>>> Using the built-in cgi works for a shell script. Also here's the code
>>>> for that one:
>>>>
>>>> <code>
>>>> #!/bin/sh
>>>> echo "HTTP/1.0 200"
>>>> echo "Content-type:
>>>> multipart/x-mixed-replace;boundary=---ThisRandomString---"
>>>> echo ""
>>>> echo "---ThisRandomString---"
>>>> while true
>>>> do
>>>> echo "Content-type: text/html"
>>>> echo ""
>>>> echo "time: "
>>>> date
>>>> echo "---ThisRandomString---"
>>>> sleep 5
>>>> done
>>>> </code>
>>>>
>>>>
>>>> Comments are welcome!
>>>>
>>>> Best regards,
>>>> Andre
>>>>
>>>> _______________________________________________
>>>> Klone-users mailing list
>>>> Klone-users at koanlogic.com
>>>> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
>>>>
>>>
>>>
>>> _______________________________________________
>>> Klone-users mailing list
>>> Klone-users at koanlogic.com
>>> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
>>>
>>>
>>
>>
>> _______________________________________________
>> Klone-users mailing list
>> Klone-users at koanlogic.com
>> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
>>
> 
> 
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
> 
> 







More information about the klone-users mailing list