示例#1
0
文件: zmq.go 项目: badgerodon/zmq
//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
}
示例#2
0
文件: zmq.go 项目: pakohan/go-zmq
// 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
}
示例#3
0
文件: zmq.go 项目: psilva261/gozmq
// 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()
}
示例#4
0
文件: zmq2.go 项目: patrickToca/zmq2
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())
	}
}
示例#5
0
文件: zmq.go 项目: 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)
}
示例#6
0
文件: zmq.go 项目: 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
}
示例#7
0
文件: zmq2.go 项目: patrickToca/zmq2
/*
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
}
示例#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
}
示例#9
0
文件: zmq2.go 项目: carosio/chello
// 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
}
示例#10
0
文件: zmq2.go 项目: carosio/chello
/*
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
}
示例#11
0
文件: zmq.go 项目: 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
}
示例#12
0
文件: zmq2.go 项目: carosio/chello
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))
	}
}
示例#13
0
文件: zmq_2_x.go 项目: ajanicij/gozmq
func createZmqContext() unsafe.Pointer {
	return C.zmq_init(1)
}