class DateBuffer
{
public:
// This class provides no protection against being accessed from multiple threads
// simultaneously. Update & InexactUpdate rewrite the date buffer, so care should
// be taken to protect against simultaneous access.
DateBuffer() : fLastDateUpdate(0) { fDateBuffer[0] = 0; }
~DateBuffer() {}
//SEE RFC 1123 for details on the date string format
//ex: Mon, 04 Nov 1996 21:42:17 GMT
//RFC 1123 date strings are always of this length
enum
{
kDateBufferLen = 29
};
// Updates this date buffer to reflect the current time.
// If a date is provided, this updates the DateBuffer to be that date.
void Update(const SInt64& inDate) { DateTranslator::UpdateDateBuffer(this, inDate); }
// Updates this date buffer to reflect the current time, with a certain degree
// of inexactitude (the range of error is defined by the kUpdateInterval value)
void InexactUpdate();
//returns a NULL terminated C-string always of kHTTPDateLen length.
char *GetDateBuffer() { return fDateBuffer; }
private:
enum
{
kUpdateInterval = 60000 // Update every minute
};
//+1 for terminator +1 for padding
char fDateBuffer[kDateBufferLen + 2];
SInt64 fLastDateUpdate;
friend class DateTranslator;
};
date strings format => http://www.csgnetwork.com/timerfc1123calc.html
DateBuffer() : fLastDateUpdate(0) { fDateBuffer[0] = 0; }
~DateBuffer() {}
void Update(const SInt64& inDate) { DateTranslator::UpdateDateBuffer(this, inDate); }
将inData数据msec转换为GMT格式的时间,并填充fDateBuffer.(参考:DataTranslator源码解析)
// Updates this date buffer to reflect the current time, with a certain degree
// of inexactitude (the range of error is defined by the kUpdateInterval value)
void DateBuffer::InexactUpdate()
{
SInt64 theCurTime = OS::Milliseconds();
if ((fLastDateUpdate == 0) || ((fLastDateUpdate + kUpdateInterval) < theCurTime))
{
fLastDateUpdate = theCurTime;
this->Update(0);
}
}
更新现在的时间,到DateBuffer中,有一点程度的不精确(不精确的范围由kUpdateInteval来限定)
char *GetDateBuffer() { return fDateBuffer; }
获取GMT格式的时间字串,比如 => Mon, 04 Nov 1996 21:42:17 GMT
刚刚开始接触DSS,希望能共同提高,如果有分析不到位的地方,希望批评指正。:)