Exemplo n.º 1
0
static
GCS_BACKEND_CLOSE_FN(dummy_close)
{
    long     ret   = -ENOMEM;
    dummy_t* dummy = backend->conn;
    gcs_comp_msg_t* comp;
    
    if (!dummy) return -EBADFD;

    comp = gcs_comp_msg_leave ();

    if (comp) {
        ret = gcs_comp_msg_size(comp);
        ret = gcs_dummy_inject_msg (backend, comp, ret, GCS_MSG_COMPONENT,
                                    GCS_SENDER_NONE);
        // Here's a race condition - some other thread can send something
        // after leave message. But caller should guarantee serial access.
        gu_fifo_close (dummy->gc_q);
        if (ret > 0) ret = 0;
	gcs_comp_msg_delete (comp);
    }

    dummy->state = DUMMY_CLOSED;

    return ret;
}
Exemplo n.º 2
0
static
GCS_BACKEND_OPEN_FN(dummy_open)
{
    long     ret   = -ENOMEM;
    dummy_t* dummy = backend->conn;
    gcs_comp_msg_t* comp;

    if (!dummy) {
        gu_debug ("Backend not initialized");
        return -EBADFD;
    }

    comp = gcs_comp_msg_new (true, false, 0, 1);
 
    if (comp) {
	ret = gcs_comp_msg_add (comp, "11111111-2222-3333-4444-555555555555");
	assert (0 == ret); // we have only one member, index = 0

        dummy->state = DUMMY_TRANS; // required by gcs_dummy_set_component()
        ret = gcs_dummy_set_component (backend, comp); // install new component
        if (ret >= 0) {                                // queue the message
            ret = gcs_comp_msg_size(comp);
            ret = gcs_dummy_inject_msg (backend, comp, ret, GCS_MSG_COMPONENT,
                                        GCS_SENDER_NONE);
            if (ret > 0) ret = 0;
        }
	gcs_comp_msg_delete (comp);
    }
    gu_debug ("Opened backend connection: %d (%s)", ret, strerror(-ret));
    return ret;
}
Exemplo n.º 3
0
static bool
DUMMY_INJECT_COMPONENT (gcs_backend_t* backend, const gcs_comp_msg_t* comp)
{
    long ret = gcs_dummy_inject_msg (Backend, comp,
                                     gcs_comp_msg_size(comp),
                                     GCS_MSG_COMPONENT, GCS_SENDER_NONE);
    FAIL_IF (ret <= 0, "gcs_dummy_inject_msg(): %ld (%s)", ret, strerror(ret));

    return false;
}
Exemplo n.º 4
0
static
GCS_BACKEND_SEND_FN(dummy_send)
{
    int err = 0;
    dummy_t* dummy = backend->conn;

    if (gu_unlikely(NULL == dummy)) return -EBADFD;

    if (gu_likely(DUMMY_PRIM == dummy->state))
    {
        err = gcs_dummy_inject_msg (backend, buf, len, msg_type,
                                    backend->conn->my_idx);
    }
    else {
        static long send_error[DUMMY_PRIM] =
            { -EBADFD, -EBADFD, -ENOTCONN, -EAGAIN };
	err = send_error[dummy->state];
    }

    return err;
}