#pragma once #include #include #include #include #include namespace node { namespace quic { template bool SetOption(Environment* env, Opt* options, const v8::Local& object, const v8::Local& name) { v8::Local value; if (!object->Get(env->context(), name).ToLocal(&value)) return false; if (!value->IsUndefined()) { Utf8Value utf8(env->isolate(), value); options->*member = *utf8; } return true; } template bool SetOption(Environment* env, Opt* options, const v8::Local& object, const v8::Local& name) { v8::Local value; if (!object->Get(env->context(), name).ToLocal(&value)) return false; if (!value->IsUndefined()) { CHECK(value->IsBoolean()); options->*member = value->IsTrue(); } return true; } template bool SetOption(Environment* env, Opt* options, const v8::Local& object, const v8::Local& name) { v8::Local value; if (!object->Get(env->context(), name).ToLocal(&value)) return false; if (!value->IsUndefined()) { CHECK_IMPLIES(!value->IsBigInt(), value->IsNumber()); uint64_t val = 0; if (value->IsBigInt()) { bool lossless = true; val = value.As()->Uint64Value(&lossless); if (!lossless) { Utf8Value label(env->isolate(), name); THROW_ERR_OUT_OF_RANGE( env, ("options." + label.ToString() + " is out of range").c_str()); return false; } } else { val = static_cast(value.As()->Value()); } options->*member = val; } return true; } // Utilities used to update the stats for Endpoint, Session, and Stream // objects. The stats themselves are maintained in an AliasedStruct within // each of the relevant classes. template void IncrementStat(Stats* stats, uint64_t amt = 1) { stats->*member += amt; } template void RecordTimestampStat(Stats* stats) { stats->*member = uv_hrtime(); } template void SetStat(Stats* stats, uint64_t val) { stats->*member = val; } template uint64_t GetStat(Stats* stats) { return stats->*member; } #define STAT_INCREMENT(Type, name) IncrementStat(&stats_); #define STAT_INCREMENT_N(Type, name, amt) \ IncrementStat(&stats_, amt); #define STAT_RECORD_TIMESTAMP(Type, name) \ RecordTimestampStat(&stats_); #define STAT_SET(Type, name, val) SetStat(&stats_, val); #define STAT_GET(Type, name) GetStat(&stats_); } // namespace quic } // namespace node