/* * * Copyright 2015 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include #include "rb_grpc.h" #include #include #include #include #include #include "rb_call.h" #include "rb_call_credentials.h" #include "rb_channel.h" #include "rb_channel_credentials.h" #include "rb_compression_options.h" #include "rb_event_thread.h" #include "rb_grpc_imports.generated.h" #include "rb_loader.h" #include "rb_server.h" #include "rb_server_credentials.h" #include "rb_xds_channel_credentials.h" #include "rb_xds_server_credentials.h" #include #include #include #ifdef GPR_LINUX #include #include #endif static VALUE grpc_rb_cTimeVal = Qnil; static rb_data_type_t grpc_rb_timespec_data_type = { "gpr_timespec", {GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, GRPC_RB_MEMSIZE_UNAVAILABLE, {NULL, NULL}}, NULL, NULL, #ifdef RUBY_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY #endif }; /* Alloc func that blocks allocation of a given object by raising an * exception. */ VALUE grpc_rb_cannot_alloc(VALUE cls) { rb_raise(rb_eTypeError, "allocation of %s only allowed from the gRPC native layer", rb_class2name(cls)); return Qnil; } /* Init func that fails by raising an exception. */ VALUE grpc_rb_cannot_init(VALUE self) { rb_raise(rb_eTypeError, "initialization of %s only allowed from the gRPC native layer", rb_obj_classname(self)); return Qnil; } /* Init/Clone func that fails by raising an exception. */ VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self) { (void)self; rb_raise(rb_eTypeError, "Copy initialization of %s is not supported", rb_obj_classname(copy)); return Qnil; } /* id_tv_{,u}sec are accessor methods on Ruby Time instances. */ static ID id_tv_sec; static ID id_tv_nsec; /** * grpc_rb_time_timeval creates a timeval from a ruby time object. * * This func is copied from ruby source, MRI/source/time.c, which is published * under the same license as the ruby.h, on which the entire extensions is * based. */ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) { gpr_timespec t; gpr_timespec* time_const; const char* tstr = interval ? "time interval" : "time"; const char* want = " want |