msantos / procket

Erlang interface to low level socket operations
http://blog.listincomprehension.com/search/label/procket
BSD 3-Clause "New" or "Revised" License
283 stars 80 forks source link

Add set sock o_nonblock nif #48

Closed colrack closed 3 years ago

colrack commented 3 years ago

This PR add a nif to set a socket non blocking.

I'm using procket in combination with erlang:open_port/2 and erlang:port_close/1. I'm polling the socket like here https://github.com/msantos/inert#busy-waiting but instead of sleep and spin again on {error, eagain} I pass in active mode with erlang:open_port/2 and then after receiving a pkt I switch back to passive mode with erlang:port_close/1. The problem is that when you use port_close the socket is set as BLOCKING and a call to procket:read/2 blocks until new data arrive.