aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/transport')
-rw-r--r--src/core/lib/transport/error_utils.c9
-rw-r--r--src/core/lib/transport/error_utils.h6
-rw-r--r--src/core/lib/transport/metadata_batch.c6
-rw-r--r--src/core/lib/transport/metadata_batch.h4
-rw-r--r--src/core/lib/transport/status_conversion.c7
-rw-r--r--src/core/lib/transport/status_conversion.h6
-rw-r--r--src/core/lib/transport/timeout_encoding.c73
-rw-r--r--src/core/lib/transport/timeout_encoding.h5
-rw-r--r--src/core/lib/transport/transport_op_string.c5
9 files changed, 46 insertions, 75 deletions
diff --git a/src/core/lib/transport/error_utils.c b/src/core/lib/transport/error_utils.c
index 5e3920b627..2e3b61b7ab 100644
--- a/src/core/lib/transport/error_utils.c
+++ b/src/core/lib/transport/error_utils.c
@@ -39,8 +39,9 @@ static grpc_error *recursively_find_error_with_field(grpc_error *error,
return NULL;
}
-void grpc_error_get_status(grpc_error *error, gpr_timespec deadline,
- grpc_status_code *code, grpc_slice *slice,
+void grpc_error_get_status(grpc_exec_ctx *exec_ctx, grpc_error *error,
+ grpc_millis deadline, grpc_status_code *code,
+ grpc_slice *slice,
grpc_http2_error_code *http_error) {
// Start with the parent error and recurse through the tree of children
// until we find the first one that has a status code.
@@ -63,8 +64,8 @@ void grpc_error_get_status(grpc_error *error, gpr_timespec deadline,
status = (grpc_status_code)integer;
} else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR,
&integer)) {
- status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer,
- deadline);
+ status = grpc_http2_error_to_grpc_status(
+ exec_ctx, (grpc_http2_error_code)integer, deadline);
}
if (code != NULL) *code = status;
diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h
index e530884215..6211031a24 100644
--- a/src/core/lib/transport/error_utils.h
+++ b/src/core/lib/transport/error_utils.h
@@ -20,6 +20,7 @@
#define GRPC_CORE_LIB_TRANSPORT_ERROR_UTILS_H
#include "src/core/lib/iomgr/error.h"
+#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/transport/http2_errors.h"
/// A utility function to get the status code and message to be returned
@@ -28,8 +29,9 @@
/// All attributes are pulled from the same child error. If any of the
/// attributes (code, msg, http_status) are unneeded, they can be passed as
/// NULL.
-void grpc_error_get_status(grpc_error *error, gpr_timespec deadline,
- grpc_status_code *code, grpc_slice *slice,
+void grpc_error_get_status(grpc_exec_ctx *exec_ctx, grpc_error *error,
+ grpc_millis deadline, grpc_status_code *code,
+ grpc_slice *slice,
grpc_http2_error_code *http_status);
/// A utility function to check whether there is a clear status code that
diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c
index 8f24b8527c..a5ff9c9685 100644
--- a/src/core/lib/transport/metadata_batch.c
+++ b/src/core/lib/transport/metadata_batch.c
@@ -74,7 +74,7 @@ void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) {
void grpc_metadata_batch_init(grpc_metadata_batch *batch) {
memset(batch, 0, sizeof(*batch));
- batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
+ batch->deadline = GRPC_MILLIS_INF_FUTURE;
}
void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx,
@@ -268,9 +268,7 @@ void grpc_metadata_batch_clear(grpc_exec_ctx *exec_ctx,
}
bool grpc_metadata_batch_is_empty(grpc_metadata_batch *batch) {
- return batch->list.head == NULL &&
- gpr_time_cmp(gpr_inf_future(batch->deadline.clock_type),
- batch->deadline) == 0;
+ return batch->list.head == NULL && batch->deadline == GRPC_MILLIS_INF_FUTURE;
}
size_t grpc_metadata_batch_size(grpc_metadata_batch *batch) {
diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h
index 1b11a3e252..3498cdd926 100644
--- a/src/core/lib/transport/metadata_batch.h
+++ b/src/core/lib/transport/metadata_batch.h
@@ -50,9 +50,9 @@ typedef struct grpc_metadata_batch {
grpc_mdelem_list list;
grpc_metadata_batch_callouts idx;
/** Used to calculate grpc-timeout at the point of sending,
- or gpr_inf_future if this batch does not need to send a
+ or GRPC_MILLIS_INF_FUTURE if this batch does not need to send a
grpc-timeout */
- gpr_timespec deadline;
+ grpc_millis deadline;
} grpc_metadata_batch;
void grpc_metadata_batch_init(grpc_metadata_batch *batch);
diff --git a/src/core/lib/transport/status_conversion.c b/src/core/lib/transport/status_conversion.c
index 9a76977e4b..73d20a170b 100644
--- a/src/core/lib/transport/status_conversion.c
+++ b/src/core/lib/transport/status_conversion.c
@@ -37,8 +37,9 @@ int grpc_status_to_http2_error(grpc_status_code status) {
}
}
-grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error,
- gpr_timespec deadline) {
+grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx *exec_ctx,
+ grpc_http2_error_code error,
+ grpc_millis deadline) {
switch (error) {
case GRPC_HTTP2_NO_ERROR:
/* should never be received */
@@ -46,7 +47,7 @@ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error,
case GRPC_HTTP2_CANCEL:
/* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been
* exceeded */
- return gpr_time_cmp(gpr_now(deadline.clock_type), deadline) >= 0
+ return grpc_exec_ctx_now(exec_ctx) > deadline
? GRPC_STATUS_DEADLINE_EXCEEDED
: GRPC_STATUS_CANCELLED;
case GRPC_HTTP2_ENHANCE_YOUR_CALM:
diff --git a/src/core/lib/transport/status_conversion.h b/src/core/lib/transport/status_conversion.h
index e93f3dfd9b..a05ed7658c 100644
--- a/src/core/lib/transport/status_conversion.h
+++ b/src/core/lib/transport/status_conversion.h
@@ -20,12 +20,14 @@
#define GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H
#include <grpc/grpc.h>
+#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/transport/http2_errors.h"
/* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */
grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status);
-grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error,
- gpr_timespec deadline);
+grpc_status_code grpc_http2_error_to_grpc_status(grpc_exec_ctx *exec_ctx,
+ grpc_http2_error_code error,
+ grpc_millis deadline);
/* Conversion of HTTP status codes (:status) to grpc status codes */
grpc_status_code grpc_http2_status_to_grpc_status(int status);
diff --git a/src/core/lib/transport/timeout_encoding.c b/src/core/lib/transport/timeout_encoding.c
index 02f179d6a3..779d016ca6 100644
--- a/src/core/lib/transport/timeout_encoding.c
+++ b/src/core/lib/transport/timeout_encoding.c
@@ -59,60 +59,27 @@ static void enc_seconds(char *buffer, int64_t sec) {
}
}
-static void enc_nanos(char *buffer, int64_t x) {
+static void enc_millis(char *buffer, int64_t x) {
x = round_up_to_three_sig_figs(x);
- if (x < 100000) {
- if (x % 1000 == 0) {
- enc_ext(buffer, x / 1000, 'u');
- } else {
- enc_ext(buffer, x, 'n');
- }
- } else if (x < 100000000) {
- if (x % 1000000 == 0) {
- enc_ext(buffer, x / 1000000, 'm');
- } else {
- enc_ext(buffer, x / 1000, 'u');
- }
- } else if (x < 1000000000) {
- enc_ext(buffer, x / 1000000, 'm');
+ if (x < GPR_MS_PER_SEC) {
+ enc_ext(buffer, x, 'm');
} else {
- /* note that this is only ever called with times of less than one second,
- so if we reach here the time must have been rounded up to a whole second
- (and no more) */
- memcpy(buffer, "1S", 3);
- }
-}
-
-static void enc_micros(char *buffer, int64_t x) {
- x = round_up_to_three_sig_figs(x);
- if (x < 100000) {
- if (x % 1000 == 0) {
- enc_ext(buffer, x / 1000, 'm');
+ if (x % GPR_MS_PER_SEC == 0) {
+ enc_seconds(buffer, x / GPR_MS_PER_SEC);
} else {
- enc_ext(buffer, x, 'u');
+ enc_ext(buffer, x, 'm');
}
- } else if (x < 100000000) {
- if (x % 1000000 == 0) {
- enc_ext(buffer, x / 1000000, 'S');
- } else {
- enc_ext(buffer, x / 1000, 'm');
- }
- } else {
- enc_ext(buffer, x / 1000000, 'S');
}
}
-void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer) {
- if (timeout.tv_sec < 0) {
+void grpc_http2_encode_timeout(grpc_millis timeout, char *buffer) {
+ if (timeout <= 0) {
enc_tiny(buffer);
- } else if (timeout.tv_sec == 0) {
- enc_nanos(buffer, timeout.tv_nsec);
- } else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) {
- enc_micros(buffer,
- (int64_t)(timeout.tv_sec * 1000000) +
- (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0)));
+ } else if (timeout < 1000 * GPR_MS_PER_SEC) {
+ enc_millis(buffer, timeout);
} else {
- enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0));
+ enc_seconds(buffer,
+ timeout / GPR_MS_PER_SEC + (timeout % GPR_MS_PER_SEC != 0));
}
}
@@ -121,7 +88,7 @@ static int is_all_whitespace(const char *p, const char *end) {
return p == end;
}
-int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) {
+int grpc_http2_decode_timeout(grpc_slice text, grpc_millis *timeout) {
int32_t x = 0;
const uint8_t *p = GRPC_SLICE_START_PTR(text);
const uint8_t *end = GRPC_SLICE_END_PTR(text);
@@ -136,7 +103,7 @@ int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) {
/* spec allows max. 8 digits, but we allow values up to 1,000,000,000 */
if (x >= (100 * 1000 * 1000)) {
if (x != (100 * 1000 * 1000) || digit != 0) {
- *timeout = gpr_inf_future(GPR_TIMESPAN);
+ *timeout = GRPC_MILLIS_INF_FUTURE;
return 1;
}
}
@@ -150,22 +117,22 @@ int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) {
/* decode unit specifier */
switch (*p) {
case 'n':
- *timeout = gpr_time_from_nanos(x, GPR_TIMESPAN);
+ *timeout = x / GPR_NS_PER_MS + (x % GPR_NS_PER_MS != 0);
break;
case 'u':
- *timeout = gpr_time_from_micros(x, GPR_TIMESPAN);
+ *timeout = x / GPR_US_PER_MS + (x % GPR_US_PER_MS != 0);
break;
case 'm':
- *timeout = gpr_time_from_millis(x, GPR_TIMESPAN);
+ *timeout = x;
break;
case 'S':
- *timeout = gpr_time_from_seconds(x, GPR_TIMESPAN);
+ *timeout = x * GPR_MS_PER_SEC;
break;
case 'M':
- *timeout = gpr_time_from_minutes(x, GPR_TIMESPAN);
+ *timeout = x * 60 * GPR_MS_PER_SEC;
break;
case 'H':
- *timeout = gpr_time_from_hours(x, GPR_TIMESPAN);
+ *timeout = x * 60 * 60 * GPR_MS_PER_SEC;
break;
default:
return 0;
diff --git a/src/core/lib/transport/timeout_encoding.h b/src/core/lib/transport/timeout_encoding.h
index 7ff35c4083..c8677719c4 100644
--- a/src/core/lib/transport/timeout_encoding.h
+++ b/src/core/lib/transport/timeout_encoding.h
@@ -22,13 +22,14 @@
#include <grpc/slice.h>
#include <grpc/support/time.h>
+#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/support/string.h"
#define GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1)
/* Encode/decode timeouts to the GRPC over HTTP/2 format;
encoding may round up arbitrarily */
-void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer);
-int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout);
+void grpc_http2_encode_timeout(grpc_millis timeout, char *buffer);
+int grpc_http2_decode_timeout(grpc_slice text, grpc_millis *timeout);
#endif /* GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H */
diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c
index 409a6c4103..2d0b1e78ea 100644
--- a/src/core/lib/transport/transport_op_string.c
+++ b/src/core/lib/transport/transport_op_string.c
@@ -48,10 +48,9 @@ static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) {
if (m != md.list.head) gpr_strvec_add(b, gpr_strdup(", "));
put_metadata(b, m->md);
}
- if (gpr_time_cmp(md.deadline, gpr_inf_future(md.deadline.clock_type)) != 0) {
+ if (md.deadline != GRPC_MILLIS_INF_FUTURE) {
char *tmp;
- gpr_asprintf(&tmp, " deadline=%" PRId64 ".%09d", md.deadline.tv_sec,
- md.deadline.tv_nsec);
+ gpr_asprintf(&tmp, " deadline=%" PRIdPTR, md.deadline);
gpr_strvec_add(b, tmp);
}
}