功能:提供平台无关的简单的套接字功能
剔除DSMPlugin和HTTP相关内容后,VSocket类如下:
======================================公有成员函数====================================
// Constructor/Destructor
VSocket();
virtual ~VSocket();
// Create
// Create a socket and attach it to this VSocket object
// 创建一个socket并将其连接到本VSocket对象
VBool Create();
// Shutdown
// Shutdown the currently attached socket
// 停止当前已连接的socket
VBool Shutdown();
// Close
// Close the currently attached socket
// 关闭当前已连接的socket
VBool Close();
// Bind
// Bind the attached socket to the specified port
// If localOnly is VTrue then the socket is bound only
// to the loopback adapter.
// 将已连接的socket绑定到指定端口
// 如果localOnly为VTrue,则只将socket绑定到回路适配器
VBool Bind(const VCard port, const VBool localOnly=VFalse);
// Connect
// Make a stream socket connection to the specified port
// on the named machine.
// 将流socket连接到已知机器的指定端口上
VBool Connect(const VString address, const VCard port);
// Listen
// Set the attached socket to listen for connections
// 将attached socket设为监听
VBool Listen();
// Accept
// If the attached socket is set to listen then this
// call blocks waiting for an incoming connection, then
// returns a new socket object for the new connection
// 如果attached socket设为监听则Accept的调用会被阻止直到有
// 新的连入连接,然后为新连接返回一个新的socket对象
VSocket *Accept();
// GetPeerName
// If the socket is connected then this returns the name
// of the machine to which it is connected.
// This string MUST be copied before the next socket call...
// 返回socket连接到的机器的名称。下次调用前需将此名称保存
VString GetPeerName();
// GetSockName
// If the socket exists then the name of the local machine
// is returned. This string MUST be copied before the next
// socket call!
// socket存在则返回本地机器的名称。下次调用前需将此名称保存
VString GetSockName();
// Resolve
// Uses the Winsock API to resolve the supplied DNS name to
// an IP address and returns it as an Int32
// 使用Winsock API将DNS名解析为IP地址,并返回一个Int32的地址值
static VCard32 Resolve(const VString name);
// SetTimeout
// Sets the socket timeout on reads and writes.
// 设置读写超时
VBool SetTimeout(VCard32 msecs);
// Send and Read return the number of bytes sent or recieved.
// 发送或接收数据,并返回发送或接收的字节数
VInt Send(const char *buff, const VCard bufflen);
VInt SendQueued(const char *buff, const VCard bufflen);
VInt Read(char *buff, const VCard bufflen);
//清除缓冲队列
void ClearQueue();
========================================保护成员===================================
// The internal socket id
int sock;
char queuebuffer[9000]; //数据缓冲区
DWORD queuebuffersize; //缓冲长度
VSocket.h中还定义了VSocketSystem类,它的大致作用是启动和卸载WS2_32.DLL 库,提供对Windows的兼容