Class: CZMQ::FFI::ZhttpResponse
- Inherits:
-
Object
- Object
- CZMQ::FFI::ZhttpResponse
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb
Overview
This class is 100% generated using zproject.
Http response that can be received from zhttp_client or sent to zhttp_server. Class can be reused between send & recv calls. Headers and Content is being destroyed after every send call.
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.new ⇒ CZMQ::ZhttpResponse
Create a new zhttp_response.
-
.test(verbose) ⇒ void
Self test of this class.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#content ⇒ String
Get the content of the response.
-
#content_length ⇒ Integer
Get the content length of the response.
-
#content_type ⇒ String
Get the response content type.
-
#destroy ⇒ void
Destroy the zhttp_response.
-
#get_content ⇒ ::FFI::AutoPointer
Get the content of the response.
-
#headers ⇒ Zhash
Get the headers of the response.
-
#initialize(ptr, finalize = true) ⇒ ZhttpResponse
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
- #null? ⇒ Boolean
-
#recv(client, arg, arg2) ⇒ Integer
Receive a response from zhttp_client.
-
#reset_content ⇒ void
Set the content to NULL.
-
#send(sock, connection) ⇒ Integer
Send a response to a request.
-
#set_content(content) ⇒ void
Set the content of the response.
-
#set_content_const(content) ⇒ void
Set the content of the response.
-
#set_content_type(value) ⇒ void
Set the content type of the response.
-
#set_status_code(status_code) ⇒ void
Set the status code of the response.
-
#status_code ⇒ Integer
Get the status code of the response.
Constructor Details
#initialize(ptr, finalize = true) ⇒ ZhttpResponse
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
26 27 28 29 30 31 32 33 34 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 26 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 |
Class Method Details
.__new ⇒ Object
20 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 20 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
37 38 39 40 41 42 43 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 37 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.zhttp_response_destroy ptr_ptr end end |
.new ⇒ CZMQ::ZhttpResponse
Create a new zhttp_response.
80 81 82 83 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 80 def self.new() ptr = ::CZMQ::FFI.zhttp_response_new() __new ptr end |
.test(verbose) ⇒ void
This method returns an undefined value.
Self test of this class.
251 252 253 254 255 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 251 def self.test(verbose) verbose = !(0==verbose||!verbose) # boolean result = ::CZMQ::FFI.zhttp_response_test(verbose) result end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
50 51 52 53 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 50 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
61 62 63 64 65 66 67 68 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 61 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 |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
73 74 75 76 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 73 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#content ⇒ String
Get the content of the response.
194 195 196 197 198 199 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 194 def content() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_content(self_p) result end |
#content_length ⇒ Integer
Get the content length of the response
184 185 186 187 188 189 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 184 def content_length() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_content_length(self_p) result end |
#content_type ⇒ String
Get the response content type
130 131 132 133 134 135 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 130 def content_type() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_content_type(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy the zhttp_response.
88 89 90 91 92 93 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 88 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zhttp_response_destroy(self_p) result end |
#get_content ⇒ ::FFI::AutoPointer
Get the content of the response.
204 205 206 207 208 209 210 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 204 def get_content() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_get_content(self_p) result = ::FFI::AutoPointer.new(result, LibC.method(:free)) result end |
#headers ⇒ Zhash
Get the headers of the response.
173 174 175 176 177 178 179 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 173 def headers() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_headers(self_p) result = Zhash.__new result, false result end |
#null? ⇒ Boolean
45 46 47 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 45 def null? !@ptr or @ptr.null? end |
#recv(client, arg, arg2) ⇒ Integer
Receive a response from zhttp_client. On success return 0, -1 otherwise.
Recv returns the two user arguments which was provided with the request. The reason for two, is to be able to pass around the server connection when forwarding requests or both a callback function and an argument.
119 120 121 122 123 124 125 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 119 def recv(client, arg, arg2) raise DestroyedError unless @ptr self_p = @ptr client = client.__ptr if client result = ::CZMQ::FFI.zhttp_response_recv(self_p, client, arg, arg2) result end |
#reset_content ⇒ void
This method returns an undefined value.
Set the content to NULL
240 241 242 243 244 245 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 240 def reset_content() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_reset_content(self_p) result end |
#send(sock, connection) ⇒ Integer
Send a response to a request. Returns 0 if successful and -1 otherwise.
101 102 103 104 105 106 107 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 101 def send(sock, connection) raise DestroyedError unless @ptr self_p = @ptr sock = sock.__ptr if sock result = ::CZMQ::FFI.zhttp_response_send(self_p, sock, connection) result end |
#set_content(content) ⇒ void
This method returns an undefined value.
Set the content of the response. Content must by dynamically allocated string. Takes ownership of the content.
218 219 220 221 222 223 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 218 def set_content(content) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_set_content(self_p, content) result end |
#set_content_const(content) ⇒ void
This method returns an undefined value.
Set the content of the response. The content is assumed to be constant-memory and will therefore not be copied or deallocated in any way.
230 231 232 233 234 235 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 230 def set_content_const(content) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_set_content_const(self_p, content) result end |
#set_content_type(value) ⇒ void
This method returns an undefined value.
Set the content type of the response.
141 142 143 144 145 146 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 141 def set_content_type(value) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_set_content_type(self_p, value) result end |
#set_status_code(status_code) ⇒ void
This method returns an undefined value.
Set the status code of the response.
162 163 164 165 166 167 168 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 162 def set_status_code(status_code) raise DestroyedError unless @ptr self_p = @ptr status_code = Integer(status_code) result = ::CZMQ::FFI.zhttp_response_set_status_code(self_p, status_code) result end |
#status_code ⇒ Integer
Get the status code of the response.
151 152 153 154 155 156 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zhttp_response.rb', line 151 def status_code() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zhttp_response_status_code(self_p) result end |