×
Namespaces

Variants
Actions
Revision as of 07:33, 9 December 2011 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Exemplos de pipes rotulados

From Nokia Developer 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 07:33.
99 page views in the last 30 days.