📄 wartransferbuffer.h
字号:
/** */#ifndef WAR_TRANSFER_BUFFER_H#define WAR_TRANSFER_BUFFER_H/* SYSTEM INCLUDES */#if defined(HAVE_WINSOCK) && !defined(WAR_WINSOCK2_H_INCLUDED)# define WAR_WINSOCK2_H_INCLUDED# include <winsock2.h>#endif/* PROJECT INCLUDES */#ifndef WAR_TYPES_H# include "WarTypes.h"#endif#ifndef WAR_EXCEPTION_H# include "WarException.h"#endif#ifndef WAR_SMART_POINTER_H# include "WarSmartPointer.h"#endif#ifndef WAR_PTR_WRAPPER_H# include "WarPtrWrapper.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplus/** Transfer buffer for IO operations. */class WarTransferBuffer : public WarSmartPointer{public: typedef WarPtrWrapper<WarSmartPointer> ref_ptr_t; // LIFECYCLE /** * Default constructor. */ WarTransferBuffer(size_t bufferSize, WarSmartPointer *pRef = NULL, const int dbId = 0) throw(WarException) : mBytesUsed(0), mBuffer(NULL), mSerialNum(0), mRefPtr(pRef), mSegmentCnt(0), mpLock(NULL), mBufferSize(bufferSize), mHeaderLen(0), mId(dbId) { mBuffer = new char[mBufferSize]; } /** * Destructor. */ ~WarTransferBuffer(void) { if (mBuffer) delete mBuffer; if (mpLock) delete mpLock; }#ifdef HAVE_WINSOCK WSABUF *GetWsabuf() { if (mHeaderLen == 0) mHeaderLen = offsetof(WSABUF, buf); ((WSABUF *)mBuffer)->len = GetLength(); }#endif // OPERATORS bool operator == (const WarTransferBuffer& from) const { return mSerialNum == from.mSerialNum; } bool operator < (const WarTransferBuffer& from) const { return mSerialNum < from.mSerialNum; } // OPERATIONS // ACCESS /// Get the max length for IO operation inline size_t GetLength() const { return mBufferSize - mHeaderLen; } /// Get the free capacity in the buffer inline size_t GetFreeCapacity() const { return GetLength() - mBytesUsed; } inline war_cstr_t GetBuffer() { return mBuffer + mHeaderLen; } inline void CopyToBuffer(war_ccstr_t from, size_t from_bytes) throw(WarException) { if (from_bytes > GetFreeCapacity()) WarThrow(WarError(WAR_ERR_OUT_OF_RANGE), NULL); memcpy(mBuffer + mHeaderLen + mBytesUsed, from, from_bytes); mBytesUsed += from_bytes; } void Reset() { mBytesUsed = 0; } // INQUIRY size_t GetBytesUsed() { return mBytesUsed; } size_t mBytesUsed; // Bytes read or written, from start of buffer (user to map to WSABUF) war_cstr_t mBuffer; int mSerialNum; // Used to sort/handle overlapped I/O requests in the correct order ref_ptr_t mRefPtr; // Used to prevent destruction of referenced objects unsigned mSegmentCnt; // Segment count. WarCriticalSection *mpLock;protected:private: size_t mBufferSize; // Allocated size size_t mHeaderLen; // Bytes to ignore at the start of the buffer int mId; // Identifier, used for debugging};/* INLINE METHODS *//* EXTERNAL REFERENCES */typedef WarPtrWrapper<WarTransferBuffer> war_transfer_buffer_ptr_t;#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif /* WAR_TRANSFER_BUFFER_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -