[zeromq-dev] 0MQ 3.0 - API improvements
Pieter Hintjens
ph at imatix.com
Fri Apr 8 09:35:35 CEST 2011
On Fri, Apr 8, 2011 at 8:19 AM, Martin Sustrik <sustrik at 250bpm.com> wrote:
> The use case being accidentally passing context handle to a socket, right?
>
> I don't know. In the ideal, fully POSIX-compliant world, the sockets would
> be identified by ints, which are not type-safe either.
>
> Maybe a cleaner way would be to put few hard-wired bytes at the beginning of
> the socket structure and check those in each function, returning EFAULT if
> it does not match.
The use case is not accidentally passing a context handle to a socket,
no. The use case is accidentally passing other structures to zmq
methods, which since they take void * arguments, don't catch such
errors at compile time. Adding some magic bytes and checking them
would work at runtime but it's a real hack.
Sockets, as ints, *are* typesafe. I can't pass a random pointer
to recv(), it does not compile.
Is there any specific reason for not wanting to use proper types for
these? The use of void * seems to go against all best practice in C.
I'm not sure it makes sense in C++ either.
-Pieter
More information about the zeromq-dev
mailing list