Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Exemplos de pipes rotulados

From Wiki
Jump to: navigation, search
Article Metadata

Artigo
Tradução:
Originado de Named Pipes Example
Por kyllercg
Última alteração feita por hamishwillee em 09 Dec 2011



Pipes rotulados

O código a seguir mostra como usar pipes rotulados.

#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;
 
// Início da thread
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)
{
// possivelmente o arquivo já existe, apague-o
unlink(fifopath);
// tente outra vez...
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;
}
This page was last modified on 9 December 2011, at 04:33.
278 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.

×