erl nif is not preemptive, so c lib which call net io is not suitable to wrapped as nif. use port is a optional way, but how a port command could be effictive. use coroutine and  nonblock IO is a good way, this project is a example of how to implement it.