mnSetFunction

This command is designed to aid with high performance applications.

Traditionally data is transferred from the worker threads to your application via the mnRecv commands. This is not the most efficient way of doing things because the threads must wait for the mnRecv command to become available and must copy data into mnRecv buffers.

A better way of doing things is to have the worker threads deal with the packets directly. mnSetFunction allows you to set a UDP and a TCP function that will receive each type of packet as it comes in.

One problem that you must consider is the issue of multi threading. More than one thread cannot write to the same resource at the same time and more than one thread cannot write and read from the same resource at the same time. Your function may be executed at the same time by multiple threads.

DarkNet only guarantees that the references passed to the functions will remain valid until the function returns.

If a TCP packet is received in client state whilst the client is connecting, it will be picked up by mnConnect or mnPollConnect and forwarded to the TCP function. In this case the packet will not be directly from a thread and so the thread parameter will not represent a thread. Instead it will be equal to the maximum number of threads.

The functions passed as parameters to this command should have the prototype:

void mnFunc(int Thread, clPacket & Packet);

There is demo code that demonstrates how to use this command.

Parameters

int Instance: This is the instance that the command should use.

void (*TCPRecvFunc)(int & ThreadID, clPacket & Packet): This is the function that will be executed every time a new TCP packet is received by the specified instance. The parameter is a pointer to a function.

void (*UDPRecvFunc)(int & ThreadID, clPacket & Packet): This is the function that will be executed every time a new UDP packet is received by the specified instance. The parameter is a pointer to a function.

Returns (Integer)

0 if no error occurred

-1 if an error occurred.

Present in

C++




This page is in the following sections:
(2) Networking Commands
(1) Networking
(0) DarkNet Help