本文整理汇总了C++中Timestamp::epochMicroseconds方法的典型用法代码示例。如果您正苦于以下问题:C++ Timestamp::epochMicroseconds方法的具体用法?C++ Timestamp::epochMicroseconds怎么用?C++ Timestamp::epochMicroseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timestamp
的用法示例。
在下文中一共展示了Timestamp::epochMicroseconds方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sslTest2
void sslTest2()
{
tracef("ssl test 2 begin: ssl send data.");
Context::Ptr pContext = new Context(Context::TLSV1_CLIENT_USE, "", Context::VERIFY_NONE);
SecureStreamSocket sss(pContext);
SocketAddress sa("127.0.0.1", 12222);
sss.connect(sa, Timespan(3, 0));
DynamicStruct ds;
ds["type"] = "request";
ds["action"] = "server.token";
Timestamp t;
UInt64 tms = t.epochMicroseconds();
char tms_str[32];
snprintf(tms_str, 31, "%llu", tms);
std::string key = "alpha2015";
key += tms_str;
MD5Engine md5;
md5.update(key);
const DigestEngine::Digest& digest = md5.digest();
std::string md5key = DigestEngine::digestToHex(digest);
DynamicStruct param;
param["key"] = md5key;
param["timestamp"] = tms_str;
param["dev_name"] = "lock1";
param["dev_type"] = "sc-01";
param["uuid"] = "SC00000001";
ds["param"] = param;
tracef("data send: %s.", ds.toString().c_str());
sss.sendBytes(ds.toString().c_str(), ds.toString().length());
sss.close();
tracef("socket closed.");
tracef("ssl test 2 finished.\n");
}
示例2: writeDate
void AMFWriter::writeDate(const Timestamp& date){
(UInt32&)lastReference=0;
if(!_amf3) {
if(amf0Preference) {
writer.write8(AMF_DATE);
writer << ((double)date.epochMicroseconds()/1000);
writer.write16(0); // Timezone, TODO?
return;
}
writer.write8(AMF_AVMPLUS_OBJECT);
}
writer.write8(AMF3_DATE);
writer.write8(0x01);
writer << ((double)date.epochMicroseconds()/1000);
_references.push_back(AMF3_DATE);
(UInt32&)lastReference=_references.size();
}
示例3: getRecords
int COperationRecord::getRecords(Timestamp& start, Timestamp& end, int limit, int offset, std::vector<OperationRecordNode>& data_set)
{
if(m_session_ptr == NULL)
{
warnf("%s, %d: Please init database first.", __FILE__, __LINE__);
return -1;
}
data_set.clear();
Timestamp tstart = start;
Int64 ststart = tstart.epochMicroseconds();
Timestamp tend = end - 1;
Int64 stend = tend.epochMicroseconds();
Statement sselect(*m_session_ptr);
sselect << "SELECT `Timestamp`, `Operation`, `Username`, `Schema` FROM `Operation` WHERE `Timestamp` BETWEEN ? AND ? LIMIT ? OFFSET ?",
use(ststart),
use(stend),
use(limit),
use(offset);
int ret = 0;
try
{
ret = sselect.execute();
}
catch(Exception& e)
{
warnf("%s, %d: Select from Operation failed[%s].", __FILE__, __LINE__, e.message().c_str());
return -1;
}
RecordSet rs(sselect);
bool more = rs.moveFirst();
while(more)
{
OperationRecordNode op_node;
std::size_t col = 0;
op_node.timestamp = rs[col++].convert<Int64>();
op_node.operation = rs[col++].convert<int>();
op_node.username = rs[col++].convert<std::string>();
op_node.schema = rs[col++].convert<int>();
more = rs.moveNext();
data_set.push_back(op_node);
}
return ret;
}
示例4: regTest5
void regTest5()
{
tracef("reg test 5 begin:reg twice");
Context::Ptr pContext = new Context(Context::TLSV1_CLIENT_USE, "", Context::VERIFY_NONE);
SecureStreamSocket sss(pContext);
SocketAddress sa("127.0.0.1", 12222);
sss.connect(sa, Timespan(3, 0));
DynamicStruct ds;
ds["type"] = "request";
ds["action"] = "server.token";
Timestamp t;
UInt64 tms = t.epochMicroseconds();
char tms_str[32];
snprintf(tms_str, 31, "%llu", tms);
std::string key = "alpha2015";
key += tms_str;
MD5Engine md5;
md5.update(key);
const DigestEngine::Digest& digest = md5.digest();
std::string md5key = DigestEngine::digestToHex(digest);
DynamicStruct param;
param["key"] = md5key;
param["timestamp"] = tms_str;
param["dev_name"] = "lock3";
param["dev_type"] = "sc-01";
param["uuid"] = "SC00000003";
ds["param"] = param;
tracef("data send: %s.", ds.toString().c_str());
sss.sendBytes(ds.toString().c_str(), ds.toString().length());
char buf[1024] = {0, };
sss.receiveBytes(buf, 1024);
JSON::Parser parser;
Dynamic::Var var = parser.parse(buf);
JSON::Object::Ptr pObj = var.extract<JSON::Object::Ptr>();
DynamicStruct ds_recv = *pObj;
std::string token = ds_recv["param"]["token"];
DynamicStruct ds_reg;
ds_reg["type"] = "request";
ds_reg["action"] = "server.register";
DynamicStruct param_reg;
param_reg["token"] = token;
param_reg["uuid"] = "SC00000003";
ds_reg["param"] = param_reg;
StreamSocket ss;
SocketAddress sa2("127.0.0.1", 13333);
ss.connect(sa2, Timespan(3, 0));
ss.sendBytes(ds_reg.toString().c_str(), ds_reg.toString().length());
tracef("reg data send: %s.", ds_reg.toString().c_str());
memset(buf, 0, 1024);
ss.receiveBytes(buf, 1024);
tracef("receive bytes: %s.", buf);
ss.close();
Thread::sleep(2000);
StreamSocket ss2;
ss2.connect(sa2, Timespan(3, 0));
tracef("reg data send again: %s.", ds_reg.toString().c_str());
ss2.sendBytes(ds_reg.toString().c_str(), ds_reg.toString().length());
memset(buf, 0, 1024);
ss2.receiveBytes(buf, 1024);
tracef("recv data: %s.", buf);
ss2.close();
tracef("reg test 5 finished.");
}
示例5: main
int main(int argc, char** argv)
{
if(argc < 4)
return 0;
std::string host = argv[1];
UInt64 ssl_port = atoi(argv[2]);
UInt64 reg_port = atoi(argv[3]);
SocketAddress ssl_addr(host, ssl_port);
SocketAddress reg_addr(host, reg_port);
Context::Ptr pContext = new Context(Context::TLSV1_CLIENT_USE, "", Context::VERIFY_NONE);
SecureStreamSocket* ssl_sock = new SecureStreamSocket(pContext);
try
{
ssl_sock->connect(ssl_addr, Timespan(3, 0));
}
catch(Exception& e)
{
warnf("%s, %d: message: %s.", __FILE__, __LINE__, e.message().c_str());
}
tracef("%s, %d: now sleep.", __FILE__, __LINE__);
Thread::sleep(3 * 1000);
char buf[512] = {0, };
DynamicStruct ssl_buf;
ssl_buf["type"] = "request";
ssl_buf["action"] = "server.token";
DynamicStruct ssl_param;
Timestamp t;
UInt64 tms = t.epochMicroseconds();
char tms_str[32] = {0, };
snprintf(tms_str, 31, "%llu", tms);
ssl_param["timestamp"] = tms_str;
std::string key = "alpha2015";
key += tms_str;
MD5Engine md5;
md5.update(key);
const DigestEngine::Digest& digest = md5.digest();
std::string md5key = DigestEngine::digestToHex(digest);
ssl_param["key"] = md5key;
ssl_param["uuid"] = "hjhjhjhj";
ssl_param["dev_type"] = "abc";
ssl_param["dev_name"] = "cba";
ssl_buf["param"] = ssl_param;
snprintf(buf, 511, "%s", ssl_buf.toString().c_str());
tracef("%s, %d: send buf: %s\n", __FILE__, __LINE__, buf);
ssl_sock->sendBytes(buf, 512);
memset(buf, 0, 512);
if(ssl_sock->poll(Timespan(30, 0), Socket::SELECT_READ) > 0)
{
ssl_sock->receiveBytes(buf, 512);
tracef("%s, %d: receive buf: %s\n", __FILE__, __LINE__, buf);
}
ssl_sock->close();
delete ssl_sock;
pContext = NULL;
Dynamic::Var var;
JSON::Parser parser;
try
{
var = parser.parse(buf);
}
catch(Exception& e)
{
warnf("%s, %d: %s\n", __FILE__, __LINE__, e.message().c_str());
return 0;
}
JSON::Object::Ptr obj = var.extract<JSON::Object::Ptr>();
DynamicStruct ssl_recv = *obj;
std::string token = ssl_recv["token"];
DynamicStruct reg_buf;
reg_buf["action"] = "register";
reg_buf["token"] = token;
reg_buf["uuid"] = "hjhjhjhj";
reg_buf["devType"] = "abc";
memset(buf, 0, 512);
snprintf(buf, 511, "%s", reg_buf.toString().c_str());
StreamSocket* reg_sock = new StreamSocket(reg_addr);
reg_sock->sendBytes(buf, 512);
memset(buf, 0, 512);
if(reg_sock->poll(Timespan(3, 0), Socket::SELECT_READ) > 0)
{
reg_sock->receiveBytes(buf, 512);
}
Thread::sleep(2000);
while(1)
{
if(reg_sock->poll(Timespan(3, 0), Socket::SELECT_READ) > 0)
{
memset(buf, 0, 512);
reg_sock->receiveBytes(buf, 512);
parser.reset();
Dynamic::Var recv_request = parser.parse(buf);
JSON::Object::Ptr req_obj = recv_request.extract<JSON::Object::Ptr>();
DynamicStruct req_ds = *req_obj;
tracef("recv request:%s\n", req_ds.toString().c_str());
req_ds["type"] = "response";
req_ds["result"] = "good";
snprintf(buf, 512, "%s", req_ds.toString().c_str());
reg_sock->sendBytes(buf, 512);
infof("send response[%s].\n", buf);
char c;
//.........这里部分代码省略.........