2014-11-19 00:25:21 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include "acl_cpp/acl_cpp_define.hpp"
|
|
|
|
|
#include <list>
|
|
|
|
|
#include "acl_cpp/stream/aio_socket_stream.hpp"
|
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
typedef struct MSG_HDR
|
|
|
|
|
{
|
|
|
|
|
int nMsg;
|
|
|
|
|
int dlen;
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
__int64 magic;
|
|
|
|
|
#else
|
|
|
|
|
long long int magic;
|
|
|
|
|
#endif
|
|
|
|
|
} MSG_HDR;
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
IO_WAIT_HDR,
|
|
|
|
|
IO_WAIT_DAT
|
|
|
|
|
} io_status;
|
|
|
|
|
|
|
|
|
|
class aio_handle;
|
|
|
|
|
class ipc_adapter;
|
|
|
|
|
class aio_socket_stream;
|
|
|
|
|
class socket_stream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽IP<EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
class ACL_CPP_API ipc_client : private aio_open_callback
|
|
|
|
|
{
|
|
|
|
|
public:
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
ipc_client(__int64 magic = -1);
|
|
|
|
|
#else
|
|
|
|
|
ipc_client(long long int magic = -1);
|
|
|
|
|
#endif
|
|
|
|
|
virtual ~ipc_client();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٽӿڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظýӿ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void destroy()
|
|
|
|
|
{
|
|
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> open <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_open() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD>ӿ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_close() {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD>Ϣʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ָýӿ<EFBFBD>
|
|
|
|
|
* @param nMsg {int} <EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣֵ
|
|
|
|
|
* @param data {void*} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dlen {int} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_message(int nMsg, void* data, int dlen);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD>佨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD>
|
|
|
|
|
* @param handle {aio_handle*} <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ:
|
2015-06-29 17:33:11 +08:00
|
|
|
|
* IP:PORT(֧<EFBFBD><EFBFBD>_WIN32/UNIX)<EFBFBD><EFBFBD>unix_path (<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>UNIX)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @param timeout {int} <EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool open(aio_handle* handle, const char* addr, int timeout);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ipc_client <EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param client {aio_socket_stream*} <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void open(aio_socket_stream* client);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD>佨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ:
|
2015-06-29 17:33:11 +08:00
|
|
|
|
* IP:PORT(֧<EFBFBD><EFBFBD>_WIN32/UNIX)<EFBFBD><EFBFBD>unix_path (<EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD>UNIX)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
* @param timeout {int} <EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool open(const char* addr, int timeout);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ipc_client <EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param client {socket_stream*} <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void open(socket_stream* client);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IPC ͨ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void wait();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void close();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool active() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param nMsg {int} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void append_message(int nMsg);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ɾ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param nMsg {int} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void delete_message(int nMsg);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param nMsg {int} <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param data {const void*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dlen {int} <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void send_message(int nMsg, const void* data, int dlen);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {aio_socket_stream*}
|
|
|
|
|
*/
|
|
|
|
|
aio_socket_stream* get_async_stream() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
aio_handle& get_handle() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {socket_stream*}
|
|
|
|
|
*/
|
|
|
|
|
socket_stream* get_sync_stream() const;
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param nMsg {int} <EFBFBD><EFBFBD>ϢID
|
|
|
|
|
* @param data {void*} <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
|
|
|
|
|
* @param dlen {int} <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void trigger(int nMsg, void* data, int dlen);
|
|
|
|
|
private:
|
2015-06-29 17:33:11 +08:00
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2014-11-19 00:25:21 +08:00
|
|
|
|
__int64 magic_;
|
|
|
|
|
#else
|
|
|
|
|
long long int magic_;
|
|
|
|
|
#endif
|
|
|
|
|
char* addr_;
|
|
|
|
|
std::list<int> messages_;
|
2015-01-04 22:51:01 +08:00
|
|
|
|
//aio_handle* handle_;
|
2014-11-19 00:25:21 +08:00
|
|
|
|
aio_socket_stream* async_stream_;
|
|
|
|
|
socket_stream* sync_stream_;
|
|
|
|
|
socket_stream* sync_stream_inner_;
|
|
|
|
|
bool closing_;
|
|
|
|
|
|
|
|
|
|
io_status status_;
|
|
|
|
|
MSG_HDR hdr_;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>麯<EFBFBD><E9BAAF>
|
|
|
|
|
|
|
|
|
|
virtual bool read_callback(char* data, int len);
|
|
|
|
|
virtual bool write_callback();
|
|
|
|
|
virtual void close_callback();
|
|
|
|
|
virtual bool timeout_callback();
|
|
|
|
|
virtual bool open_callback();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|