the PactHandle that is returned by `pactffi_new_pa...
# libpact_ffi-users
p
the PactHandle that is returned by
pactffi_new_pact
is defined as this in the pact.h file:
typedef uint16_t PactHandle;
The problem is when i am calling
pactffi_create_mock_server_for_transport
with PactHandle as lets say 1 (
uint16_t
) , it returns me -1 which means
An invalid handle was received. Handles should be created with pactffi_new_pact
Am i missing something here? Thanks in advance Edit: I am writing wrappers for these functions in C, so that I can then finally use Erlang NIFs to call these wrapper functions
1
y
each time you call pactffi_new_pact you get an opaque pointer, which is an incrementing id reference, to a pointer held in pact_ffi's address space. have you called
pactffi_new_pact
and passed the result (which is the interaction handle) to
pactffi_create_mock_server_for_transport
thankyou 1
p
I am first creating a new pact with
pactffi_new_pact
, then I am storing the returned value in my erlang code, then again invoking pact_ffi_new_interaction(PactHandle, Description) from my erlang code which then invokes my c code. My sample C code for pact_ffi_new_interaction looks like this:
Copy code
static ERL_NIF_TERM erl_pactffi_new_interaction(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    unsigned int len1;
    enif_get_list_length(env, argv[1], &len1);
    char *buf1 ; // This is my interaction description
    buf1 = (char *)malloc(len1 * sizeof(char));
    if (!enif_get_string(env, argv[1], buf1, sizeof(buf1), ERL_NIF_LATIN1)) {
        return enif_make_badarg(env);
    }
    int ip; // This is my PactHandle
    if (!enif_get_int(env, argv[0], &ip)) {
        return enif_make_badarg(env);
    }
    PactHandle pacthandle = ip;
    InteractionHandle interactionhandle = pactffi_new_interaction(pacthandle, buf1);
    return enif_make_int(env, interactionhandle);
}
I think i got your point, I will have to invoke the
pactffi_create_mock_server_for_transport
from where I am creating the
pactffi_new_pact
right ?
can i not fetch the pacthandle from that int that I am getting in return ?
okay, i changed the code to typecast the int to PactHandle which i was not doing earlier, now i am getting -3 (the code says mock server could not be started)
I enabled logging for ffi, it seems i was giving the wrong address unintentionally from my erlang code, thanks @Yousaf Nabi (pactflow.io)
🙌 1
y
saweet! yeah tip 1 always enable logging :)