Пример #1
0
void applyToHeap(GenericHeap* hp, void (*fnPtr)(void * ))
{
	void * index;
	int i;
	for(i=1; i<= hp->lastIndex ; i++)
	{
		index=hp->container[i];
		fnPtr(index);	
	}

}
Пример #2
0
int main() {
	void (*fnPtr)(void *);
	void (*delPtr)(void *);
	void *data;

	{
        std::string capture = "Help, I've been captured!";
		auto lambda = makeClosure<>([=] { std::cout << capture << '\n'; });

		fnPtr = lambda.invoke;
		delPtr = lambda.destroy;
		data = lambda.release();
	}

	fnPtr(data);
	delPtr(data);
}
Пример #3
0
int readDataFromSocket(int socketFD, int (*fnPtr)(int, char*, int)) {
    ssize_t length = 0;
    char *buf;
    buf = malloc(sizeof(char) * MAXBUFFSIZE);
    if (buf == NULL) {
        perror("MALLOC");
        abort();
    }


    while (1) {
        ssize_t count;
        count = read (socketFD, &buf[length], MAXBUFFSIZE - length);
        length += count;
        if (length == MAXBUFFSIZE) {
            printf("hope this never is reached");
            //some error condition here
        }
        switch (count) {
        case -1:
            if (errno != EAGAIN) {
                perror ("read");
                return 1;
            }
            if (length != 0) {
                return fnPtr(socketFD, buf, length);
            }
            //not sure what to do here so falling throught
        case 0:
            return 1;
        default:
            continue;
        }
    }
    return 0;
}