Home | History | Annotate | Download | only in _cygrpc
      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 
     16 cdef gpr_timespec _timespec_from_time(object time):
     17   cdef gpr_timespec timespec
     18   if time is None:
     19     return gpr_inf_future(GPR_CLOCK_REALTIME)
     20   else:
     21     timespec.seconds = time
     22     timespec.nanoseconds = (time - float(timespec.seconds)) * 1e9
     23     timespec.clock_type = GPR_CLOCK_REALTIME
     24     return timespec
     25 
     26 
     27 cdef double _time_from_timespec(gpr_timespec timespec):
     28   cdef gpr_timespec real_timespec = gpr_convert_clock_type(
     29       timespec, GPR_CLOCK_REALTIME)
     30   return <double>real_timespec.seconds + <double>real_timespec.nanoseconds / 1e9
     31