📄 ipc.h
字号:
* sent out to (or received by) the peer. It may be pending * in the send_queue. In order to make sure the message is no * longer needed, please specify the msg_done function in the * message structure and once this function is called, the * message is no longer needed. * * is_sending_blocked() is another way to check if there is a message * pending in the send_queue. * */ int (* recv) (IPC_Channel * ch, IPC_Message** msg);/* * IPC_OPS::waitin * Wait for input to become available * * Parameters: * ch (IN) : the channel which contains the connection. * * Side effects: * If output becomes unblocked while waiting, it will automatically * be resumed without comment. * * Return values: * IPC_OK : a message is pending or output has become unblocked. * IPC_FAIL : operation failed. * IPC_BROKEN : the channel is broken (disconnected) * IPC_INTR : waiting was interrupted by a signal */ int (* waitin) (IPC_Channel * ch);/* * IPC_OPS::waitout * Wait for output to finish * * Parameters: * ch (IN) : the channel which contains the connection. * * Side effects: * If input becomes available while waiting, it will automatically * be read into the channel queue without comment. * * Return values: * IPC_OK : output no longer blocked * IPC_FAIL : operation failed. * IPC_BROKEN : the channel is broken (disconnected) * IPC_INTR : waiting was interrupted by a signal */ int (* waitout) (IPC_Channel * ch);/* * IPC_OPS::is_message_pending * check to see if there is any messages ready to read, or hangup has * occurred. * * Parameters: * ch (IN) : the pointer to the channel. * * Return values: * TRUE : there are messages ready to read, or hangup. * FALSE: there are no messages ready to be read. */ gboolean (* is_message_pending) (IPC_Channel * ch);/* * IPC_OPS::is_sending_blocked * check the send_queue to see if there are any messages blocked. * * Parameters: * ch (IN) : the pointer to the channel. * * Return values: * TRUE : there are messages blocked (waiting) in the send_queue. * FALSE: there are no message blocked (waiting) in the send_queue. * * See also: * get_send_select_fd() */ gboolean (* is_sending_blocked) (IPC_Channel *ch);/* * IPC_OPS::resume_io * Resume all possible IO operations through the IPC transport * * Parameters: * the pointer to the channel. * * Return values: * IPC_OK : resume all the possible I/O operation successfully. * IPC_FAIL : the operation fails. * IPC_BROKEN : the channel is broken. * */ int (* resume_io) (IPC_Channel *ch);/* * IPC_OPS::get_send_select_fd() * return a file descriptor which can be given to select/poll. This fd * is used by the IPC code for sending. It is intended that this be * ONLY used with select, poll, or similar mechanisms, not for direct I/O. * Note that due to select(2) and poll(2) semantics, you must check * is_sending_blocked() to see whether you should include this FD in * your poll for writability, or you will loop very fast in your * select/poll loop ;-) * * Parameters: * ch (IN) : the pointer to the channel. * * Return values: * integer >= 0 : the send fd for selection. * -1 : there is no send fd. * * See also: * is_sending_blocked() */ int (* get_send_select_fd) (IPC_Channel * ch);/* * IPC_OPS::get_recv_select_fd * return a file descriptor which can be given to select. This fd * is for receiving. It is intended that this be ONLY used with select, * poll, or similar mechanisms, NOT for direct I/O. * * Parameters: * ch (IN) : the pointer to the channel. * * Return values: * integer >= 0 : the recv fd for selection. * -1 : there is no recv fd. * * NOTE: This file descriptor is often the same as the send * file descriptor. */ int (* get_recv_select_fd) (IPC_Channel * ch);/* * IPC_OPS::set_send_qlen * allow user to set the maximum send_queue length. * * Parameters * ch (IN) : the pointer to the channel. * q_len (IN) : the max length for the send_queue. * * Return values: * IPC_OK : set the send queue length successfully. * IPC_FAIL : there is no send queue. (This isn't supposed * to happen). * It means something bad happened. * */ int (* set_send_qlen) (IPC_Channel * ch, int q_len);/* * IPC_OPS::set_recv_qlen * allow user to set the maximum recv_queue length. * * Parameters: * ch (IN) : the pointer to the channel. * q_len (IN) : the max length for the recv_queue. * * Return values: * IPC_OK : set the recv queue length successfully. * IPC_FAIL : there is no recv queue. * */ int (* set_recv_qlen) (IPC_Channel * ch, int q_len);/* * IPC_OPS: set callback for high/low flow mark * ch (IN) : the pointer to the channel * callback (IN) : the callback function * user_data(IN) : a pointer to user_data * callback will be called with channel and * this user_data as parameters * * Return values: * void * */ void (* set_high_flow_callback) (IPC_Channel* ch , flow_callback_t callback, void* user_data); void (* set_low_flow_callback) (IPC_Channel* ch , flow_callback_t callback, void* user_data); /* * IPC_OPS::new_ipcmsg * ch (IN) : the pointer to the channel * data (IN) : data to be copied to the message body * len (IN) : data len * private (IN): the pointer value to set as in the message * * Return values: * the pointer to a new created message will be * returned if success or NULL if failure * */ IPC_Message* (*new_ipcmsg)(IPC_Channel* ch, const void* data, int len, void* private); };/* * ipc_wait_conn_constructor: * the common constructor for ipc waiting connection. * Use ch_type to identify the connection type. Usually it's only * needed by server side. * * Parameters: * ch_type (IN) : the type of the waiting connection to create. * ch_attrs (IN) : the hash table which contains the attributes * needed by this waiting connection in name/value * pair format. * * For example, the only attribute needed by UNIX * domain sockets is path name. * * Return values: * the pointer to a new waiting connection or NULL if the connection * can't be created. * Note: * current implementation only supports unix domain socket * whose type is IPC_DOMAIN_SOCKET * */extern IPC_WaitConnection * ipc_wait_conn_constructor(const char * ch_type, GHashTable* ch_attrs);/* * ipc_channel_constructor: * brief the common constructor for ipc channel. * Use ch_type to identify the channel type. * Usually this function is only called by client side. * * Parameters: * ch_type (IN): the type of the channel you want to create. * ch_attrs (IN): the hash table which contains the attributes needed * by this channel. * For example, the only attribute needed by UNIX domain * socket is path name. * * Return values: * the pointer to the new channel whose status is IPC_DISCONNECT * or NULL if the channel can't be created. * * Note: * current implementation only support unix domain socket * whose type is IPC_DOMAIN_SOCKET * */extern IPC_Channel * ipc_channel_constructor(const char * ch_type, GHashTable* ch_attrs);/* * ipc_channel_pair: * Construct a pair of connected IPC channels in a fashion analogous * to pipe(2) or socketpair(2). * * Parameters: * channels: an array of two IPC_Channel pointers for return result */int ipc_channel_pair(IPC_Channel* channels[2]);/* * ipc_set_auth: * A helper function used to convert array of uid and gid into * an authentication structure (IPC_Auth) * * Parameters: * a_uid (IN): the array of a set of user ids. * a_gid (IN): the array of a set of group ids. * num_uid (IN): the number of user ids. * num_gid (IN): the number of group ids. * * Return values: * the pointer to the authentication structure which contains the * set of uid and the set of gid. Or NULL if this structure can't * be created. * */extern IPC_Auth * ipc_set_auth(uid_t * a_uid, gid_t * a_gid, int num_uid, int num_gid);/* Destroys an object constructed by ipc_set_auth */extern void ipc_destroy_auth(IPC_Auth * auth);extern void ipc_set_pollfunc(int (*)(struct pollfd*, unsigned int, int));struct SOCKET_MSG_HEAD{ int msg_len; int magic;};#define MAXDATASIZE 65535#define HEADMAGIC 0xabcd#define POOL_SIZE (4*1024)struct ipc_bufpool{ int refcount; char* currpos; char* consumepos; char* startpos; char* endpos; int size;};struct ipc_bufpool* ipc_bufpool_new(int);void ipc_bufpool_del(struct ipc_bufpool* pool);int ipc_bufpool_spaceleft(struct ipc_bufpool* pool);int ipc_bufpool_update(struct ipc_bufpool* pool, struct IPC_CHANNEL * ch, int msg_len, IPC_Queue* rqueue);gboolean ipc_bufpool_full(struct ipc_bufpool* pool, struct IPC_CHANNEL* ch, int*);int ipc_bufpool_partial_copy(struct ipc_bufpool* dstpool, struct ipc_bufpool* srcpool);void ipc_bufpool_ref(struct ipc_bufpool* pool);void ipc_bufpool_unref(struct ipc_bufpool* pool);#define IPC_PATH_ATTR "path" /* pathname attribute */#define IPC_DOMAIN_SOCKET "uds" /* Unix domain socket */#define IPC_MODE_ATTR "sockmode" /* socket mode attribute */#ifdef IPC_DOMAIN_SOCKET# define IPC_ANYTYPE IPC_DOMAIN_SOCKET#else# error "No IPC types defined(!)"#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -