Code Examples.
Code Examples.
The following example shows how to create a commport, sending and receiving messages on it and then deleting it.
As a first step, a communication port is created. For creating a commport we can specify a required communication port id, if the commport is going to serve as a well known server. This can be chosen from clIocServices.h file. If 0 is passed for commPortId then the IOC will chose one commomuincation port id for the application. For sending and receiving through this communication port the communication handle should be used.
ClUint32T commPortId = 0x8888;
}
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
ClWordT ClIocCommPortHandleT
The Communication port handle.
Definition: clIocApi.h:353
#define CL_IOC_RELIABLE_MESSAGING
Communication port creation related flags .
Definition: clIocApi.h:129
ClRcT clIocCommPortCreate(CL_IN ClIocPortT portId, CL_IN ClIocCommPortFlagsT portType, CL_OUT ClIocCommPortHandleT *pIocCommPortHdl)
Creates a communication port.
Here we can see how a message can be sent to a destination. The protocol field is a must for sending a packet, and it should be chosen from clIocProtocols.h file. The data to be sent should be passed as a buffer message. And the receiver address can be a physical, logical or a multicast address.
ClUint32T protocol;
protocol = USER_PROTOCOL;
sendBuffer,
protocol,
&receiverAddress,
&sendOption);
{
}
ClPtrT ClBufferHandleT
The type of the handle for the buffer messages.
Definition: clBufferApi.h:82
ClRcT clIocSend(CL_IN ClIocCommPortHandleT commPortHandle, CL_IN ClBufferHandleT message, CL_IN ClUint8T protoType, CL_IN ClIocAddressT *pDestAddr, CL_IN ClIocSendOptionT *pSendOption)
Sends message on a communication port.
#define CL_IOC_TIMEOUT_FOREVER
Infinite timeout.
Definition: clIocApi.h:115
IOC address.
Definition: clIocApi.h:401
Send related options.
Definition: clIocApi.h:457
ClUint32T timeout
The timeout interval in milliseconds.
Definition: clIocApi.h:481
ClUint8T priority
Message priority.
Definition: clIocApi.h:462
The clIocReceive() call will block on the commport for receiving a message. The call expects a valid buffer message handle to receive the data. On receiving some data the IOC unblocks the receiver thread, which is blocked on the commport. All the information relating to the message received( like sender info, length of the message, protocol for analysing the message), will be present in recvParam.
recvOption,
recvBuffer,
recvParam);
{
}
ClRcT clIocReceive(CL_IN ClIocCommPortHandleT commPortHdl, CL_IN ClIocRecvOptionT *pRecvOption, CL_OUT ClBufferHandleT userMsg, CL_OUT ClIocRecvParamT *pRecvParam)
Receives message on communication port.
The IOC receive returns this structure along with the message.
Definition: clIocApi.h:491
IOC receive options.
Definition: clIocApi.h:523
For deleting a commport a valid commPortHandle must be passed. And before calling this API we need make sure that no thread is waiting for any data on this commport.
{
}
ClRcT clIocCommPortDelete(CL_IN ClIocCommPortHandleT iocCommPortHdl)
Deletes the communication port.