1 Star 0 Fork 1

shawhen/netlib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
netlib.hpp 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
shawhen 提交于 2015-06-11 18:40 . init
// netlib.hpp
#ifndef _KS_INC_NETLIB_HPP_
#define _KS_INC_NETLIB_HPP_
#include "netlib.h"
namespace ks {
bool net_address_make(struct sockaddr* addr, const char* ip, unsigned short port)
{ return ks_net_address_make(addr, ip, port)!=FALSE; }
bool net_address_make(struct sockaddr* addr, const char* ip_port)
{ return ks_net_address_make1(addr, ip_port)!=FALSE; }
class NetChannel {
public:
static NetChannel* cast(KSNetChannel* channel) { return (NetChannel*)channel; }
operator KSNetChannel* () { return &channel_; }
public:
KSNetChannelStatus status() const { return channel_.status; }
int err() const { return channel_.err; }
int fd() const { return channel_.fd; }
bool working() const { return ks_net_channel_is_working(&channel_); }
public:
bool connect_sync(KSNetEventDispatcher* dp, const struct sockaddr* addr)
{ return ks_net_channel_connect_sync(&channel_, dp, addr)!=FALSE; }
bool connect_async(KSNetEventDispatcher* dp, const struct sockaddr* addr)
{ return ks_net_channel_connect_async(&channel_, dp, addr)!=FALSE; }
bool connect_finish(KSNetEventDispatcher* dp, int fd)
{ return ks_net_channel_connect_finish(&channel_, fd)!=FALSE; }
bool write_all(const void* buf, size_t len, const void* header_buf=0, size_t header_len=0)
{ return ks_net_channel_write_all_full(&channel_, buf, len, header_buf, header_len)!=FALSE; }
size_t write(const void* buf, size_t len)
{ return ks_net_channel_write(&channel_, buf, len); }
void flush()
{ ks_net_channel_flush(&channel_); }
void close(int status=KS_NET_CHANNEL_ST_CLOSED, int err=0)
{ ks_net_channel_close_full(&channel_, status, err); }
void close_wait_peer()
{ ks_net_channel_close_wait_peer(&channel_); }
private:
KSNetChannel channel_;
};
} // ks
#endif//_KS_INC_NETLIB_HPP_
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/shawhen/netlib.git
git@gitee.com:shawhen/netlib.git
shawhen
netlib
netlib
master

搜索帮助