Skip to content

Commit 3c4a907

Browse files
committed
Add "dirty NIF" flags to IO calls
1 parent 6864fec commit 3c4a907

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

native/libp2p_nif/libp2p.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
_handle; \
2828
})
2929

30-
#define NIF_ENTRY(FUNCTION_NAME, ARITY) \
31-
{ \
32-
#FUNCTION_NAME, ARITY, FUNCTION_NAME \
30+
#define NIF_ENTRY(FUNCTION_NAME, ARITY, ...) \
31+
{ \
32+
#FUNCTION_NAME, ARITY, FUNCTION_NAME, __VA_ARGS__ \
3333
}
3434

3535
const uint64_t BUFFER_SIZE = 4096;
@@ -276,13 +276,14 @@ static ErlNifFunc nif_funcs[] = {
276276
NIF_ENTRY(host_new, 1),
277277
NIF_ENTRY(host_close, 1),
278278
NIF_ENTRY(host_set_stream_handler, 2),
279-
NIF_ENTRY(host_new_stream, 3),
279+
// TODO: check if host_new_stream is truly dirty
280+
NIF_ENTRY(host_new_stream, 3, ERL_NIF_DIRTY_JOB_IO_BOUND), // blocks negotiating protocol
280281
NIF_ENTRY(host_peerstore, 1),
281282
NIF_ENTRY(host_id, 1),
282283
NIF_ENTRY(host_addrs, 1),
283284
NIF_ENTRY(peerstore_add_addrs, 4),
284-
NIF_ENTRY(stream_read, 1),
285-
NIF_ENTRY(stream_write, 2),
285+
NIF_ENTRY(stream_read, 1, ERL_NIF_DIRTY_JOB_IO_BOUND), // blocks until reading
286+
NIF_ENTRY(stream_write, 2, ERL_NIF_DIRTY_JOB_IO_BOUND), // blocks when buffer is full
286287
NIF_ENTRY(stream_close, 1),
287288
};
288289

0 commit comments

Comments
 (0)