Guest User

Untitled

a guest
May 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. module LibZMQ
  2. extend FFI::Library
  3. LINUX = ["libzmq.so", "/usr/local/lib/libzmq.so", "/opt/local/lib/libzmq.so"]
  4. OSX = ["libzmq.dylib", "/usr/local/lib/libzmq.dylib", "/opt/local/lib/libzmq.dylib"]
  5. WINDOWS = []
  6. ffi_lib(LINUX + OSX + WINDOWS)
  7.  
  8. # Message api
  9. class Msg_t < FFI::Struct
  10. layout :content, :pointer,
  11. :flags, :uint8,
  12. :vsm_size, :uint8,
  13. :vsm_data, [:uint8, 30]
  14.  
  15. end # class Msg_t
  16.  
  17. attach_function :zmq_msg_init, [:pointer], :int
  18. attach_function :zmq_msg_init_size, [:pointer, :size_t], :int
  19. callback :message_deallocator, [:pointer, :pointer], :void
  20. attach_function :zmq_msg_init_data, [:pointer, :pointer, :size_t, :message_deallocator, :pointer], :int
  21. attach_function :zmq_msg_close, [:pointer], :int
  22. attach_function :zmq_msg_data, [:pointer], :pointer
  23. attach_function :zmq_msg_size, [:pointer], :size_t
  24. attach_function :zmq_msg_copy, [:pointer, :pointer], :int
  25. attach_function :zmq_msg_move, [:pointer, :pointer], :int
  26.  
  27. # Called by zmq_close
  28. MessageDeallocator = Proc.new do |data_ptr, hint_ptr|
  29. #puts "msg_callback: freed data [#{data_ptr}]"
  30. data_ptr.free
  31. end
  32. end
Add Comment
Please, Sign In to add comment