1# Copyright 2018 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15 16cdef gpr_timespec _timespec_from_time(object time) except *: 17 if time is None: 18 return gpr_inf_future(GPR_CLOCK_REALTIME) 19 else: 20 return gpr_time_from_nanos( 21 <int64_t>(<double>time * GPR_NS_PER_SEC), 22 GPR_CLOCK_REALTIME, 23 ) 24 25 26cdef double _time_from_timespec(gpr_timespec timespec) except *: 27 cdef gpr_timespec real_timespec = gpr_convert_clock_type( 28 timespec, GPR_CLOCK_REALTIME) 29 return gpr_timespec_to_micros(real_timespec) / GPR_US_PER_SEC 30