示例#1
0
void testCoroutineStreamOther(void *in_pStreamState,
	CoroutineStreamInitFunction in_initFun, 
	CoroutineStreamDestroyFunction in_destroyFun)
{
	ByteStreamInterface byteStreamInterface;
	ByteStreamReference byteStreamReference;
	CoroutineDescriptor thisCoroutine;
	CoroutineDescriptor otherCoroutine;
	unsigned int bytesToReadArray[] = { 2, 32 };
	size_t idx;

	// Test 1, 2: the current coroutine is the writer and 2 or 32 bytes are read
	for (idx = 0; idx < 2; idx++)
	{
		bool result = (*in_initFun)(in_pStreamState, &byteStreamInterface, 
			true, &thisCoroutine, &otherCoroutine, 
			&readerCoroutineFun, bytesToReadArray+idx);

		test(result);

		if (!result)
			return;

		byteStreamReference.mByteStreamInterface = byteStreamInterface;
		byteStreamReference.mpByteStreamState = in_pStreamState;

		writeFun(byteStreamReference, bytesToReadArray[idx]);
		test((*byteStreamInterface.mpfWrite)(in_pStreamState, NULL, 0) == 0);

		(*in_destroyFun)(in_pStreamState);
	}

	// Test 3, 4: the current coroutine is the reader and 2 or 32 bytes are read
	for (idx = 0; idx < 2; idx++)
	{
		bool result = (*in_initFun)(in_pStreamState, &byteStreamInterface, 
			false, &thisCoroutine, &otherCoroutine, 
			&writerCoroutineFun, bytesToReadArray+idx);

		test(result);

		if (!result)
			return;

		byteStreamReference.mByteStreamInterface = byteStreamInterface;
		byteStreamReference.mpByteStreamState = in_pStreamState;

		readFun(byteStreamReference, bytesToReadArray[idx]);
		test((*byteStreamInterface.mpfRead)(in_pStreamState, NULL, 0) == 0);

		(*in_destroyFun)(in_pStreamState);
	}
}
void Notification(ADDRINT val)
{
    char buff[80];

    if (!writeFun)
    {
        fprintf(stderr, "Write Function was not initialized ...\n");
        exit(1);
    }

    sprintf(buff, "Notification value: %p", Addrint2VoidStar(val));
    writeFun(buff);
}
示例#3
0
void writerCoroutineFun(ByteStreamReference in_byteStreamReference, void *in_pUserdata)
{
	unsigned int *bytesToRead = (unsigned int *) in_pUserdata;
	writeFun(in_byteStreamReference, *bytesToRead);
}