Example #1
0
//func GetSocketOption(socket *Socket,
func Init(io_threads int) (ZContext, os.Error) {
	ptr := C.zmq_init(C.int(io_threads))
	if ptr == nil {
		return ZContext{nil}, error()
	}
	return ZContext{ptr}, nil
}
Example #2
0
// Creates a new Context with the given number of dedicated IO threads.
func NewContextThreads(nthreads int) (ctx *Context, err error) {
	ptr := C.zmq_init(C.int(nthreads))
	if ptr == nil {
		return nil, zmqerr()
	}
	return &Context{ptr}, nil
}
Example #3
0
// Create a new context.
// void *zmq_init (int io_threads);
func NewContext() (Context, error) {
	// TODO Pass something useful here. Number of cores?
	// C.NULL is correct but causes a runtime failure on darwin at present
	if c := C.zmq_init(1); c != nil /*C.NULL*/ {
		return &zmqContext{c}, nil
	}
	return nil, errno()
}
Example #4
0
func init() {
	var err error
	nr_of_threads = 1
	ctx, err = C.zmq_init(C.int(nr_of_threads))
	if ctx == nil {
		panic("Init of ZeroMQ context failed: " + errget(err).Error())
	}
}
Example #5
0
File: zmq.go Project: brunoqc/gozmq
// Create a new context.
// void *zmq_init (int io_threads);
func NewContext() (*Context, error) {
	// TODO Pass something useful here. Number of cores?
	c, err := C.zmq_init(1)
	// C.NULL is correct but causes a runtime failure on darwin at present
	if c != nil /*C.NULL*/ {
		return &Context{c}, nil
	}
	return nil, casterr(err)
}
Example #6
0
File: zmq.go Project: miffa/gozero
// Creates a zmq context and returns it.
//
// Don't forget to set EnvGOMAXPROCS appropriately when working with libzmq
//
// Contexts are finalized by the GC unless they are manually destructed
// by calling Terminate() beforehand.  Applications need to arrange
// that no socket is used or even closed after the owning context has
// been destructed.  This requires to have at least one running go routine
// with a live referene to the context.
func (p libZmqProvider) NewContext(args InitArgs) (Context, os.Error) {
	contextPtr := C.zmq_init(C.int(args.IoThreads))

	if IsCNullPtr(uintptr(contextPtr)) {
		return nil, p.GetError()
	}

	lzmqContext := lzmqContext(contextPtr)
	return lzmqContext, nil
}
Example #7
0
/*
This function specifies the size of the ØMQ thread pool to handle I/O operations.
If your application is using only the inproc transport for messaging you may set
this to zero, otherwise set it to at least one.

This function creates a new context without closing the old one. Use it before
creating any sockets.

Default value   1
*/
func SetIoThreads(n int) error {
	if n != nr_of_threads {
		c, err := C.zmq_init(C.int(n))
		if c == nil {
			return errget(err)
		}
		nr_of_threads = n
		ctx = c
	}
	return nil
}
Example #8
0
/*
This function specifies the size of the ØMQ thread pool to handle I/O operations.
If your application is using only the inproc transport for messaging you may set
this to zero, otherwise set it to at least one.

This function creates a new context without closing the old one. Use it before
creating any sockets.

Default value   1
*/
func SetIoThreads(n int) error {
	if n != nr_of_threads {
		c, err := C.zmq_init(C.int(n))
		if c == nil {
			return errget(err)
		}
		old = append(old, ctx) // keep a reference, to prevent garbage collection
		ctx = c
		nr_of_threads = n
	}
	return nil
}
Example #9
0
// Create a new context.
//
// The argument specifies the size of the ØMQ thread pool to handle I/O operations.
// If your application is using only the inproc transport for messaging you may set
// this to zero, otherwise set it to at least one.
func NewContext(nr_of_threads int) (ctx *Context, err error) {
	ctx = &Context{}
	c, e := C.zmq_init(C.int(nr_of_threads))
	if c == nil {
		err = errget(e)
		ctx.err = err
	} else {
		ctx.ctx = c
		ctx.opened = true
		ctx.nr_of_threads = nr_of_threads
		runtime.SetFinalizer(ctx, (*Context).Term)
	}
	return
}
Example #10
0
/*
This function specifies the size of the ØMQ thread pool to handle I/O operations.
If your application is using only the inproc transport for messaging you may set
this to zero, otherwise set it to at least one.

This function creates a new default context without closing the old one.
Use it before creating any sockets.

Default value: 1
*/
func SetIoThreads(n int) error {
	if n != nr_of_threads {
		c, err := C.zmq_init(C.int(n))
		if c == nil {
			return errget(err)
		}
		old = append(old, defaultCtx) // keep a reference, to prevent garbage collection
		defaultCtx = &Context{
			ctx:    c,
			opened: true,
		}
		nr_of_threads = n
	}
	return nil
}
Example #11
0
File: zmq.go Project: quenel/gozmq
// Create a new context.
func NewContext() (*Context, error) {
	c := &Context{iothreads: 1}
	c.init = func() {
		c.mutex.Lock()
		defer c.mutex.Unlock()
		if c.c == nil && c.err == nil {
			// C.NULL is correct but causes a runtime failure on darwin at present
			if ptr, err := C.zmq_init(C.int(c.iothreads)); ptr != nil /*C.NULL*/ {
				c.c = ptr
			} else {
				c.err = casterr(err)
			}
		}
	}
	return c, nil
}
Example #12
0
func init() {
	var err error
	nr_of_threads = 1
	defaultCtx = &Context{}
	defaultCtx.ctx, err = C.zmq_init(C.int(nr_of_threads))
	defaultCtx.opened = true
	if defaultCtx.ctx == nil {
		panic("Init of ZeroMQ context failed: " + errget(err).Error())
	}
	old = make([]*Context, 0)
	major, minor, patch = Version()
	if major != 2 {
		panic("Using zmq2 with ZeroMQ major version " + fmt.Sprint(major))
	}
	if major != int(C.zmq2_major) || minor != int(C.zmq2_minor) || patch != int(C.zmq2_patch) {
		panic(
			fmt.Sprintf(
				"zmq2 was installed with ZeroMQ version %d.%d.%d, but the application links with version %d.%d.%d",
				int(C.zmq2_major), int(C.zmq2_minor), int(C.zmq2_patch),
				major, minor, patch))
	}
}
Example #13
0
func createZmqContext() unsafe.Pointer {
	return C.zmq_init(1)
}