コード例 #1
0
ファイル: fmq_server.c プロジェクト: JuanCerezuela/filemq
static bool
mount_refresh (mount_t *self, server_t *server)
{
    bool activity = false;

    //  Get latest snapshot and build a patches list for any changes
    fmq_dir_t *latest = fmq_dir_new (self->location, NULL);
    zlist_t *patches = fmq_dir_diff (self->dir, latest, self->alias);

    //  Drop old directory and replace with latest version
    fmq_dir_destroy (&self->dir);
    self->dir = latest;

    //  Copy new patches to clients' patches list
    sub_t *sub = (sub_t *) zlist_first (self->subs);
    while (sub) {
        fmq_patch_t *patch = (fmq_patch_t *) zlist_first (patches);
        while (patch) {
            sub_patch_add (sub, patch);
            patch = (fmq_patch_t *) zlist_next (patches);
            activity = true;
        }
        sub = (sub_t *) zlist_next (self->subs);
    }
    
    //  Destroy patches, they've all been copied
    while (zlist_size (patches)) {
        fmq_patch_t *patch = (fmq_patch_t *) zlist_pop (patches);
        fmq_patch_destroy (&patch);
    }
    zlist_destroy (&patches);
    return activity;
}
コード例 #2
0
ファイル: fmq_server.c プロジェクト: asgibbons/filemq
static void
mount_sub_store (mount_t *self, client_t *client, fmq_msg_t *request)
{
    assert (self);
    assert (self->subs);
    
    //  Store subscription along with any previous ones
    //  Coalesce subscriptions that are on same path
    char *path = fmq_msg_path (request);
    sub_t *sub = (sub_t *) zlist_first (self->subs);
    while (sub) {
        if (client == sub->client) {
            //  If old subscription is superset/same as new, ignore new
            if (strncmp (path, sub->path, strlen (sub->path)) == 0)
                return;
            else
            //  If new subscription is superset of old one, remove old
            if (strncmp (sub->path, path, strlen (path)) == 0) {
                zlist_remove (self->subs, sub);
                sub_destroy (&sub);
                sub = (sub_t *) zlist_first (self->subs);
            }
            else
                sub = (sub_t *) zlist_next (self->subs);
        }
        else
            sub = (sub_t *) zlist_next (self->subs);
    }
    //  New subscription for this client, append to our list
    sub = sub_new (client, path, fmq_msg_cache (request));
    zlist_append (self->subs, sub);

    //  If client requested resync, send full mount contents now
    if (fmq_msg_options_number (client->request, "RESYNC", 0) == 1) {
        zlist_t *patches = zdir_resync (self->dir, self->alias);
        while (zlist_size (patches)) {
            zdir_patch_t *patch = (zdir_patch_t *) zlist_pop (patches);
            sub_patch_add (sub, patch);
            zdir_patch_destroy (&patch);
        }
        zlist_destroy (&patches);
    }
}