×
Namespaces

Variants
Actions
Revision as of 08:16, 17 September 2009 by Narendrachinni (Talk | contribs)

Named Pipes Example

From Nokia Developer Wiki
Jump to: navigation, search

Named Pipes Description

{{{width}}}

The following code shows the usage of named pipes(follows the steps given in the above link):

#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#include <pthread.h>
 
const char* fifopath = "C:\\mkfifo.file";
unsigned int threadid;
 
// thread entry point
void* FifoWriterThread(void* arg)
{
const char* buf = "somejunk";
TInt fd = open (fifopath, O_WRONLY);
if(fd > 0 )
{
write(fd, buf, 9);
close(fd);
}
return 0;
}
 
void CreateThreadL()
{
pthread_create(&threadid,(pthread_attr_t *)NULL,FifoWriterThread, NULL);
}
 
void OpenForRead()
{
int err = mkfifo (fifopath, 0666);
if(err != 0)
{
// probably file already exists, delete the file
unlink(fifopath);
// try once more..
err = mkfifo (fifopath, 0666);
if(err != 0)
{
return;
}
}
CreateThreadL();
char buf[128];
TInt fd = open (fifopath, O_RDONLY);
if ( fd ( 0 )
{
return ;
}
err = read (fd, buf, 128);
close(fd);
unlink(fifopath);
}
 
int main()
{
OpenForRead();
return 0;
}
128 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×