rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* Write an adapter in C
@ 2012-06-15 14:48 Riccardo Tacconi
  2012-06-16  5:52 ` Roberto De Ioris
  0 siblings, 1 reply; 2+ messages in thread
From: Riccardo Tacconi @ 2012-06-15 14:48 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 986 bytes --]

Hi, I would try to write an adapter for G-WAN server, which can run 
c-scripts. This is a G-WAN handler:

#include "gwan.h" // G-WAN exported functions#include <string.h> // memcmp()
int main(int argc, char *argv[]) 
{
   char *query = get_env(argv, QUERY_STRING, 0); // query: "start=200000"
   if(!query || memcmp(query, "start=", sizeof("start=") - 1)) // FLV query?
      return 200; // HTTP status (200:'OK')
   
   http_t *head = get_env(argv, HTTP_HEADERS, 0); // set HTTP bytes range
   head->h_range_from = atol(query + sizeof("start=") - 1); // checked by G-WAN

   #define FLV_HEAD "FLV\x1\x1\0\0\0\x9\0\0\0\x9" // insert the FLV Header
   http_header(HEAD_ADD | HEAD_AFTER, FLV_HEAD, sizeof(FLV_HEAD) - 1, argv);
   return 206; // HTTP status (206:'Partial Content')      
}


I could exchange data with Rack from a module like that. I do not how to write a Rack adapter, is there any tutorial. Should I call Ruby code from C, so should I write an wrapper to Rack methods?


[-- Attachment #2: Type: text/html, Size: 11012 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Write an adapter in C
  2012-06-15 14:48 Write an adapter in C Riccardo Tacconi
@ 2012-06-16  5:52 ` Roberto De Ioris
  0 siblings, 0 replies; 2+ messages in thread
From: Roberto De Ioris @ 2012-06-16  5:52 UTC (permalink / raw)
  To: rack-devel


> Hi, I would try to write an adapter for G-WAN server, which can run
> c-scripts. This is a G-WAN handler:
>
> #include "gwan.h" // G-WAN exported functions#include <string.h> //
> memcmp()
> int main(int argc, char *argv[])
> {
>    char *query = get_env(argv, QUERY_STRING, 0); // query: "start=200000"
>    if(!query || memcmp(query, "start=", sizeof("start=") - 1)) // FLV
> query?
>       return 200; // HTTP status (200:'OK')
>
>    http_t *head = get_env(argv, HTTP_HEADERS, 0); // set HTTP bytes range
>    head->h_range_from = atol(query + sizeof("start=") - 1); // checked by
> G-WAN
>
>    #define FLV_HEAD "FLV\x1\x1\0\0\0\x9\0\0\0\x9" // insert the FLV Header
>    http_header(HEAD_ADD | HEAD_AFTER, FLV_HEAD, sizeof(FLV_HEAD) - 1,
> argv);
>    return 206; // HTTP status (206:'Partial Content')
> }
>
>
> I could exchange data with Rack from a module like that. I do not how to
> write a Rack adapter, is there any tutorial. Should I call Ruby code from
> C, so should I write an wrapper to Rack methods?
>

Are you sure this is the best way to follow ?

Just to give you an idea on the amount of code you need:

http://projects.unbit.it/uwsgi/browser/plugins/rack/rack_plugin.c

gwan can proxy to http service, why not simply using
rackup,unicorn,uWSGI,thin behind gwan ?


-- 
Roberto De Ioris
http://unbit.it

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-06-16  5:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-15 14:48 Write an adapter in C Riccardo Tacconi
2012-06-16  5:52 ` Roberto De Ioris

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).