-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathxpipe.h
More file actions
48 lines (43 loc) · 889 Bytes
/
xpipe.h
File metadata and controls
48 lines (43 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef __XPIPEH__
#define __XPIPEH__
#include <unistd.h>
#include <string>
#include <string.h>
#include <stdio.h>
using namespace std;
/*
无名管道的C++封装类,用于父子进程进行通信
作者 :陈学友
时间 :2013年7月15日 20:30:58
邮 箱:chen_xueyou@163.com
*/
class xpipe
{
public:
xpipe();
~xpipe();
///核心方法
ssize_t send(void *buf, size_t n);
ssize_t recv(void *buf, size_t nbytes);
///常用方法特化
ssize_t send(const string &content);
ssize_t recv(string &content);
//确定通信角色
void senderonly(){DisReadable();}
void receiveronly(){DisWriteable();}
//属性操作
string role() const;
long Bufsize(long newbufsize=0);
private:
//读写关闭操作
void DisReadable();
void DisWriteable();
/* data */
private:
int m_fd[2];
bool m_readable;
bool m_writeable;
long m_bufsize;
char * m_buf;
};
#endif