Skip to content

Commit

Permalink
reduce the pain of applications needing to use int64_t for propagatin…
Browse files Browse the repository at this point in the history
…g application errors, when all their error codes are small (e.g., raw H3, QPACK), retaining conflicts
  • Loading branch information
kazuho committed Jan 12, 2025
1 parent 40959b7 commit 1d7e532
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions include/quicly/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ extern "C" {

/**
* Error code used by quicly. The code coalesces the following to an int64_t.
* * INT_MIN ... INT_MAX: picotls error codes (of type int)
* * 0b01xxxx...: QUIC application error codes
* * 0b10xxxx...: QUIC protocol error codes
* Internal error codes should be allocated from the unused space in the `int` space (i.e., unused space of picotls error codes);
* * 0..0x2ff: picotls error codes (of type int)
* * 0x30000..0x400000000002ffff: QUIC application error codes
* * 0x400000000002ffff..0x800000000002ffff...: QUIC protocol error codes
* Internal error codes should be allocated from the unused space below 0x30000 (i.e., unused space of picotls error codes);
* quicly itself uses 0xffxx. `quicly_error_t` is defined as a signed type so that the picotls error code space can be mapped
* without sign conversion.
*/
typedef int64_t quicly_error_t;

#define QUICLY_ERROR_IS_QUIC(e) (((int64_t)(e) & 0x4000000000000000) != 0)
#define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) (((uint64_t)(int64_t)(e) & 0xc000000000000000u) == 0x8000000000000000u)
#define QUICLY_ERROR_IS_QUIC_APPLICATION(e) (((uint64_t)(int64_t)(e) & 0xc000000000000000u) == 0x4000000000000000u)
#define QUICLY_ERROR_GET_ERROR_CODE(e) ((uint64_t)((int64_t)(e) & 0x3fffffffffffffff))
#define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((int64_t)((uint64_t)(int64_t)(e) | 0x8000000000000000u))
#define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((int64_t)((int64_t)(e) | 0x4000000000000000))
#define QUICLY_ERROR_IS_QUIC(e) ((uint64_t)(int64_t)(e) - 0x30000u < 0x8000000000000000u)
#define QUICLY_ERROR_IS_QUIC_TRANSPORT(e) ((uint64_t)(int64_t)(e) - 0x4000000000030000u < 0x4000000000000000u)
#define QUICLY_ERROR_IS_QUIC_APPLICATION(e) ((uint64_t)(int64_t)(e) - 0x30000u < 0x4000000000000000u)
#define QUICLY_ERROR_GET_ERROR_CODE(e) (((uint64_t)(int64_t)(e) - 0x30000u) & 0x3fffffffffffffffu)
#define QUICLY_ERROR_FROM_TRANSPORT_ERROR_CODE(e) ((int64_t)((uint64_t)(e) + 0x4000000000030000u))
#define QUICLY_ERROR_FROM_APPLICATION_ERROR_CODE(e) ((int64_t)(uint64_t)(e) + 0x30000)
/**
* PTLS_ERROR_NO_MEMORY and QUICLY_ERROR_STATE_EXHAUSTION are special error codes that are internal but can be passed to
* quicly_close. These are converted to QUICLY_TRANSPORT_ERROR_INTERNAL when sent over the wire.
Expand Down

0 comments on commit 1d7e532

Please sign in to comment.