Closed AbhimanyuAryan closed 1 year ago
I followed up on this tutorial: https://morioh.com/p/c07e68e7377b
but it generates a Unix executable but I can't use that Julia. What I need is a .so
file
./fioapp
INFO: Listening on port 3000
INFO: Server is running 7 workers X 8 threads with facil.io 0.7.6 (kqueue)
* Detected capacity: 131056 open file limit
* Root pid: 50763
* Press ^C to stop
INFO: 50765 is running.
INFO: 50764 is running.
INFO: 50767 is running.
INFO: 50766 is running.
INFO: 50769 is running.
INFO: 50768 is running.
INFO: 50770 is running.
ok, so I used this command to create .so
file. make
command generated .o
files for lib
so I thought I could generate .so
using .o
gcc -shared -o libfacil.so \
facil/fio.o \
facil/cli/fio_cli.o \
facil/fiobj/fio_siphash.o \
facil/fiobj/fiobj_ary.o \
facil/fiobj/fiobj_data.o \
facil/fiobj/fiobj_hash.o \
facil/fiobj/fiobj_json.o \
facil/fiobj/fiobj_mustache.o \
facil/fiobj/fiobj_numbers.o \
facil/fiobj/fiobj_str.o \
facil/fiobj/fiobject.o \
facil/http/http.o \
facil/http/http1.o \
facil/http/http_internal.o \
facil/http/websockets.o \
facil/redis/redis_engine.o \
facil/tls/fio_tls_missing.o \
facil/tls/fio_tls_openssl.o
but looks like there are no exported symbols
$ nm -D libfacil.so
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: error: libfacil.so: File format has no dynamic symbol table
because my julia program can't use functions from libfacil.so
# Define the options structure according to facil.io documentation
mutable struct HttpOptions
on_request::Ptr{Cvoid}
log::Cint
end
# Define the on_request callback function
function on_request(request::Ptr{Cvoid})
# You may need to write more code here to handle the request
ccall((:http_write, "libfacil.so"), Cint, (Ptr{Cvoid}, Cstring, Csize_t), request, "HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\nHello World!\r\n", 44)
end
# Get a pointer to the on_request function
on_request_ptr = @cfunction(on_request, Cvoid, (Ptr{Cvoid},))
# Define the http_listen function
function http_listen(port::String, binding::String, options::Ref{HttpOptions})
ccall((:http_listen, "libfacil.so"), Cint, (Cstring, Cstring, Ref{HttpOptions}), port, binding, options)
end
# Define the facil_run function
function facil_run(threads::Cint)
ccall((:facil_run, "libfacil.so"), Cvoid, (Cint,), threads)
end
# Now call the functions
options = HttpOptions(on_request_ptr, 1)
http_listen("3000", "", Ref(options))
facil_run(Cint(1))
How can I compile facil into a shared library to use various functionality in Julia code? Something like this: https://github.com/AbhimanyuAryan/ccallex
I am not familiar with how
makefiles
work so that causes a lot of trouble in understandingtechnically, what I want to achieve is calling various facil functionality like starting a server, serving requests from julia ccall
result = ccall((:add, "libexample.so"), Int32, (Int32, Int32), 2, 3) println(result) # This should print 5
for this simple example. I can see the _add symbol is exported properly in .so
nm libexample.so
0000000000003f98 T _add
so it's definitely an issue with generating .so
file for facil library
ok no so the -D
flag was stripping the exports. Now I can see with nm libfacil.so
nm libfacil.so
000000000004cde0 s _DAY_NAMES
000000000004c358 S _FIOBJECT_VTABLE_ARRAY
000000000004c3a0 S _FIOBJECT_VTABLE_DATA
000000000004cd08 S _FIOBJECT_VTABLE_FLOAT
000000000004c3e8 S _FIOBJECT_VTABLE_HASH
000000000004ccc0 S _FIOBJECT_VTABLE_NUMBER
000000000004cd50 S _FIOBJECT_VTABLE_STRING
0000000000005e48 T _FIO_DEALLOC_NOOP
000000000004c300 S _FIO_DEFAULT_RW_HOOKS
0000000000002508 T _FIO_LOG2STDERR
0000000000054000 D _FIO_LOG_LEVEL
0000000000056010 D _FIO_MATCH_GLOB
0000000000056008 D _FIO_PUBSUB_DEFAULT
0000000000056180 D _HTTP1_VTABLE
0000000000056a98 S _HTTP_HEADER_ACCEPT
0000000000056aa0 S _HTTP_HEADER_ACCEPT_RANGES
0000000000056aa8 S _HTTP_HEADER_CACHE_CONTROL
0000000000056ab0 S _HTTP_HEADER_CONNECTION
0000000000056ab8 S _HTTP_HEADER_CONTENT_ENCODING
0000000000056ac0 S _HTTP_HEADER_CONTENT_LENGTH
0000000000056ac8 S _HTTP_HEADER_CONTENT_RANGE
0000000000056ad0 S _HTTP_HEADER_CONTENT_TYPE
0000000000056ad8 S _HTTP_HEADER_COOKIE
0000000000056ae0 S _HTTP_HEADER_DATE
0000000000056ae8 S _HTTP_HEADER_ETAG
0000000000056af0 S _HTTP_HEADER_HOST
0000000000056af8 S _HTTP_HEADER_LAST_MODIFIED
0000000000056b00 S _HTTP_HEADER_ORIGIN
0000000000056b08 S _HTTP_HEADER_SET_COOKIE
0000000000056b10 S _HTTP_HEADER_UPGRADE
0000000000056b18 S _HTTP_HEADER_WS_SEC_CLIENT_KEY
0000000000056b20 S _HTTP_HEADER_WS_SEC_KEY
0000000000056b28 S _HTTP_HVALUE_BYTES
0000000000056b30 S _HTTP_HVALUE_CLOSE
0000000000056b38 S _HTTP_HVALUE_CONTENT_TYPE_DEFAULT
0000000000056b40 S _HTTP_HVALUE_GZIP
0000000000056b48 S _HTTP_HVALUE_KEEP_ALIVE
0000000000056b50 S _HTTP_HVALUE_MAX_AGE
0000000000056b58 S _HTTP_HVALUE_NO_CACHE
0000000000056b60 S _HTTP_HVALUE_SSE_MIME
0000000000056b68 S _HTTP_HVALUE_WEBSOCKET
0000000000056b70 S _HTTP_HVALUE_WS_SEC_VERSION
0000000000056b78 S _HTTP_HVALUE_WS_UPGRADE
0000000000056b80 S _HTTP_HVALUE_WS_VERSION
0000000000040ada s _JSON_NUMERAL
00000000000407da s _JSON_SEPERATOR
000000000004ce18 s _MONTH_NAMES
0000000000018df8 t _OUTLINED_FUNCTION_0
000000000001c8c0 t _OUTLINED_FUNCTION_0
000000000001e094 t _OUTLINED_FUNCTION_0
0000000000022180 t _OUTLINED_FUNCTION_0
00000000000239fc t _OUTLINED_FUNCTION_0
0000000000018e00 t _OUTLINED_FUNCTION_1
000000000001c8c8 t _OUTLINED_FUNCTION_1
U __DefaultRuneLocale
0000000000018e14 t ___GLOBAL_init_65535
U ___assert_rtn
U ___chkstk_darwin
U ___cxa_atexit
U ___error
U ___maskrune
U ___memcpy_chk
U ___stack_chk_fail
U ___stack_chk_guard
U ___stderrp
U ___tolower
U __tlv_bootstrap
U _accept
0000000000056a20 b _add_content_length.cl_hash
0000000000056a38 b _add_content_type.ct_hash
0000000000025924 t _add_date
0000000000056a28 b _add_date.date_hash
0000000000056a30 b _add_date.mod_hash
0000000000056218 s _arena_last_used
00000000000563b0 s _arena_last_used$tlv$init
0000000000056900 b _arenas
000000000003ff38 s _base64_decodes
0000000000041fef s _base64_encodes_original
0000000000042031 s _base64_encodes_url
000000000000b92c t _big_alloc
U _bind
0000000000018a84 t _block_free
0000000000018be8 t _block_new
000000000003eb74 t _block_new.cold.1
U _bzero
00000000000566a8 b _callback_collection
U _calloc
U _clock_gettime
U _close
0000000000056058 d _cluster_data
U _connect
0000000000039078 T _create_ws_buffer
00000000000569e0 b _current_date
00000000000569d8 b _date_lock
0000000000013548 t _deferred_on_close
0000000000004030 t _deferred_on_data
0000000000004454 t _deferred_on_ready
00000000000138a4 t _deferred_on_ready_usr
0000000000014bd0 t _deferred_on_shutdown
00000000000042f0 t _deferred_ping
0000000000056290 s _each_at_key
00000000000563d0 s _each_at_key$tlv$init
0000000000056050 d _evio_fd
U _exit
U _fchmod
U _fcntl
000000000000463c T _fio_accept
0000000000015cb8 t _fio_accept_after_fork
0000000000056960 b _fio_aliases
000000000001afe0 t _fio_ary_____require_on_top
00000000000085d8 T _fio_atof
0000000000004ef4 T _fio_atol
0000000000006708 T _fio_attach
000000000000670c t _fio_attach__internal
0000000000006978 T _fio_attach_fd
0000000000013298 T _fio_base64_decode
0000000000013060 T _fio_base64_encode
000000000001317c T _fio_base64url_encode
000000000000ba14 T _fio_calloc
00000000000025f4 T _fio_capa
0000000000015348 t _fio_ch_set__find_map_pos_
00000000000151b8 t _fio_ch_set_rehash
000000000003eae4 t _fio_ch_set_rehash.cold.1
0000000000015550 t _fio_channel_copy
0000000000002848 t _fio_clear_fd
0000000000019230 T _fio_cli_end
00000000000191c8 t _fio_cli_end_promise
0000000000019a30 T _fio_cli_get
0000000000019aa8 T _fio_cli_get_i
0000000000019d30 t _fio_cli_hash__find_map_pos_
0000000000019bfc t _fio_cli_hash_insert
0000000000019f20 t _fio_cli_hash_rehash
000000000003ebb0 t _fio_cli_hash_rehash.cold.1
0000000000019ba4 T _fio_cli_set
0000000000019534 t _fio_cli_set_arg
0000000000018e2c T _fio_cli_start
0000000000056928 b _fio_cli_start.run_once
0000000000019b3c T _fio_cli_unnamed
0000000000019b30 T _fio_cli_unnamed_count
0000000000005e98 T _fio_close
0000000000015d54 t _fio_cluster_at_exit
0000000000015d24 t _fio_cluster_cleanup
000000000001860c t _fio_cluster_client_handler
000000000000b574 t _fio_cluster_client_sender
0000000000016210 t _fio_cluster_data_cleanup
0000000000016378 t _fio_cluster_listen_accept
00000000000164c8 t _fio_cluster_listen_on_close
00000000000171e4 t _fio_cluster_on_close
0000000000018360 t _fio_cluster_on_connect
0000000000016d4c t _fio_cluster_on_data
000000000003e9bc t _fio_cluster_on_fail
0000000000017188 t _fio_cluster_on_shutdown
00000000000175b4 t _fio_cluster_ping
000000000001651c t _fio_cluster_protocol_alloc
0000000000016684 t _fio_cluster_server_handler
00000000000147b4 t _fio_cluster_server_sender
0000000000009370 T _fio_connect
0000000000015cc8 t _fio_connect2cluster
00000000000097c0 t _fio_connect_on_close
00000000000096f0 t _fio_connect_on_ready
000000000000960c t _fio_connect_on_ready_tls
000000000000953c t _fio_connect_on_ready_tls_alpn
0000000000013fa8 t _fio_cycle
0000000000014004 t _fio_cycle_schedule_events
0000000000056914 b _fio_cycle_schedule_events.idle
0000000000056918 b _fio_cycle_schedule_events.last_to_review
0000000000014e64 t _fio_cycle_unwind
0000000000056648 b _fio_data
0000000000003330 T _fio_defer
0000000000003718 T _fio_defer_clear_queue
0000000000014a94 t _fio_defer_cycle
00000000000036c4 T _fio_defer_has_queue
0000000000007370 T _fio_defer_io_task
00000000000034d8 T _fio_defer_perform
0000000000003518 t _fio_defer_perform_single_task_for_queue
0000000000003370 t _fio_defer_push_task_fn
0000000000056278 s _fio_defer_thread_wait.static_throttle
0000000000056368 s _fio_defer_thread_wait.static_throttle$tlv$init
0000000000003f58 T _fio_engine
0000000000015930 t _fio_engine_set__find_map_pos_
0000000000015774 t _fio_engine_set_rehash
000000000003eb00 t _fio_engine_set_rehash.cold.1
0000000000003d40 T _fio_expected_concurrency
00000000000566a0 b _fio_expected_concurrency.print_cores_warning
0000000000022310 t _fio_f2f
0000000000022300 t _fio_f2i
000000000002224c t _fio_f2str
000000000000275c T _fio_fd2uuid
0000000000014fb0 t _fio_filter_dup_lock_internal
0000000000005fe4 T _fio_flush
0000000000006334 T _fio_flush_all
0000000000005368 T _fio_force_close
0000000000003f64 T _fio_force_event
0000000000003228 T _fio_fork
0000000000056911 b _fio_fork_lock
0000000000007174 T _fio_free
0000000000008bd4 T _fio_ftoa
000000000002248c T _fio_ftocstr
000000000002221c t _fio_ftrue
000000000000b728 t _fio_glob_match
000000000001dc58 t _fio_hash____find_map_pos_
000000000001cfec t _fio_hash___insert
000000000001c8f4 t _fio_hash___rehash
000000000003f014 t _fio_hash___rehash.cold.1
0000000000056038 D _fio_hash_secret_marker1
0000000000056039 D _fio_hash_secret_marker2
00000000000063f4 t _fio_hooks_default_before_close
00000000000063fc t _fio_hooks_default_cleanup
00000000000063ec t _fio_hooks_default_flush
00000000000063cc t _fio_hooks_default_read
00000000000063dc t _fio_hooks_default_write
0000000000056a40 b _fio_http_at_capa
00000000000569e8 b _fio_http_mime_types
000000000002220c t _fio_i2f
0000000000022200 t _fio_i2i
00000000000221b8 t _fio_i2str
000000000001b244 t _fio_io2str
0000000000007424 t _fio_io_task_perform
0000000000002c00 T _fio_is_closed
0000000000003d08 T _fio_is_master
0000000000002c78 T _fio_is_running
0000000000002bc4 T _fio_is_valid
0000000000003cf8 T _fio_is_worker
0000000000022188 t _fio_itrue
000000000001f5a4 t _fio_json_on_string
000000000001e130 t _fio_json_parse
0000000000002c9c T _fio_last_tick
0000000000007524 t _fio_lib_destroy
0000000000007a30 t _fio_lib_init
000000000003ea38 t _fio_lib_init.cold.1
0000000000008d58 T _fio_listen
0000000000015b58 t _fio_listen2cluster
000000000003eb1c t _fio_listen2cluster.cold.1
00000000000092e4 t _fio_listen_cleanup_task
00000000000091f8 t _fio_listen_on_close
0000000000009174 t _fio_listen_on_data
0000000000009094 t _fio_listen_on_data_tls
0000000000009000 t _fio_listen_on_data_tls_alpn
0000000000009248 t _fio_listen_on_startup
0000000000002d7c T _fio_local_addr
00000000000085e4 T _fio_ltoa
0000000000022448 T _fio_ltocstr
0000000000006f44 T _fio_malloc
000000000000b8d0 T _fio_malloc_after_fork
000000000000bc48 t _fio_memcpy
000000000000ab48 T _fio_message_defer
000000000000ab08 T _fio_message_metadata
000000000000a96c T _fio_message_metadata_callback_set
0000000000015ad4 t _fio_meta_ary___require_on_top
000000000002ba3c t _fio_mime_set_rehash
000000000003f78c t _fio_mime_set_rehash.cold.1
0000000000007dd8 T _fio_mmap
0000000000017818 t _fio_mock_on_message
000000000000af38 t _fio_msg_internal_create
0000000000014998 t _fio_msg_internal_free2
0000000000056650 b _fio_old_sig_chld
0000000000056660 b _fio_old_sig_int
0000000000056680 b _fio_old_sig_pipe
0000000000056670 b _fio_old_sig_term
0000000000056690 b _fio_old_sig_usr1
0000000000007784 t _fio_on_fork
0000000000003d30 T _fio_parent_pid
0000000000002cf4 T _fio_peer_addr
0000000000005e4c T _fio_pending
0000000000018834 t _fio_perform_subscription_callback
0000000000013bd4 t _fio_poll_add
0000000000013814 t _fio_poll_add_read
0000000000005f50 t _fio_poll_add_write
0000000000013b14 t _fio_poll_remove_fd
00000000000567f8 b _fio_postoffice
0000000000017728 t _fio_postoffice_meta_copy_new
0000000000002610 T _fio_protocol_try_lock
000000000000273c T _fio_protocol_unlock
000000000000ab54 T _fio_publish
0000000000018648 t _fio_publish2channel_task
000000000000b168 t _fio_publish2process
000000000000a4cc T _fio_pubsub_attach
000000000000a7bc T _fio_pubsub_detach
000000000000a8b8 T _fio_pubsub_is_attached
0000000000015600 t _fio_pubsub_on_channel_create
0000000000013c74 t _fio_pubsub_on_fork
000000000000a60c T _fio_pubsub_reattach
000000000000bcf8 T _fio_rand64
0000000000056260 s _fio_rand64.c
00000000000563c8 s _fio_rand64.c$tlv$init
0000000000056230 s _fio_rand64.s.0
00000000000563b8 s _fio_rand64.s.0$tlv$init
0000000000056248 s _fio_rand64.s.1
00000000000563c0 s _fio_rand64.s.1$tlv$init
000000000000bf60 T _fio_rand_bytes
0000000000005184 T _fio_read
000000000000bce8 T _fio_realloc
000000000000ba1c T _fio_realloc2
0000000000003b48 T _fio_reap_children
000000000003ea10 t _fio_reap_children.cold.1
00000000000144a0 t _fio_review_timeout
000000000000be08 t _fio_risky_hash
0000000000019298 t _fio_risky_hash
0000000000003898 T _fio_run_every
0000000000006400 T _fio_rw_hook_replace_unsafe
0000000000006520 T _fio_rw_hook_set
0000000000007fa0 t _fio_sentinel_task
0000000000013e38 t _fio_sentinel_worker_thread
000000000003ea90 t _fio_sentinel_worker_thread.cold.1
00000000000045e8 T _fio_set_non_block
000000000000cb48 T _fio_sha1_init
000000000000cc40 t _fio_sha1_perform_all_rounds
000000000000dc78 T _fio_sha1_result
000000000000cb74 T _fio_sha1_write
000000000000dd78 T _fio_sha2_init
000000000000e018 t _fio_sha2_perform_all_rounds
0000000000012df0 T _fio_sha2_result
000000000000debc T _fio_sha2_write
0000000000056a91 S _fio_signal_children_flag
0000000000003c08 T _fio_signal_handler_reset
0000000000056a92 S _fio_signal_set_flag
000000000000a4a4 T _fio_siphash13
000000000000c848 T _fio_siphash24
000000000000c85c t _fio_siphash_xy
000000000001a0c4 t _fio_siphash_xy
00000000000139d8 t _fio_sock_packet_rotate_unsafe
0000000000005d1c t _fio_sock_perform_close_fd
0000000000005954 t _fio_sock_sendfile_from_fd
0000000000005d20 t _fio_sock_write_buffer
0000000000005ac4 t _fio_sock_write_from_fd
00000000000048dc T _fio_socket
0000000000007de4 T _fio_start
0000000000006a40 T _fio_state_callback_add
00000000000071a8 T _fio_state_callback_clear
00000000000072f4 T _fio_state_callback_clear_all
0000000000006cc0 T _fio_state_callback_force
00000000000072b0 T _fio_state_callback_on_fork
0000000000006ba0 T _fio_state_callback_remove
0000000000007168 t _fio_state_on_idle_perform
0000000000002c64 T _fio_stop
000000000002251c t _fio_str2bool
0000000000022678 t _fio_str2f
000000000002263c t _fio_str2i
00000000000225e0 t _fio_str2str
00000000000180b0 t _fio_str_capa_assert
000000000002273c t _fio_str_capa_assert
000000000003d620 t _fio_str_capa_assert
0000000000017ef4 t _fio_str_concat
000000000003de30 t _fio_str_free2
000000000004af6b s _fio_str_utf8_map
000000000003aff0 t _fio_str_utf8_valid
0000000000023298 t _fio_str_vprintf
00000000000229e8 t _fio_str_write
000000000003dcc8 t _fio_str_write
0000000000017c70 t _fio_sub_hash__find_map_pos_
000000000001781c t _fio_sub_hash_insert
0000000000017a50 t _fio_sub_hash_rehash
000000000003eb58 t _fio_sub_hash_rehash.cold.1
0000000000009e40 T _fio_subscribe
000000000000a4b8 T _fio_subscription_channel
000000000000458c T _fio_suspend
00000000000032c0 T _fio_thread_free
00000000000032ec T _fio_thread_join
0000000000056a90 S _fio_thread_lock
000000000000322c T _fio_thread_new
0000000000054008 D _fio_thread_queue
0000000000006a24 T _fio_timeout_get
000000000000699c T _fio_timeout_set
00000000000039cc t _fio_timer_add_order
0000000000007950 t _fio_timer_clear_all
0000000000056910 b _fio_timer_lock
0000000000014750 t _fio_timer_perform_single
0000000000056040 d _fio_timers
0000000000008c98 T _fio_tls_accept
00000000000249f4 T _fio_tls_alpn_add
0000000000008c90 T _fio_tls_alpn_count
000000000003e95c T _fio_tls_cert_add
0000000000008cc8 T _fio_tls_connect
0000000000008d28 T _fio_tls_destroy
0000000000008cf8 T _fio_tls_dup
000000000003e92c T _fio_tls_new
000000000003e98c T _fio_tls_trust
0000000000002cac T _fio_touch
0000000000056990 b _fio_unnamed_count
000000000000a05c T _fio_unsubscribe
0000000000009838 T _fio_url_parse
0000000000002e4c T _fio_uuid_link
0000000000013728 t _fio_uuid_links__find_map_pos_
0000000000013598 t _fio_uuid_links_rehash
000000000003ea74 t _fio_uuid_links_rehash.cold.1
0000000000003060 T _fio_uuid_unlink
0000000000056930 b _fio_values
00000000000082cc t _fio_worker_cleanup
00000000000080a0 t _fio_worker_startup
0000000000005664 T _fio_write2_fn
000000000003d91c t _fiobj2resp___internal
000000000003d8d4 t _fiobj2resp_task
000000000002d350 t _fiobj4sock_dealloc
000000000003b2fc t _fiobj4sock_dealloc
000000000003dabc t _fiobj4sock_dealloc
000000000001a660 T _fiobj_ary2ptr
000000000003ec88 t _fiobj_ary2ptr.cold.1
000000000001a624 T _fiobj_ary_capa
000000000003ec60 t _fiobj_ary_capa.cold.1
000000000001af54 T _fiobj_ary_compact
000000000003ee40 t _fiobj_ary_compact.cold.1
000000000001a3ac T _fiobj_ary_count
000000000003ebd0 t _fiobj_ary_count.cold.1
000000000001a3f4 t _fiobj_ary_dealloc
000000000001a4fc t _fiobj_ary_each1
000000000001ad00 T _fiobj_ary_find
000000000003edc8 t _fiobj_ary_find.cold.1
000000000001a6a4 T _fiobj_ary_index
000000000003ecb0 t _fiobj_ary_index.cold.1
000000000001a4e0 t _fiobj_ary_is_eq
000000000001a494 t _fiobj_ary_is_true
000000000003ebf8 t _fiobj_ary_is_true.cold.1
000000000001a57c T _fiobj_ary_new
000000000003ec20 t _fiobj_ary_new.cold.1
000000000001a5c0 T _fiobj_ary_new2
000000000003ec40 t _fiobj_ary_new2.cold.1
000000000001aa9c T _fiobj_ary_pop
000000000003ed28 t _fiobj_ary_pop.cold.1
000000000001aa04 T _fiobj_ary_push
000000000003ed00 t _fiobj_ary_push.cold.1
000000000001ad90 T _fiobj_ary_remove
000000000003edf0 t _fiobj_ary_remove.cold.1
000000000001ae50 T _fiobj_ary_remove2
000000000003ee18 t _fiobj_ary_remove2.cold.1
000000000001ac80 T _fiobj_ary_replace
000000000003eda0 t _fiobj_ary_replace.cold.1
000000000001a718 T _fiobj_ary_set
000000000003ecd8 t _fiobj_ary_set.cold.1
000000000001ac20 T _fiobj_ary_shift
000000000003ed78 t _fiobj_ary_shift.cold.1
000000000001aafc T _fiobj_ary_unshift
000000000003ed50 t _fiobj_ary_unshift.cold.1
000000000001c110 T _fiobj_data_assert_dynamic
000000000003ef10 t _fiobj_data_assert_dynamic.cold.1
000000000001b068 t _fiobj_data_dealloc
000000000001b330 t _fiobj_data_i
000000000001b0cc t _fiobj_data_is_true
000000000001b13c t _fiobj_data_iseq
000000000001b6f4 T _fiobj_data_len
000000000001b464 T _fiobj_data_newfd
000000000003eebc t _fiobj_data_newfd.cold.1
000000000003eed8 t _fiobj_data_newfd.cold.2
000000000001b398 T _fiobj_data_newstr
000000000003ee68 t _fiobj_data_newstr.cold.1
000000000003ee84 t _fiobj_data_newstr.cold.2
000000000001b404 T _fiobj_data_newstr2
000000000003eea0 t _fiobj_data_newstr2.cold.1
000000000001b4c4 T _fiobj_data_newtmpfile
000000000001bdf8 T _fiobj_data_pos
000000000001c178 t _fiobj_data_pre_write
000000000003ef34 t _fiobj_data_pre_write.cold.1
000000000003ef50 t _fiobj_data_pre_write.cold.2
000000000003ef6c t _fiobj_data_pre_write.cold.3
000000000003ef88 t _fiobj_data_pre_write.cold.4
000000000001bf54 T _fiobj_data_pread
000000000001c524 T _fiobj_data_puts
000000000003efc8 t _fiobj_data_puts.cold.1
000000000001b96c T _fiobj_data_read
000000000001bb84 T _fiobj_data_read2ch
000000000001b784 T _fiobj_data_save
000000000001be48 T _fiobj_data_seek
000000000001b540 T _fiobj_data_slice
000000000003eef4 t _fiobj_data_slice.cold.1
000000000001c3cc T _fiobj_data_write
000000000003efa4 t _fiobj_data_write.cold.1
0000000000024080 t _fiobj_dealloc_task
0000000000024644 t _fiobj_each1
000000000002a0e0 t _fiobj_each1
000000000002d158 t _fiobj_each1
0000000000023a04 T _fiobj_each2
0000000000022230 t _fiobj_f_is_eq
0000000000022390 T _fiobj_float_new
000000000003f498 t _fiobj_float_new.cold.1
00000000000223d0 T _fiobj_float_set
000000000003f4b8 t _fiobj_float_set.cold.1
0000000000022414 T _fiobj_float_tmp
00000000000562c0 s _fiobj_float_tmp.ret
00000000000563e8 s _fiobj_float_tmp.ret$tlv$init
000000000001a7fc t _fiobj_free
000000000001c6b8 t _fiobj_free
000000000001d2f4 t _fiobj_free
000000000001ebc8 t _fiobj_free
0000000000024a78 t _fiobj_free
000000000002d354 t _fiobj_free
000000000002f3e0 t _fiobj_free
000000000003ade8 t _fiobj_free
000000000003dac0 t _fiobj_free
0000000000023f48 T _fiobj_free_complex_object
000000000001caf4 T _fiobj_hash2num
000000000003f058 t _fiobj_hash2num.cold.1
000000000001cf40 T _fiobj_hash_capa
000000000003f0c8 t _fiobj_hash_capa.cold.1
000000000001dbb4 T _fiobj_hash_clear
000000000003f230 t _fiobj_hash_clear.cold.1
000000000001cacc T _fiobj_hash_count
000000000003f034 t _fiobj_hash_count.cold.1
000000000001cb1c t _fiobj_hash_dealloc
000000000001d8f0 T _fiobj_hash_delete
000000000001d9cc T _fiobj_hash_delete2
000000000001cc74 t _fiobj_hash_each1
000000000003f0a0 t _fiobj_hash_each1.cold.1
000000000001da8c T _fiobj_hash_get
000000000003f1b8 t _fiobj_hash_get.cold.1
000000000001daf4 T _fiobj_hash_get2
000000000003f1e0 t _fiobj_hash_get2.cold.1
000000000001db44 T _fiobj_hash_haskey
000000000003f208 t _fiobj_hash_haskey.cold.1
000000000001cc58 t _fiobj_hash_is_eq
000000000001cc28 t _fiobj_hash_is_true
000000000003f07c t _fiobj_hash_is_true.cold.1
000000000001caa8 T _fiobj_hash_key_in_loop
000000000001cdfc T _fiobj_hash_new
000000000001ce80 T _fiobj_hash_new2
000000000001d4fc T _fiobj_hash_pop
000000000003f118 t _fiobj_hash_pop.cold.1
000000000001c8d0 T _fiobj_hash_rehash
000000000003efec t _fiobj_hash_rehash.cold.1
000000000001d6c4 T _fiobj_hash_remove
000000000003f168 t _fiobj_hash_remove.cold.1
000000000001d7e4 T _fiobj_hash_remove2
000000000003f190 t _fiobj_hash_remove2.cold.1
000000000001d64c T _fiobj_hash_replace
000000000003f140 t _fiobj_hash_replace.cold.1
000000000001cf68 T _fiobj_hash_set
000000000003f0f0 t _fiobj_hash_set.cold.1
000000000001edd0 T _fiobj_hash_update_json
000000000002219c t _fiobj_i_is_eq
000000000001de24 t _fiobj_iseq
00000000000267bc t _fiobj_iseq
000000000002431c T _fiobj_iseq____internal_complex__
000000000002476c t _fiobj_iseq____internal_complex__task
00000000000248b4 t _fiobj_iseq_simple
000000000001e09c T _fiobj_json2obj
000000000002125c T _fiobj_mustache_build
0000000000020ed0 T _fiobj_mustache_build2
0000000000021f78 t _fiobj_mustache_find_obj
0000000000020ecc T _fiobj_mustache_free
000000000001fdc0 T _fiobj_mustache_load
0000000000020e9c T _fiobj_mustache_new
000000000002231c T _fiobj_num_new_bignum
000000000003f478 t _fiobj_num_new_bignum.cold.1
0000000000022358 T _fiobj_num_tmp
00000000000562a8 s _fiobj_num_tmp.ret
00000000000563d8 s _fiobj_num_tmp.ret$tlv$init
000000000001f9ec t _fiobj_obj2cstr
00000000000255e4 t _fiobj_obj2cstr
000000000002d054 t _fiobj_obj2cstr
000000000002f2dc t _fiobj_obj2cstr
000000000003ace4 t _fiobj_obj2cstr
000000000003b58c t _fiobj_obj2cstr
000000000001d214 t _fiobj_obj2hash
000000000001f574 T _fiobj_obj2json
000000000001ee4c T _fiobj_obj2json2
000000000003f258 t _fiobj_obj2json2.cold.1
000000000001ef80 t _fiobj_obj2json_task
00000000000226b4 T _fiobj_str_buf
000000000003f4e0 t _fiobj_str_buf.cold.1
0000000000022ce4 T _fiobj_str_capa
000000000003f55c t _fiobj_str_capa.cold.1
0000000000022c98 T _fiobj_str_capa_assert
000000000003f534 t _fiobj_str_capa_assert.cold.1
0000000000022ed4 T _fiobj_str_clear
000000000003f5d4 t _fiobj_str_clear.cold.1
0000000000022df4 T _fiobj_str_compact
000000000003f5ac t _fiobj_str_compact.cold.1
0000000000023808 T _fiobj_str_concat
000000000003f69c t _fiobj_str_concat.cold.1
00000000000224cc t _fiobj_str_dealloc
0000000000022c7c T _fiobj_str_freeze
0000000000023990 T _fiobj_str_hash
000000000003f6c4 t _fiobj_str_hash.cold.1
0000000000022548 t _fiobj_str_is_eq
0000000000022b50 T _fiobj_str_move
000000000003f518 t _fiobj_str_move.cold.1
0000000000022960 T _fiobj_str_new
000000000003f4fc t _fiobj_str_new.cold.1
000000000002323c T _fiobj_str_printf
000000000003f64c t _fiobj_str_printf.cold.1
00000000000234a4 T _fiobj_str_readfile
0000000000022d3c T _fiobj_str_resize
000000000003f584 t _fiobj_str_resize.cold.1
0000000000022bb8 T _fiobj_str_tmp
00000000000562f0 s _fiobj_str_tmp.tmp
0000000000056370 s _fiobj_str_tmp.tmp$tlv$init
0000000000023454 T _fiobj_str_vprintf
000000000003f674 t _fiobj_str_vprintf.cold.1
0000000000022f68 T _fiobj_str_write
000000000003f5fc t _fiobj_str_write.cold.1
0000000000022fb8 T _fiobj_str_write_i
000000000003f624 t _fiobj_str_write_i.cold.1
0000000000023e50 t _fiobj_task_wrapper
00000000000249c8 T _fiobject___noop_count
00000000000249bc T _fiobject___noop_dealloc
00000000000249d0 T _fiobject___noop_is_eq
00000000000249ec T _fiobject___noop_to_f
00000000000249e4 T _fiobject___noop_to_i
00000000000249d8 T _fiobject___noop_to_str
00000000000249c0 T _fiobject___simple_dealloc
U _fork
U _fprintf
U _fputc
U _free
0000000000039130 T _free_ws_buffer
U _freeaddrinfo
U _fstat
U _fwrite
U _getaddrinfo
U _getenv
U _gethostname
U _getpid
U _getrlimit
U _getrusage
U _getsockopt
000000000002cc10 t _headers2str
0000000000056a48 b _headers2str.connection_hash
0000000000056a50 b _headers2str.host_hash
0000000000040bd9 s _hex_chars
0000000000041266 s _hex_chars
000000000002bf38 t _htt1p_finish
000000000002cf1c t _http1_after_finish
000000000002d7f0 t _http1_consume_data
000000000002ea98 t _http1_consume_header_top
000000000002ea14 t _http1_consume_header_trailer
000000000002caec T _http1_destroy
000000000002c488 t _http1_hijack
000000000002bfbc t _http1_http2websocket
000000000003f7ac t _http1_http2websocket.cold.1
0000000000056a60 b _http1_http2websocket_server.sec_key
0000000000056a58 b _http1_http2websocket_server.sec_version
00000000000561ee d _http1_http2websocket_server.ws_key_accpt_str
000000000002c838 T _http1_new
000000000002cae4 t _http1_on_close
000000000002d778 t _http1_on_data
000000000002c9c4 t _http1_on_data_first_time
000000000002e7d8 t _http1_on_header
000000000002c460 t _http1_on_pause
000000000002cac8 t _http1_on_ready
000000000002e718 t _http1_on_request
000000000002e6c0 t _http1_on_response
000000000002c470 t _http1_on_resume
000000000002bfb4 t _http1_push_data
000000000002c458 t _http1_push_file
000000000002bcbc t _http1_send_body
000000000002bd64 t _http1_sendfile
000000000002c810 t _http1_sse_close
000000000002d688 t _http1_sse_on_close
000000000002d650 t _http1_sse_on_ready
000000000002d664 t _http1_sse_on_shutdown
000000000002d734 t _http1_sse_ping
000000000002c7b4 t _http1_sse_write
000000000002c4f8 t _http1_upgrade2sse
000000000002c82c T _http1_vtable
000000000002d604 t _http1_websocket_client_on_failed
000000000002d55c t _http1_websocket_client_on_hangup
000000000002d5a0 t _http1_websocket_client_on_upgrade
000000000004f560 s _http1pr_status2str.status2str
0000000000028540 T _http_add2hash
0000000000028bc0 T _http_add2hash2
0000000000027460 T _http_connect
000000000003f750 t _http_connect.cold.1
000000000002ae84 T _http_date2rfc2109
000000000002acb4 T _http_date2rfc2822
000000000002ab04 T _http_date2rfc7231
000000000002b1ec T _http_decode_path
000000000002b2b8 T _http_decode_path_unsafe
000000000002b038 T _http_decode_url
000000000002b118 T _http_decode_url_unsafe
0000000000025884 T _http_finish
000000000002a794 T _http_gmtime
0000000000026fd4 T _http_hijack
0000000000038e04 t _http_lib_cleanup
000000000002f7a8 t _http_lib_constructor
000000000002f7dc t _http_lib_init
0000000000026fec T _http_listen
000000000002b934 T _http_mimetype_clear
0000000000026b98 T _http_mimetype_find
000000000002b7b8 T _http_mimetype_find2
0000000000056350 s _http_mimetype_find2.buffer
0000000000056638 s _http_mimetype_find2.buffer$tlv$init
000000000002b374 T _http_mimetype_register
000000000002b770 T _http_mimetype_stats
0000000000027948 t _http_on_client_failed
000000000002b9e4 t _http_on_close_client
000000000002741c t _http_on_finish
0000000000027414 t _http_on_open
00000000000278c0 t _http_on_open_client
000000000002b9cc t _http_on_request_fallback
000000000002ee40 T _http_on_request_handler______internal
0000000000056a70 b _http_on_request_handler______internal.host_hash
000000000002b9d4 t _http_on_response_fallback
000000000002f5e8 T _http_on_response_handler______internal
0000000000027350 t _http_on_server_protocol_http1
000000000002b9dc t _http_on_upgrade_fallback
000000000002920c T _http_parse_body
00000000000569d0 b _http_parse_body.content_type_hash
00000000000286a0 T _http_parse_cookies
00000000000569c8 b _http_parse_cookies.setcookie_header_hash
0000000000028438 T _http_parse_query
0000000000026e1c T _http_pause
0000000000026efc t _http_pause_wrapper
0000000000026e04 T _http_paused_udata_get
0000000000026e0c T _http_paused_udata_set
0000000000027454 T _http_peer_addr
0000000000026d28 T _http_push_data
0000000000026d48 T _http_push_file
0000000000029f24 T _http_req2str
0000000000026f00 T _http_resume
0000000000026fa4 t _http_resume_fallback_wrapper
0000000000026f4c t _http_resume_wrapper
000000000002cb74 t _http_s_destroy
00000000000256f4 T _http_send_body
0000000000026a24 T _http_send_error
000000000002f694 T _http_send_error2
000000000003f7d4 t _http_send_error2.cold.1
0000000000025b54 T _http_sendfile
0000000000025cd4 T _http_sendfile2
00000000000569a8 b _http_sendfile2.accept_enc_hash
000000000003f6ec t _http_sendfile2.cold.1
00000000000569c0 b _http_sendfile2.ifrange_hash
00000000000569b8 b _http_sendfile2.none_match_hash
00000000000569b0 b _http_sendfile2.range_hash
0000000000024eb8 T _http_set_cookie
00000000000569a0 b _http_set_cookie.cookie_hash
0000000000056998 b _http_set_cookie.warn_illegal
0000000000024a24 T _http_set_header
0000000000024dec T _http_set_header2
00000000000256e8 T _http_settings
00000000000270dc t _http_settings_new
000000000002838c T _http_sse2uuid
00000000000283c4 T _http_sse_close
000000000002840c T _http_sse_dup
000000000002841c T _http_sse_free
0000000000027e00 t _http_sse_on_message
0000000000027db4 t _http_sse_on_message__direct
0000000000027eb4 t _http_sse_on_unsubscribe
0000000000028028 T _http_sse_set_timout
0000000000027bd0 T _http_sse_subscribe
0000000000027f10 T _http_sse_unsubscribe
0000000000028038 T _http_sse_write
0000000000026cd4 T _http_status2str
000000000004ce78 s _http_status2str.status2str
00000000000266b4 T _http_time2str
0000000000056320 s _http_time2str.cached_httpdate
0000000000056600 s _http_time2str.cached_httpdate$tlv$init
0000000000056338 s _http_time2str.cached_len
0000000000056630 s _http_time2str.cached_len$tlv$init
0000000000056308 s _http_time2str.cached_tick
00000000000565f8 s _http_time2str.cached_tick$tlv$init
0000000000027fd8 T _http_upgrade2sse
0000000000026d78 T _http_upgrade2ws
0000000000056a68 b _http_upgrade_hash
00000000000290c4 t _http_urlstr2fiobj
000000000002a2d8 T _http_write_log
U _inet_ntop
0000000000041166 s _invalid_cookie_name_char
0000000000041276 s _invalid_cookie_value_char
00000000000409da s _is_hex
U _kevent
U _kill
U _kqueue
0000000000056a18 b _last_date_added
U _listen
U _malloc
U _memchr
U _memcmp
U _memcpy
U _memmove
0000000000056018 d _memory
U _mkstemp
U _mmap
0000000000013aac t _mock_on_data
0000000000013aa8 t _mock_on_ev
0000000000013b0c t _mock_on_shutdown
00000000000164c0 t _mock_on_shutdown_eternal
0000000000013b08 t _mock_ping
0000000000014ec8 t _mock_ping2
0000000000009200 t _mock_ping_eternal
U _munmap
0000000000021ac8 t _mustache__instruction_push
000000000003f45c t _mustache__instruction_push.cold.1
0000000000021294 t _mustache__load_data
000000000003f3b4 t _mustache__load_data.cold.1
000000000003f3d0 t _mustache__load_data.cold.2
0000000000021518 t _mustache__load_file
000000000003f3ec t _mustache__load_file.cold.1
00000000000218a0 t _mustache__push_text_instruction
000000000003f408 t _mustache__push_text_instruction.cold.1
000000000003f424 t _mustache__push_text_instruction.cold.2
000000000003f440 t _mustache__push_text_instruction.cold.3
0000000000040c90 s _mustache__write_escaped.html_escape_len
000000000004c4c0 s _mustache__write_escaped.html_escape_strs
000000000001fdf0 t _mustache_load
000000000003f280 t _mustache_load.cold.1
000000000003f37c t _mustache_load.cold.10
000000000003f398 t _mustache_load.cold.11
000000000003f29c t _mustache_load.cold.2
000000000003f2b8 t _mustache_load.cold.3
000000000003f2d4 t _mustache_load.cold.4
000000000003f2f0 t _mustache_load.cold.5
000000000003f30c t _mustache_load.cold.6
000000000003f328 t _mustache_load.cold.7
000000000003f344 t _mustache_load.cold.8
000000000003f360 t _mustache_load.cold.9
0000000000021b8c t _mustache_on_arg
U _nanosleep
00000000000562d8 s _num_buffer
00000000000563f8 s _num_buffer$tlv$init
000000000003a12c t _on_close
000000000003a2a8 t _on_data
000000000003a018 t _on_data_first
0000000000056908 b _on_malloc_zero
000000000003a47c t _on_ready
000000000003a094 t _on_shutdown
0000000000027abc t _on_websocket_http_connected
0000000000027b8c t _on_websocket_http_connection_finished
U _open
U _perror
U _pread
U _pthread_atfork
U _pthread_create
U _pthread_detach
U _pthread_join
U _pwrite
U _rand
U _read
U _realloc
0000000000003ba4 t _reap_child_handler
000000000003df24 t _redis_attach_cmd
000000000003e17c t _redis_connect
000000000003b690 T _redis_engine_create
000000000003d448 T _redis_engine_destroy
000000000003b300 T _redis_engine_send
000000000003e698 t _redis_forward_reply
000000000003d4d8 t _redis_free
000000000003e5d8 t _redis_on_auth
000000000003c7c4 t _redis_on_close
000000000003e274 t _redis_on_connect
000000000003e5c4 t _redis_on_connect_failed
000000000003c2f4 t _redis_on_data
000000000003d300 t _redis_on_engine_fork
000000000003d440 t _redis_on_facil_shutdown
000000000003d2a8 t _redis_on_facil_start
000000000003d138 t _redis_on_internal_cmd
000000000003d08c t _redis_on_internal_publish
000000000003d214 t _redis_on_internal_reply
000000000003e780 t _redis_on_mock_subscribe_child
000000000003e784 t _redis_on_publish_child
000000000003c184 t _redis_on_publish_root
000000000003c77c t _redis_on_shutdown
000000000003bc84 t _redis_on_subscribe_root
000000000003bd88 t _redis_on_unsubscribe_root
000000000003e62c t _redis_perform_callback
000000000003c904 t _redis_pub_ping
000000000003cbd0 t _redis_sub_ping
00000000000390d0 T _resize_ws_buffer
000000000003e048 t _resp_add_obj
000000000003c9d4 t _resp_on_pub_message
000000000003cc14 t _resp_on_sub_message
000000000002e770 t _seek2ch
U _sendfile
0000000000024c80 t _set_header_add
U _setrlimit
U _setsockopt
000000000003fe78 s _sha1_padding
000000000003feb8 s _sha2_padding
0000000000013dbc t _sig_int_handler
U _sigaction
U _snprintf
U _socket
U _sprintf
U _stat
U _strcasecmp
U _strcmp
U _strerror
00000000000408da s _string_seek_stop
U _strlen
U _strncasecmp
U _strstr
U _strtod
U _strtold
U _strtoll
0000000000056920 b _sys_alloc.next_alloc
U _sysconf
0000000000054018 d _task_queue_normal
0000000000055010 d _task_queue_urgent
U _unlink
U _vsnprintf
U _wait
U _waitpid
0000000000039138 T _websocket_attach
000000000003945c T _websocket_close
00000000000279f8 T _websocket_connect
000000000003a490 t _websocket_consume
0000000000039d60 T _websocket_is_client
0000000000039b00 t _websocket_on_pubsub_message
0000000000039bbc t _websocket_on_pubsub_message_direct
0000000000039bac t _websocket_on_pubsub_message_direct_bin
000000000003b14c t _websocket_on_pubsub_message_direct_internal
0000000000039bb4 t _websocket_on_pubsub_message_direct_txt
0000000000039bc4 t _websocket_on_unsubscribe
000000000003ac2c t _websocket_on_unwrapped
00000000000394b8 T _websocket_optimize4broadcasts
0000000000056a88 b _websocket_optimize4broadcasts.binary
0000000000056a78 b _websocket_optimize4broadcasts.generic
0000000000056a80 b _websocket_optimize4broadcasts.text
0000000000039790 t _websocket_optimize_binary
000000000003b144 t _websocket_optimize_free
0000000000039514 t _websocket_optimize_generic
0000000000039688 t _websocket_optimize_text
0000000000039898 T _websocket_subscribe
0000000000039d40 T _websocket_udata_get
0000000000039d50 T _websocket_udata_set
0000000000039c80 T _websocket_unsubscribe
0000000000039d48 T _websocket_uuid
0000000000039d68 T _websocket_write
0000000000039dc8 t _websocket_write_impl
000000000003aaa4 t _websocket_xmask
U _write
000000000002a208 t _write_header
000000000002d280 t _write_header
000000000001faf0 t _write_safe_str
000000000003a23c t _ws_ping
there's definitely something wrong with my julia program. I'll look into it
Hi @AbhimanyuAryan ,
TL;DR; : the default makefile should have a lib
rule, so make lib
should produce a shared library.
Thank you for your interest in facil.io and in porting it as a shared library to Julia.
I do not work with Julia, but I assume this could be a great project :)
FYI, the default makefile should have a lib
rule, so make lib
should produce a shared library.
At the moment I'm working on the facil.io 0.8.x version (the API is still somewhat fluid, but we're getting there). You can see the core C STL and modular library at: https://github.com/facil-io/cstl
The only integration issue I can see is that many functions are really short-hand helpers and they are actually static
and inline
functions that might not appear in the shared library code (as they are part of the C header)... such functionality might need to be ported manually to Julia or another C file could be added to make sure the functions are emitted.
I'll think about ways to solve this for version 0.8.x so integrating facil.io into other languages is made easier.
I hope this helps.
Good Luck!
FYI:
I just noticed that the Julia language documentation mentions a GitHub project for automatically creating Julia functions from C and C++ header files.
Feel free to comment here with any further suggestions / comments.
Hi @boazsegev I look at Clang.jl and it just automates the creation of binding but before that I want to make sure everything works as expected.
So, I tried the traditional approach and it worked as expected
julia> const libfacil = "./libfacil.so"
"./libfacil.so"
julia> ccall((:fio_start, libfacil), Cvoid, (Cint,), 1)
INFO: Server is running 1 worker X 1 thread with facil.io 0.7.6 (kqueue)
* Detected capacity: 131056 open file limit
* Root pid: 61044
* Press ^C to stop
but when I moved a step further with using http_listen
. I got Segmentation fault error
code
# First, define the path to the shared library
const libfacil = "./libfacil.so"
# # Then, define the C function signature in Julia
# # For example, to call the `fio_start` function:
ccall((:fio_start, libfacil), Cvoid, (Cint,), 1)
function on_request(request::Ptr{Cvoid})
ccall((:http_send_body, libfacil), Cvoid, (Ptr{Cvoid}, Cstring, Csize_t), request, "Hello World!\r\n", 14)
end
# Convert the Julia function to a C function pointer
const on_request_c = @cfunction(on_request, Cvoid, (Ptr{Cvoid},))
# Start listening on the specified port
ccall((:http_listen, libfacil), Cint, (Cstring, Ptr{Cvoid}, Ptr{Cvoid}, Cint), "3000", C_NULL, on_request_c, 1)
# Start the server
ccall((:fio_start, libfacil), Cvoid, (Cint,), 1)
error:
julia http.jl
[60734] signal (11.2): Segmentation fault: 11
in expression starting at /Users/abhi/Git/CJulia/facil/tmp/http.jl:17
_platform_strlen at /usr/lib/system/libsystem_platform.dylib (unknown line)
Allocations: 2996 (Pool: 2985; Big: 11); GC: 0
[1] 60733 segmentation fault julia http.jl
I also checked the if the library is loaded correctly or not and it seems ok too
julia> using Libdl
julia> dlopen("./libfacil.so")
Ptr{Nothing} @0x000000009a6e6190
julia> lib = dlopen("./libfacil.so")
Ptr{Nothing} @0x000000009a6e6190
julia> if lib == C_NULL
error("Failed to load libfacil.so shared library")
end
The http_listen
function expects a struct
, not a list of parameters... this might change the way the function call is made (depending on the system's conventions for function calls), not to mention that some systems might have different struct packing...
Maybe this is related to the error? Maybe (I am not sure), if a Julia C struct was used to bridge the parameters it would work...?
yes that is the error. I need to pass a Julia struct that converts to c struct
https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#Struct-Type-Correspondences
ok looks like I made some progress
# First, define the path to the shared library
const httplib = "./libfacil.so"
struct http_settings_s
on_request::Ptr{Cvoid}
log::Cint
# Add other fields as needed
end
function on_request(request::Ptr{Cvoid})
ccall((:http_send_body, httplib), Cvoid, (Ptr{Cvoid}, Cstring, Csize_t), request, "Hello World!\r\n", 14)
end
# Convert the Julia function to a C function pointer
const on_request_c = @cfunction(on_request, Cvoid, (Ptr{Cvoid},))
# Define the C struct
const settings = http_settings_s(on_request_c, 1)
println("before listen")
# Start listening on the specified port
ccall((:http_listen, httplib), Cintmax_t, (Cstring, Cstring, Ref{http_settings_s}), "3000", C_NULL, settings)
println("after listen")
# Start the server
ccall((:fio_start, httplib), Cvoid, (Cint,), 1)
println("after start")
but now it doesn't go on the next line fio_start
. Looks like http_listen is blocking
julia http.jl
before listen
FATAL: No supported SSL/TLS library available.
ok, @boazsegev ignore previous messages. Stupid me I had to just use @async
in front of http_listen
as it was a blocking process. Now it works fine in Julia ❤️💚💜
the final julia code looks like this
# First, define the path to the shared library
const httplib = "./libfacil.so"
struct http_settings_s
on_request::Ptr{Cvoid}
log::Cint
# Add other fields as needed
end
function on_request(request::Ptr{Cvoid})
ccall((:http_send_body, httplib), Cvoid, (Ptr{Cvoid}, Cstring, Csize_t), request, "Hello World!\r\n", 14)
end
# Convert the Julia function to a C function pointer
const on_request_c = @cfunction(on_request, Cvoid, (Ptr{Cvoid},))
# Define the C struct
const settings = http_settings_s(on_request_c, 1)
println("before listen")
# Start listening on the specified port
@async ccall((:http_listen, httplib), Cintmax_t, (Cstring, Cstring, Ref{http_settings_s}), "3000", C_NULL, settings)
println("after listen")
# Start the server
ccall((:fio_start, httplib), Cvoid, (Cint,), 1)
println("after start")
I will make a few more examples with ccall
and then use Clang.jl and BinaryBuilder.jl to create a wrapper. Quite complex need to understand how they work but not impossible. It will take a lot of time but the output will be excellent. A fast HTTP, WebSocket lib for Julia 🎉
NodeJS 272k requests with autocannon vs CCall facil 1107k requests
How can I compile facil into a shared library to use various functionality in Julia code? Something like this: https://github.com/AbhimanyuAryan/ccallex
I am not familiar with how
makefiles
work so that causes a lot of trouble in understandingtechnically, what I want to achieve is calling various facil functionality like starting a server, serving requests from julia ccall