> First sorry for all the noise, but I really like to make good use of
> uwsgi.
>
> I have been looking at apps and mount, and it seems after some initial
> problems that I can now do both, but not combined.
>
> But I am not sure if I quite understand the foundations here, and I
> can't find any good documentation on the subject, either. I like to use
> mount and app in order to push more flexibility into the uwsgi config, a
> philosophy I really like in uwsgi.
>
> I have a plugin where I like to make some apps (named request entry
> points as I understand it), and I like the mount option in the config to
> route requests to these apps related to the mount point.
>
> So I thought ... if I register 2 apps in my plugin named "app_a" and
> "app_b", i would like these to be bound to two different mount points,
> like this :
>
> mount= /a=app_a
> mount= /b=app_b
>
> I my plugin the "mount_app" callback will be called with these mount
> arguments, but I have no idea as to how to relate these to the apps I
> have registered.
>
> Can anyone provide some basic info on the ideas as to how this should
> work, or maybe point to some documentation.
>
> Kind regards
>
> /BL
>
>


Hi, first of all mounting and apps are absolutely separated concepts, an
app is an "entry point" in your server code (like a function pointer).

Once you have a created an app it gets an id (a signed integer starting
from 0).

Dealing with app-ids (as a number) is unpractical so you can "mount" them
(or "map" if you prefer) to a "string". As we generally deal with HTTP in
uWSGI, the common pattern is to mount in uri (like /foo or /bar), but you
can generally assign whatever name you want.

Now, you are dealing with C++, so i suppose you have a function pointer as
the entry point (something you expose with extern "C" in your code)

If you expose the mount_app hook in your plugin, the function will be
called for each mount option:

mount = /foo=hello_world
mount = /bar=simple_func

will cal your hook 2 times:

int yourplugin_mount_app(char *mountpoint, char *something) {
        // check for maximum number of apps
        if (uwsgi_apps_cnt >= uwsgi.max_apps) {
                return -1;
        }
        // get the id for your app
        int id = uwsgi_apps_cnt;
        // get a pointer to your function
        void *ptr = dlsym(something, ...);
        // be sure to have a final \0 on mountpoint string
        struct uwsgi_app *wi = uwsgi_add_app(id, modifier1, mountpoint,
mountpoint_len, ptr, ptr);

        // the loading time is basically 0 in c/c++ so we can hardcode them
        wi->started_at = uwsgi_now();
        wi->startup_time = 0;

        // ensure app is initialized on all workers (even without a master)
        uwsgi_emulate_cow_for_apps(id);
        return id;
}

as you can see uwsgi_add_app() last two arguments are the same. This is
because i did not find something additional to pass, but you can use it
for whatever you want

now in your request() handler you can get the app with:

wsgi_req->app_id = uwsgi_get_app_id(wsgi_req, wsgi_req->appid,
wsgi_req->appid_len, modifier1);

and if it is >= 0

struct uwsgi_app *wi = &uwsgi_apps[wsgi_req->app_id];

and in wi->interpreter or wi->callable you have the pointer of your function

Well, i think it should be enough for starting :)

Remember that once you have defined mountpoints, you need to add some
"routing rule", the simple one is --manage-script-name that maps
SCRIPT_NAME to the mountpoint, but you can set complex rule with the
internal routing framework:

route = ^/foo setapp:/foo

-- 
Roberto De Ioris
http://unbit.com
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to