📄 ~util.~h
字号:
/**
* util.h
*
* Short Message Abstractive Library.(SMAL)
*
* Copyright 2003-2006 北京风起水流软件工作室
*
* http://www.zealware.com
*
* princetoad@gmail.com
*
*/
#ifndef _SMAL_UTIL_H_
#define _SMAL_UTIL_H_
#include <smal.h>
//#include <common/logqueue.h>
#include <common/const.h>
#include <winsock2.h>
class MySync
{
public:
/**@name Operations */
//@{
/**Block until the synchronisation object is available
*/
virtual void Wait() = 0;
/**Signal that the synchronisation object is available
*/
virtual void Signal() = 0;
//@}
};
class MyCriticalSection : public MySync
{
public:
/**@name Construction */
//@{
/**Create a new critical section object .
*/
MyCriticalSection();
MyCriticalSection(const MyCriticalSection &);
/**Destroy the critical section object
*/
~MyCriticalSection();
//@}
/**@name Operations */
//@{
/** Enter the critical section by waiting for exclusive access.
*/
void Wait();
inline void Enter()
{ Wait(); }
/** Leave the critical section by unlocking the mutex
*/
void Signal();
inline void Leave()
{ Signal(); }
//@}
private:
MyCriticalSection & operator=(const MyCriticalSection &) { return *this; }
CRITICAL_SECTION criticalSection;
};
///////////////////////////////////////////////////////////////////////////////
//
/** 常用结构体定义
*/
/** 线程信息结构体
*/
struct thread_info
{
DWORD m_pThreadId;
HANDLE m_hThread;
bool m_bBusyWorking;
thread_info() { m_hThread=0; m_bBusyWorking=false; }
};
/** 服务器端操作
*/
struct client_conn {
SOCKET hClient;
char sIcpid[MAX_PATH];
char sSpid[MAX_PATH];
ConnectionType type;
int nVersion;
client_conn() {
hClient = 0;
memset(sIcpid, 0, MAX_PATH);
memset(sSpid, 0, MAX_PATH);
nVersion = 0;
type = e_SendAndRecv;
}
};
///////////////////////////////////////////////////////////////////////////////
// 全局公共函数
//
/**
获得日期时间函数
格式"%04d-%02d-%02d %02d:%02d:%02d", 即YYYY-MM-DD hh:mm:ss:mss,主要用于记录日志的记录的时间戳
*/
void GetDateTime(char * strValue);
/**
转换64位无符号整数的网络字节序
*/
#define hton64(i) ( ((unsigned __int64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
#define ntoh64 hton64
int AsciiToBcd( unsigned char *lpAscii, unsigned char *lpBcd, int nLength);
void BcdToAscii( unsigned char *lpAscii, unsigned char *lpBcd, int nLength);
void ConvertMsgId( char * dst_msgid, unsigned char* uc_msgid );
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -