class CZMQ::FFI::ZhttpServer
Simple http server. To start handling requests:
-
Create a dealer socket
-
Connect the socket to the server backend address provided in the options.
-
Create a zhttp_request.
-
Call zhttp_request_recv to accept a new request.
-
Call zhttp_response_send to send a response.
You can connect as many dealers as you want. The Server is using simple dealer socket to route the requests.
NOTE: when using libmicrohttpd << 0.9.34 the application might experience high CPU usage due to the lack of MHD_suspend_connection and MHD_resume_connection APIs. It is recommended to use this class only with libmicrohttpd at least 0.9.34 in production. @note This class is 100% generated using zproject.
Public Class Methods
@param ptr [::FFI::Pointer] @return [Proc]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 49 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.zhttp_server_destroy ptr_ptr end end
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary. @param ptr [::FFI::Pointer] @param finalize [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 38 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end
Create a new http server @param options [ZhttpServerOptions, #__ptr] @return [CZMQ::ZhttpServer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 93 def self.new(options) options = options.__ptr if options ptr = ::CZMQ::FFI.zhttp_server_new(options) __new ptr end
Self test of this class.
@param verbose [Boolean] @return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 123 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zhttp_server_test(verbose) result end
Public Instance Methods
Return internal pointer @return [::FFI::Pointer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 62 def __ptr raise DestroyedError unless @ptr @ptr end
Nullify internal pointer and return pointer pointer. @note This detaches the current instance from the native object
and thus makes it unusable.
@return [::FFI::MemoryPointer] the pointer pointing to a pointer
pointing to the native object
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 73 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end
Undefines the finalizer for this object. @note Only use this if you need to and can guarantee that the native
object will be freed by other means.
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 85 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end
Destroy an http server
@return [void]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 102 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zhttp_server_destroy(self_p) result end
@return [Boolean]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 57 def null? !@ptr or @ptr.null? end
Return the port the server is listening on.
@return [Integer]
# File lib/czmq-ffi-gen/czmq/ffi/zhttp_server.rb, line 112 def port() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_server_port(self_p) result end