# Is http\_listen blocking further call execution in my ccall program

**URL:** <https://discourse.julialang.org/t/is-http-listen-blocking-further-call-execution-in-my-ccall-program/99542>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 29, 2023, 7:49am UTC](https://discourse.julialang.org/t/is-http-listen-blocking-further-call-execution-in-my-ccall-program/99542 "2023-05-29T07:49:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AbhimanyuAryan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhimanyuaryan/32/15733_2.png) [@AbhimanyuAryan](https://discourse.julialang.org/u/AbhimanyuAryan)\
**Post date:** [May 29, 2023, 7:49am UTC](https://discourse.julialang.org/t/is-http-listen-blocking-further-call-execution-in-my-ccall-program/99542/1 "2023-05-29T07:49:36Z")

</div>

Given the C Code

```plaintext
#include "http.h"

void on_request(http_s *request);

FIOBJ HTTP_HEADER_X_DATA;

int main(void) {
  HTTP_HEADER_X_DATA = fiobj_str_new("X-Data", 6);
  http_listen("3000", NULL, .on_request = on_request, .log = 1);
  fio_start(.threads = 1);
  fiobj_free(HTTP_HEADER_X_DATA);
}

void on_request(http_s *request) {
  http_set_cookie(request, .name = "my_cookie", .name_len = 9, .value = "data",
                  .value_len = 4);
  http_set_header(request, HTTP_HEADER_CONTENT_TYPE,
                  http_mimetype_find("txt", 3));
  http_set_header(request, HTTP_HEADER_X_DATA, fiobj_str_new("my data", 7));
  http_send_body(request, "Hello World!\r\n", 14);
}

```

I wrote it’s Julia’s ccall counterpart

```julia
# First, define the path to the shared library
const httplib = "./libf.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")

```

and I get the output

```julia
julia http.jl
before listen
FATAL: No supported SSL/TLS library available.

```

the output of

```julia
# Start the server
ccall((:fio_start, httplib), Cvoid, (Cint,), 1)

```

looks like

```julia
❯ julia http.jl 
INFO: Server is running 1 worker X 1 thread with server 0.7.6 (kqueue)
* Detected capacity: 131056 open file limit
* Root pid: 72503
* Press ^C to stop

```

---

<div class="post-metadata">

**Author:** ![AbhimanyuAryan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhimanyuaryan/32/15733_2.png) [@AbhimanyuAryan](https://discourse.julialang.org/u/AbhimanyuAryan)\
**Post date:** [May 29, 2023, 7:57am UTC](https://discourse.julialang.org/t/is-http-listen-blocking-further-call-execution-in-my-ccall-program/99542/2 "2023-05-29T07:57:05Z")

</div>

> [@AbhimanyuAryan](#):
>
> `worker`

signature of various methods

```julia
intptr_t http_listen(const char *port, const char *binding,
                     struct http_settings_s);
/** Listens to HTTP connections at the specified `port` and `binding`. */

```

http\_settings\_s struct

```julia
struct http_settings_s {
  void (*on_request)(http_s *request);
  void (*on_upgrade)(http_s *request, char *requested_protocol, size_t len);
  void (*on_response)(http_s *response);
  void (*on_finish)(struct http_settings_s *settings);
  void *udata;
  const char *public_folder;
  size_t public_folder_length;
  size_t max_header_size;
  size_t max_body_size;
  intptr_t max_clients;
  void *tls;
  intptr_t reserved1;
  intptr_t reserved2;
  intptr_t reserved3;
  size_t ws_max_msg_size;
  uint8_t timeout;
  uint8_t ws_timeout;
  uint8_t log;
  uint8_t is_client;
};

```

```julia
int http_send_body(http_s *h, void *data, uintptr_t length);

```

---

<div class="post-metadata">

**Author:** ![AbhimanyuAryan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhimanyuaryan/32/15733_2.png) [@AbhimanyuAryan](https://discourse.julialang.org/u/AbhimanyuAryan)\
**Post date:** [May 29, 2023, 8:46pm UTC](https://discourse.julialang.org/t/is-http-listen-blocking-further-call-execution-in-my-ccall-program/99542/3 "2023-05-29T20:46:12Z")

</div>

this is resolved had to just use @async in front of http\_listen
