这些是3年前都自实现的,现在记录起来,以防忘记丢失,以便后续查阅使用。
代码:
xinclude.h文件:
#ifndef _XINCLUDE_H_
#define _XINCLUDE_H_
//include
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <errno.h> //errno
#include <time.h>
//include linux c
#include <signal.h> //SIG_ERR signal
//include c includer
#include <string.h> //strerror
//include c++ includer
#include <string> //std::string
#include <sstream> //std::stringstream
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <queue>
#include <vector> //std::vector
//using namespace
using namespace std;
//define
#define MAX_ROUND_VALUE 65530
#define MAX_RCV_SIZE 2000
#define MAX_SND_SIZE 2000
//message struct
typedef struct message_st
{
void* m_pcBuf;//message buf
int m_iLen; //message length
int m_iSize; //buf capacity size
message_st()
{
m_pcBuf = NULL;
m_iLen = 0;
m_iSize = 0;
}
//message is valid
inline bool IsValid()
{
return (m_pcBuf != NULL) && (m_iLen > 0);
}
//allocate memory for message
inline bool Malloc(int iSize)
{
bool bRet = false;
if (true =&