mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
#include "export.h"
|
|
#include "def.h"
|
|
#include "shm.h"
|
|
|
|
namespace ipc {
|
|
|
|
using shm::handle_t;
|
|
using buff_t = std::vector<byte_t>;
|
|
|
|
IPC_EXPORT buff_t make_buff(void const * data, std::size_t size);
|
|
|
|
template <std::size_t N>
|
|
buff_t make_buff(byte_t const (& data)[N]) { return make_buff(data, N); }
|
|
|
|
IPC_EXPORT handle_t connect (char const * name);
|
|
IPC_EXPORT void disconnect(handle_t h);
|
|
|
|
IPC_EXPORT std::size_t recv_count(handle_t h);
|
|
|
|
IPC_EXPORT bool send(handle_t h, void const * data, std::size_t size);
|
|
IPC_EXPORT buff_t recv(handle_t h);
|
|
|
|
class IPC_EXPORT channel {
|
|
public:
|
|
channel();
|
|
channel(char const * name);
|
|
channel(channel&& rhs);
|
|
|
|
~channel();
|
|
|
|
void swap(channel& rhs);
|
|
channel& operator=(channel rhs);
|
|
|
|
bool valid() const;
|
|
char const * name () const;
|
|
|
|
channel clone() const;
|
|
|
|
bool connect(char const * name);
|
|
void disconnect();
|
|
|
|
std::size_t recv_count() const;
|
|
|
|
bool send(void const * data, std::size_t size);
|
|
bool send(buff_t const & buff);
|
|
bool send(std::string const & str);
|
|
|
|
buff_t recv();
|
|
|
|
private:
|
|
class channel_;
|
|
channel_* p_;
|
|
};
|
|
|
|
} // namespace ipc
|