1

I am using G-WAN 4.11.20

init.c

#pragma link "mono-2.0"
#pragma include "/home/igor/Projects/gwan_linux64-bit/mono-3.0.2"
#include "gwan.h"  // G-WAN API
#include <mono/metadata/metadata.h>
#include <mono/metadata/loader.h>
#include <mono/metadata/object.h>

static MonoString*  Sample ()
{
   return mono_string_new (mono_domain_get (), "Hello!");
}

int main(int argc, char *argv[])
{
   mono_add_internal_call("Gwan::Sample", Sample);
   return 0;
}

gwan_api.cs

public class Gwan
{
     [MethodImplAttribute(MethodImplOptions.InternalCall)]
     extern public static string Sample();
}

gwan is starting with assertion:

ghashtable.c:236: assertion 'hash != NULL' failed

Than after calling script, I am getting the same problem.

Unhandled Exception: System.MissingMethodException: Cannot find the requested method.
  at (wrapper managed-to-native) Gwan:Sample ()
  at hello2.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Cannot find the requested method.
  at (wrapper managed-to-native) Gwan:Sample ()
  at hello2.Main (System.String[] args) [0x00000] in <filename unknown>:0

My feeling is that I don't configure mono right, any suggestions?

Igor Golodnitsky
  • 4,456
  • 7
  • 44
  • 67

2 Answers2

1

Unlike main.c (the maintenance script) the init.c script must terminate for the G-WAN server to start listening.

Since the init.c code is released after its execution, this makes it a poor candidate for storing persistent code supposed to be called by G-WAN servlets to build dynamic contents for client requests.

You probably woul have more chances with main.c, or a G-WAN connection handler.

Gil
  • 3,279
  • 1
  • 15
  • 25
  • 1
    Make it working, as I wanted, thank you for your help. – Igor Golodnitsky Oct 18 '14 at 21:04
  • Interesting, looks like REQUEST and many of get_env data is cleared when I am inside cs servlet. Why not clear it after execution? – Igor Golodnitsky Oct 18 '14 at 21:53
  • The request context is (partially) cleared after the request has been processed and then totally cleared after a connection close (not while a servlet is executing). Check that you are accessing the 'right' information context by checking the value of the client socket from your servlet. – Gil Oct 20 '14 at 15:26
  • This is "cs" servlet. I am calling a function in C handler, that for example call get_env with REQUEST. While as result I see only GET /?hello.cs without all other data. Because of that, I need to make strdup and set it globally. – Igor Golodnitsky Oct 21 '14 at 09:01
  • I guess you are referring to URL parameters. They are still there but you need to read the buffer until you reach the end of the URI (with " HTTP/1.1 "), and skip the null characters used to separate each URL parameter. – Gil Oct 23 '14 at 11:26
  • QUERY_STRING is empty too. How do you know, did you try it? – Igor Golodnitsky Oct 23 '14 at 13:39
  • I certainly could not try from C# as I would need your code to do so. I am referring to the behavior for C, which applies to C#: the request is sliced and diced while parsed. As a consequence, if you wish to read the READ xbuffer directly then you have to read NULL-byte-separated parameters until you reach the end of the URI (which is marked by the protocol version "HTTP/1.x"). – Gil Oct 24 '14 at 15:27
-1

You must implement the C# wrappers for any new G-WAN API (or external function) you want to support from your C# scripts.

See Gwan C#, how to get HTTP headers?

Community
  • 1
  • 1
Pete
  • 42
  • 3
  • Loading your persistent code from an ephemeral module. Thanks 'Pete' for the quick reply. – Gil Oct 18 '14 at 12:27