📄 think_net.h
字号:
/*
* think_net.h: Think Net Interface
* version: 1.0
* OS: AIX,HP-UX,Solaris,FreeBSD,Linux
* author: luojian(enigma1983@163.com)
* history:
* 2008-11-07 1.0 released
*
*/
#ifndef __THINK_NET_H__
#define __THINK_NET_H__
#include "think_os.h"
#include "think_error.h"
/* C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __THINK_WINDOWS__
#define socketclose closesocket
#define socklen_t int
#else
#define socketclose close
#endif
#ifndef INADDR_NONE
#define INADDR_NONE -1
#endif
#define THINK_NET_BUFSIZE 8192
#define THINK_NET_WAIT 0x10000000 /* wait */
#define THINK_NET_READ 0x20000000 /* read */
#define THINK_NET_WRITE 0x40000000 /* write */
#define THINK_NET_ERROR 0x80000000 /* error */
struct __think_net_buflist {
char *buf;
unsigned int pos;
unsigned int len;
struct __think_net_buflist *prior;
struct __think_net_buflist *next;
};
typedef struct __think_net_buflist THINK_NET_BUFLIST;
struct __think_net {
int sockfd;
char ip[16];
unsigned short port;
int flags;
unsigned int nrbytes;
unsigned int nwbytes;
THINK_NET_BUFLIST *rlist;
THINK_NET_BUFLIST *wlist;
};
typedef struct __think_net THINK_NET;
struct __think_netlist {
THINK_NET *net;
struct __think_netlist *prior;
struct __think_netlist *next;
};
typedef struct __think_netlist THINK_NETLIST;
int think_netstart(void);
int think_netstop(void);
THINK_NET *think_netconnect(const char *ip,unsigned short port);
THINK_NET *think_netlisten(const char *ip,unsigned short port);
THINK_NET *think_netaccept(THINK_NET *net);
int think_netrecv(THINK_NET *net,void *buf,unsigned int siz,int flags);
int think_netsend(THINK_NET *net,const void *buf,unsigned int len,int flags);
int think_netclose(THINK_NET *net);
/* select */
int think_netadd(THINK_NETLIST **netlist,THINK_NET *net);
int think_netdel(THINK_NETLIST **netlist,THINK_NET *net);
THINK_NETLIST *think_netfind(THINK_NETLIST *netlist,THINK_NET *net);
int think_netclean(THINK_NETLIST **netlist);
int think_netselect(THINK_NETLIST **netlist,int timeout);
/* buffer list */
int think_netsendtobuflist(THINK_NET *net,const void *buf,unsigned int len);
int think_netrecvtobuflist(THINK_NET *net);
int think_netrecvfrombuflist(THINK_NET *net,void *buf,unsigned int siz);
int think_netsendfrombuflist(THINK_NET *net);
int think_netselectbybuflist(THINK_NETLIST **netlist,int timeout);
int think_netpeekfrombuflist(THINK_NET *net,void *buf,unsigned int siz);
/* C++ */
#ifdef __cplusplus
}
#endif
#endif /* __THINK_NET_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -