Ejemplo n.º 1
0
func (z *zeroconf) restartAndQuit() {
	for {
		select {
		case <-z.restart:
			glog.Warning("Avahi client failed. Make sure that avahi-daemon is running while I restart the client.")

			C.stopAvahiClient(z.threadedPoll, z.client)

			var errstr *C.char
			C.startAvahiClient(&z.threadedPoll, &z.client, &errstr)
			if errstr != nil {
				err := errors.New(C.GoString(errstr))
				C.free(unsafe.Pointer(errstr))
				glog.Errorf("Failed to restart Avahi client: %s", err)
			}

		case <-z.q:
			for name := range z.printers {
				z.removePrinter(name)
			}
			C.stopAvahiClient(z.threadedPoll, z.client)
			close(z.q)
			return
		}
	}
}
Ejemplo n.º 2
0
func newZeroconf() (*zeroconf, error) {
	z := zeroconf{
		state:    C.AVAHI_CLIENT_CONNECTING,
		printers: make(map[string]record),
		restart:  make(chan struct{}),
		q:        make(chan struct{}),
	}
	instance = &z

	if errstr := C.startAvahiClient(&z.threadedPoll, &z.client); errstr != nil {
		err := fmt.Errorf("Failed to start Avahi client: %s", C.GoString(errstr))
		return nil, err
	}

	go z.restartAndQuit()

	return &z, nil
}
Ejemplo n.º 3
0
func newZeroconf() (*zeroconf, error) {
	z := zeroconf{
		state:    C.AVAHI_CLIENT_CONNECTING,
		printers: make(map[string]record),
		restart:  make(chan struct{}),
		q:        make(chan struct{}),
	}
	instance = &z

	var errstr *C.char
	C.startAvahiClient(&z.threadedPoll, &z.client, &errstr)
	if errstr != nil {
		err := errors.New(C.GoString(errstr))
		C.free(unsafe.Pointer(errstr))
		return nil, err
	}

	go z.restartAndQuit()

	return &z, nil
}