void ares_gethostbyname(ares_channel channel, const char *name, int family, ares_host_callback callback, void *arg) { // if( QueueManager::manager()->check_cache(name,callback,arg) ) // return; Queue *q = (Queue *)channel; q->add(name,s3eTimerGetUTC()+5000,callback,arg); QueueManager::manager()->step(q); /* { // DEBUG hostent ent; //char *hostname = new char[current->first()->host.size()+1]; //memcpy(hostname,current->first()->host.c_str(),current->first()->host.size()); //hostname[current->first()->host.size()] = 0; //ent.h_name = hostname; ent.h_name = (char *)name; ent.h_length = 4; char *addr_list[2]; char *aliases[1] = { NULL }; s3eInetIPAddress result; s3eInetAton(&result,"78.40.184.246"); addr_list[0] = (char*)&result; addr_list[1] = NULL; ent.h_addr_list = addr_list; ent.h_aliases = aliases; ent.h_addrtype = AF_INET; //current->first_done(ARES_SUCCESS,&ent); callback(arg,ARES_SUCCESS,0,&ent); } */ }
int64 getTimeUTCMS() { #if __S3E__ return s3eTimerGetUTC(); #elif _WIN32 FILETIME tm; GetSystemTimeAsFileTime(&tm); int64 t = tm.dwLowDateTime + (int64(tm.dwHighDateTime) << 32); int64 utc = (t - 116444736000000000LL) / 10000; return utc; #elif __ANDROID__ return jniGetTimeUTCMS(); #elif EMSCRIPTEN struct timeval tv; gettimeofday(&tv, NULL); int64 tm = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000; return tm; #elif __APPLE__ struct timeval tv; gettimeofday(&tv, NULL); int64 tm = (unsigned long long)(tv.tv_sec) * 1000 + (unsigned long long)(tv.tv_usec) / 1000; return tm; /* CFAbsoluteTime tm = CFAbsoluteTimeGetCurrent(); int64 v = int64(tm * 1000.0); return v; */ #endif return getTimeMS(); }
void CAccelerometer::getAccelValues(Acceleration& acc) { int64 timestamp = s3eTimerGetUTC(); // Cap and scale to [-1,1] double x = ((double) M(s3eAccelerometerGetX)()) / 1000.0f; double y = ((double) M(s3eAccelerometerGetY)()) / 1000.0f; double z = ((double) M(s3eAccelerometerGetZ)()) / 1000.0f; x = x <- 1 ? -1 : x; x = x > 1 ? 1 : x; y = y <- 1 ? -1 : y; y = y > 1 ? 1 : y; z = z <- 1 ? -1 : z; z = z > 1 ? 1 : z; acc = Acceleration(x, y, z, timestamp); }
std::string get_ent(const std::string &hostname) const { std::map<std::string,DnsCacheEntry>::const_iterator e = dns_cache.end(); std::map<std::string,DnsCacheEntry>::const_iterator f = dns_cache.find(hostname); if( f == e ) return ""; #ifdef _DEBUG int64_t fresh = 3 * 1000; #else int64_t fresh = 300 * 1000; #endif if( s3eTimerGetUTC() - f->second.last_update >= fresh ) return ""; return f->second.result; }
void step(Queue *channel) { check_result(channel); check_timeouts(s3eTimerGetUTC(),channel); check_queue(channel); }
DnsCacheEntry(const std::string &a_result) : last_update(s3eTimerGetUTC()), result(a_result) { }
DnsCacheEntry() : last_update(s3eTimerGetUTC()) { }
void add_ent(const std::string &hostname, const std::string &ent) { dns_cache[hostname].result = ent; dns_cache[hostname].last_update = s3eTimerGetUTC(); }