improve ipc msg
parent
99ea8d1646
commit
0712460db0
@ -1,35 +0,0 @@
|
||||
#include "RpcChannel.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class RpcChannelFifo : public RpcChannel {
|
||||
public:
|
||||
RpcChannelFifo(const char* inPipe, const char* outPipe) {
|
||||
fdOut = open(inPipe, O_WRONLY);
|
||||
fdIn = open(outPipe, O_RDONLY);
|
||||
}
|
||||
|
||||
void send(const std::string& data) override {
|
||||
::write(fdOut, data.c_str(), data.size());
|
||||
::write(fdOut, "\n", 1);
|
||||
}
|
||||
|
||||
std::string receive() override {
|
||||
char buf[4096];
|
||||
int n = ::read(fdIn, buf, sizeof(buf) - 1);
|
||||
if (n <= 0) {
|
||||
return {};
|
||||
}
|
||||
buf[n] = 0;
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
private:
|
||||
int fdIn{};
|
||||
int fdOut{};
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue