[erlang-questions] Detecting connection from a node using an invalid cookie with ei_connect

Andrew Thompson <>
Sat Nov 1 00:03:05 CET 2008


I've been playing with the ei library for the last few days and I've
managed to use it to put together a threaded c node where the ei_accept
is in the main thread and each node that connects has its messages
processed in a new thread. This all worked fine until I accidentally
connected from a node where the cookie was set wrong. Doing this makes
ei_accept return -1 (ERL_ERROR) and set erl_errno to EIO. From what I
can see, there's no way to distinguish a socket error from a node
version mismatch or a cookie challenge failure.

It seems like the easiest way would be to add some more error constants
to ei.h like ERL_BADCOOKIE and ERL_BADVERSION and return those in the
cases that ei_accept fails due to non timeout/IO reasons. Of course, any
better suggestions are welcome. I'm not too eager to make my code
dependant on a locally patched version of ei. erl_errno only seems to
ever be set to POSIX error codes, so changing what that's set to looks
to be a no-no.

Also, I noticed that erl_errno doesn't work (fails with undefined
reference to __erl_errno) on FreeBSD 6.3 unless I use the compiler flag
-D_REENTRANT. I saw a couple similar error reports when googling, but no
resolution.

Andrew



More information about the erlang-questions mailing list