Exemplo n.º 1
0
func NewNode(timeout time.Duration) (node *Node) {
	logger := C.log_create(C.DNET_LOG_DEBUG)

	config := C.struct_dnet_config{family: C.AF_INET, wait_timeout: C.uint(timeout.Seconds())}
	config.log = &logger

	node = &Node{config: config}
	node.node = C.dnet_node_create(&node.config)

	return
}
Exemplo n.º 2
0
// NewNode returns new Node with a given Logger.
func NewNodeConfig(logfile string, level string, cfg *NodeConfig) (node *Node, err error) {
	clevel := C.CString(level)
	defer C.free(unsafe.Pointer(clevel))

	clogfile := C.CString(logfile)
	defer C.free(unsafe.Pointer(clogfile))

	var dcfg C.struct_dnet_config
	C.memset(unsafe.Pointer(&dcfg), 0, C.sizeof_struct_dnet_config)

	dcfg.io_thread_num = C.int(cfg.IOThreadNum)
	dcfg.nonblocking_io_thread_num = C.int(cfg.NonBlockingIOThreadNum)
	dcfg.net_thread_num = C.int(cfg.NetThreadNum)
	dcfg.wait_timeout = C.long(cfg.WaitTimeout)
	dcfg.check_timeout = C.long(cfg.CheckTimeout)
	dcfg.flags = C.int(cfg.Flags)
	dcfg.stall_count = C.long(cfg.StallCount)

	cnode := C.new_node_config(clogfile, clevel, &dcfg)
	if cnode == nil {
		err = fmt.Errorf("could not create node, please check stderr output")
		return
	}
	node = &Node{cnode}
	return
}