Client. C function: send data to the MPs queue
# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
# Include <sys/IOCTL. h>
# Include <sys/types. h>
# Include <sys/STAT. h>
# Include <fcntl. h>
# Include <sys/select. h>
# Include <sys/time. h>
# Define sip_pipe "/tmp/SIP-Reg"
# Define msg_size 100
Int main (void)
{
Int sip_writer_fd;
Static char buffer [msg_size];
Int test = 1000;
Sip_writer_fd = open (sip_pipe, o_wronly | o_nonblock );
If (sip_writer_fd <0 ){
Perror ("Open Control Pipe for write ");
Exit (1 );
}
For (;;)
{
Memset (buffer, 0, sizeof buffer );
Sprintf (buffer, "% d/N", test ++ );
Write (sip_writer_fd, buffer, strlen (buffer ));
Sleep (1 );
}
Return 0;
}
Server. C function: Reads and prints data from a media transcoding queue to a terminal.
Int main (void)
{
Int sip_control_pipe;
Static char buffer [msg_size];
Double period = 0.5;
Unlink (sip_pipe );
Mkfifo (sip_pipe, 0666 );
Sip_control_pipe = open (sip_pipe, o_rdonly | o_nonblock );
If (sip_control_pipe <0)
{
Perror ("Open Control Pipe for read ");
Exit (1 );
}
For (;;)
{
Fd_set RDS;
Struct timeval step;
Int ret, Len;
Fd_zero (& RDs );
Fd_set (sip_control_pipe, & RDs );
Step. TV _sec = period;
Step. TV _usec = (period-step. TV _sec) * 000000l;
Ret = select (sip_control_pipe + 1, & RDS, null, null, & step );
If (Ret <0 ){
Perror ("select ");
Exit (1 );
}
If (Ret! = 0) & (fd_isset (sip_control_pipe, & RDs )))
{
Memset (buffer, 0, sizeof buffer );
Len = read (sip_control_pipe, buffer, msg_size );
If (LEN <msg_size)
{
Printf (buffer );
}
}
}
Return 0;
}