/*
 * Document-method: socket
 *
 * call-seq:
 *   zmq.socket(socket_type)
 *
 * Creates a new 0MQ socket.  The socket_type argument specifies the socket
 * type, which determines the semantics of communication over the socket.
 *
 * The newly created socket is initially unbound, and not associated with any
 * endpoints. In order to establish a message flow a socket must first be
 * connected to at least one endpoint with connect(), or at least one
 * endpoint must be created for accepting incoming connections with
 * bind().
 *
 * For a description of the various socket types, see ZMQ::Socket.
 */
static VALUE context_socket (VALUE self_, VALUE type_)
{
    void * c = NULL;
    Data_Get_Struct (self_, void, c);
    void * s = zmq_socket (c, NUM2INT (type_));
    if (!s) {
        rb_raise (rb_eRuntimeError, "%s", zmq_strerror (zmq_errno ()));
        return Qnil;
    }

    return Data_Wrap_Struct(socket_type, 0, socket_free, s);
}