Redis anet

anet.c -- Basic TCP socket stuff made a bit less boring.

这里接口很简洁,值得复用!

// 返回socket
int anetTcpConnect(char* err, char* addr, int port);
int anetTcpNonBlockConnect(char* err, char* addr, int port);
int anetUnixConnect(char* err, char* path);
int anetUnixNonBlockConnect(char* err, char* path);


// 出错返回-1,否则返回读写的字节数
int anetRead(int fd, char* buf, int count);
int anetWrite(int fd, char* buf, int count);


// ANET_OK或ANET_ERR,ipbuf中返回ip
int anetResolve(char* err, char* host, char* ipbuf);


// 返回socket
int anetTcpServer(char* err, int port, char* bindaddr);
int anetUnixServer(char* err, char* path, mode_t perm);
int anetTcpAccept(char* err, int serversock, char* ip, int* port);
int anetUnixAccept(char* err, int serversock);


// 选项
int anetNonBlock(char* err, int fd);
int anetEnableTcpNoDelay(char* err, int fd);
int anetDisableTcpNoDelay(char* err, int fd);


 // 获得对端ip和port

int anetPeerToString(int fd, char* ip, int* port); 


// 两个接口都会打开KEEPALIVE选项,后一个在Linux下还会设置选项对应的interval值

int anetKeepAlive(char* err, int fd, int interval);
int anetTcpKeepAlive(char* err, int fd);

你可能感兴趣的:(Linux)