Beispiel #1
0
static void web_SockJsServer_close(web_SockJsServer _this, struct mg_connection *conn) {
    web_SockJsServer_Connection c = web_SockJsServer_Connection(conn->connection_param);
    if (c) {
        if (_this->onClose._parent.procedure) {
            cx_call(_this->onClose._parent.procedure, NULL, _this->onClose._parent.instance, c);
        }
        c->conn = 0;
        cx_destruct(c);
        conn->connection_param = NULL;
    }
}
Beispiel #2
0
/* Handle incoming HTTP events */
static int web_handler(struct mg_connection *conn, enum mg_event ev) {
    int result = MG_TRUE;

    switch (ev) {
    case MG_AUTH:
        break;

    /* New websocket connection */
    case MG_WS_CONNECT: {
        cx_id id;
        web_server s = conn->server_param;
        sprintf(id, "C%d", s->connectionId);

        /* Create connection object */
        web_wsconnection wc = web_wsconnection__declare(s, id);
        s->connectionId++;
        wc->conn = (cx_word)conn;
        web_wsconnection__define(wc, NULL, conn->remote_ip, conn->remote_port);

        /* Set dispatcher for trigger */
        cx_observer_setDispatcher(web_wsconnection_onUpdate_o, (cx_dispatcher)s);
        cx_observer_setDispatcher(web_wsconnection_onDelete_o, (cx_dispatcher)s);

        conn->connection_param = wc;
        break;
    }

    /* Close websocket connection */
    case MG_CLOSE:
        if (conn->connection_param) {
            web_wsconnection wc = conn->connection_param;
            if (wc->observing) {
                /* Remove connection from observer queue */
                cx_silence(wc->observing, web_wsconnection_onUpdate_o, wc);
                cx_silence(wc->observing, web_wsconnection_onDelete_o, wc);
                /* Set observing to NULL */
                cx_set(&wc->observing, NULL);
            }
            /* Set connection parameter to NULL since pointer
             * will be invalid after this callback */
            wc->conn = 0;
            cx_destruct(wc);
            conn->connection_param = NULL;
        }
        break;

    /* HTTP request */
    case MG_REQUEST: 
        /* If request is a websocket, forward to websocket handler */
        if (conn->is_websocket) {
            if (conn->content_len) {
                result = web_socketHandler(conn);
            }
        } else {
            /* If the URI is prefixed with a '_' an object is requested */
            if (!memcmp(conn->uri, "/_", 2)) {
                result = web_serveObject(conn);

            /* If the URI contains a '.' before a '?' a file is requested */
            } else if (strchr (conn->uri, '.')) {
                result = web_serveFile(conn, conn->uri + 1);

            /* If none of the above, serve index.html. Since the client
             * is a single page app, the URI can contain a path to the
             * object currently displayed. This URI is not relevant for
             * the server. However, when such a URI is requested, the 
             * index.html file must be served. */
            } else {
                result = web_serveFile(conn, "index.html");
            }
        }
        break;
    case MG_HTTP_ERROR:
        result = FALSE;
        break;
    case MG_POLL:
        result = FALSE;
        break;
    default:
        result = MG_FALSE;
        break;
    }

    return result;
}
Beispiel #3
0
/* ::cortex::lang::type::delete() */
cx_void cx_type_delete(cx_any _this) {
/* $begin(::cortex::lang::type::delete) */
    cx_destruct(_this.value);
/* $end */
}