コード例 #1
0
ファイル: pa.c プロジェクト: jaccovanschaik/libjvs
int main(int argc, char *argv[])
{
    PointerArray pa = { 0 };

    paSet(&pa, 0, (void *) 0x1);

    make_sure_that(paCount(&pa) == 1);
    make_sure_that(paGet(&pa, 0) == (void *) 0x1);
    make_sure_that(paGet(&pa, 1) == NULL);
    make_sure_that(paGet(&pa, 2) == NULL);

    paSet(&pa, 2, (void *) 0x3);

    make_sure_that(paCount(&pa) == 3);
    make_sure_that(paGet(&pa, 0) == (void *) 0x1);
    make_sure_that(paGet(&pa, 1) == NULL);
    make_sure_that(paGet(&pa, 2) == (void *) 0x3);

    paSet(&pa, 1, (void *) 0x2);

    make_sure_that(paCount(&pa) == 3);
    make_sure_that(paGet(&pa, 0) == (void *) 0x1);
    make_sure_that(paGet(&pa, 1) == (void *) 0x2);
    make_sure_that(paGet(&pa, 2) == (void *) 0x3);

    paDrop(&pa, 0);

    make_sure_that(paCount(&pa) == 3);
    make_sure_that(paGet(&pa, 0) == NULL);
    make_sure_that(paGet(&pa, 1) == (void *) 0x2);
    make_sure_that(paGet(&pa, 2) == (void *) 0x3);

    paDrop(&pa, 2);

    make_sure_that(paCount(&pa) == 2);
    make_sure_that(paGet(&pa, 0) == NULL);
    make_sure_that(paGet(&pa, 1) == (void *) 0x2);
    make_sure_that(paGet(&pa, 2) == NULL);

    paDrop(&pa, 1);

    make_sure_that(paCount(&pa) == 0);
    make_sure_that(paGet(&pa, 0) == NULL);
    make_sure_that(paGet(&pa, 1) == NULL);
    make_sure_that(paGet(&pa, 2) == NULL);

    paClear(&pa);
}
コード例 #2
0
static void ns_add_connection(NS *ns, int fd)
{
    NS_Connection *conn = calloc(1, sizeof(NS_Connection));

    paSet(&ns->connections, fd, conn);

P   dbgPrint(stderr, "New connection on fd %d\n", fd);

    disOnData(&ns->dis, fd, ns_handle_data, NULL);
}
コード例 #3
0
/*
 * Arrange for <cb> to be called when there is data available on file descriptor <fd>. <cb> will be
 * called with the given <dis>, <fd> and <udata>, which is a pointer to "user data" that will be
 * returned <cb> as it was given here, and that will not be accessed by dis in any way.
 */
void disOnData(Dispatcher *dis, int fd,
        void (*cb)(Dispatcher *dis, int fd, void *udata), const void *udata)
{
    DIS_File *file;

    dbgAssert(stderr, fd >= 0, "bad file descriptor: %d\n", fd);

P   dbgPrint(stderr, "Adding file on fd %d\n", fd);

    if ((file = paGet(&dis->files, fd)) == NULL) {
        file = calloc(1, sizeof(DIS_File));

        paSet(&dis->files, fd, file);
    }

    file->cb = cb;
    file->udata = udata;
}