MPs queue in Linux

Source: Internet
Author: User
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;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.