4
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
5
6
6
#include " node.h"
7
- #include " node_quic_buffer.h"
8
- #include " string_bytes.h"
9
7
#include " uv.h"
10
8
#include " v8.h"
11
9
@@ -80,18 +78,18 @@ enum QuicErrorFamily : int32_t {
80
78
struct QuicError {
81
79
int32_t family;
82
80
uint64_t code;
83
- QuicError (
81
+ inline QuicError (
84
82
int32_t family_ = QUIC_ERROR_SESSION,
85
83
int code_ = NGTCP2_NO_ERROR);
86
- QuicError (
84
+ inline QuicError (
87
85
int32_t family_ = QUIC_ERROR_SESSION,
88
86
uint64_t code_ = NGTCP2_NO_ERROR);
89
- QuicError (
87
+ inline QuicError (
90
88
Environment* env,
91
89
v8::Local<v8::Value> codeArg,
92
90
v8::Local<v8::Value> familyArg = v8::Local<v8::Object>(),
93
91
int32_t family_ = QUIC_ERROR_SESSION);
94
- const char * GetFamilyName ();
92
+ inline const char * GetFamilyName ();
95
93
};
96
94
97
95
class SocketAddress {
@@ -269,8 +267,8 @@ class SocketAddress {
269
267
270
268
struct QuicPath : public ngtcp2_path {
271
269
QuicPath (
272
- SocketAddress* local,
273
- SocketAddress* remote) {
270
+ SocketAddress* local,
271
+ SocketAddress* remote) {
274
272
ngtcp2_addr_init (&this ->local , **local, local->Size (), nullptr );
275
273
ngtcp2_addr_init (&this ->remote , **remote, remote->Size (), nullptr );
276
274
}
@@ -300,23 +298,9 @@ class QuicCID {
300
298
str_ = std::string (cid_.data , cid_.data + cid_.datalen );
301
299
}
302
300
303
- std::string ToStr () const { return str_; }
304
-
305
- std::string ToHex () const {
306
- if (hex_.empty () && cid_.datalen > 0 ) {
307
- size_t len = cid_.datalen * 2 ;
308
- MaybeStackBuffer<char , 64 > dest;
309
- dest.AllocateSufficientStorage (len);
310
- dest.SetLengthAndZeroTerminate (len);
311
- size_t written = StringBytes::hex_encode (
312
- reinterpret_cast <const char *>(cid_.data ),
313
- cid_.datalen ,
314
- *dest,
315
- dest.length ());
316
- hex_ = std::string (*dest, written);
317
- }
318
- return hex_;
319
- }
301
+ inline std::string ToStr () const ;
302
+
303
+ inline std::string ToHex () const ;
320
304
321
305
const ngtcp2_cid* operator *() const { return &cid_; }
322
306
@@ -356,43 +340,24 @@ void IncrementStat(
356
340
// reset the timer; Stop to halt the timer.
357
341
class Timer final : public MemoryRetainer {
358
342
public:
359
- explicit Timer (Environment* env, std::function<void ()> fn)
360
- : env_(env),
361
- fn_(fn) {
362
- uv_timer_init (env_->event_loop (), &timer_);
363
- timer_.data = this ;
364
- }
343
+ inline explicit Timer (Environment* env, std::function<void ()> fn);
365
344
366
345
// Stops the timer with the side effect of the timer no longer being usable.
367
346
// It will be cleaned up and the Timer object will be destroyed.
368
- void Stop () {
369
- if (stopped_)
370
- return ;
371
- stopped_ = true ;
372
-
373
- if (timer_.data == this ) {
374
- uv_timer_stop (&timer_);
375
- timer_.data = nullptr ;
376
- }
377
- }
347
+ inline void Stop ();
378
348
379
349
// If the timer is not currently active, interval must be either 0 or greater.
380
350
// If the timer is already active, interval is ignored.
381
- void Update (uint64_t interval) {
382
- if (stopped_)
383
- return ;
384
- uv_timer_start (&timer_, OnTimeout, interval, interval);
385
- uv_unref (reinterpret_cast <uv_handle_t *>(&timer_));
386
- }
351
+ inline void Update (uint64_t interval);
387
352
388
- static void Free (Timer* timer);
353
+ static inline void Free (Timer* timer);
389
354
390
355
SET_NO_MEMORY_INFO ()
391
356
SET_MEMORY_INFO_NAME (Timer)
392
357
SET_SELF_SIZE (Timer)
393
358
394
359
private:
395
- static void OnTimeout (uv_timer_t * timer);
360
+ static inline void OnTimeout (uv_timer_t * timer);
396
361
397
362
bool stopped_ = false ;
398
363
Environment* env_;
@@ -402,8 +367,8 @@ class Timer final : public MemoryRetainer {
402
367
403
368
using TimerPointer = DeleteFnPtr<Timer, Timer::Free>;
404
369
405
- ngtcp2_crypto_level from_ossl_level (OSSL_ENCRYPTION_LEVEL ossl_level);
406
- const char * crypto_level_name (ngtcp2_crypto_level level);
370
+ inline ngtcp2_crypto_level from_ossl_level (OSSL_ENCRYPTION_LEVEL ossl_level);
371
+ inline const char * crypto_level_name (ngtcp2_crypto_level level);
407
372
408
373
} // namespace quic
409
374
} // namespace node
0 commit comments