// Configure accepts a port number and configures // the beacon, returning an address func (b *Beacon) Configure(port int) (string, error) { rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), C.CString("CONFIGURE")) if rc == -1 { return "", ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), C.CString(strconv.Itoa(port))) if rc == -1 { return "", ErrActorCmd } Chostname := C.zstr_recv(unsafe.Pointer(b.zactorT)) hostname := C.GoString(Chostname) return hostname, nil }
// Configure accepts a port number and configures // the beacon, returning an address func (b *Beacon) Configure(port int) (string, error) { cmd := C.CString("CONFIGURE") defer C.free(unsafe.Pointer(cmd)) cPort := C.CString(strconv.Itoa(port)) defer C.free(unsafe.Pointer(cPort)) rc := C.zstr_sendm(unsafe.Pointer(b.zactorT), cmd) if rc == -1 { return "", ErrActorCmd } rc = C.zstr_send(unsafe.Pointer(b.zactorT), cPort) if rc == -1 { return "", ErrActorCmd } cHostname := C.zstr_recv(unsafe.Pointer(b.zactorT)) hostname := C.GoString(cHostname) return hostname, nil }
// Recv waits for the specific timeout in milliseconds to receive a beacon func (b *Beacon) Recv(timeout int) [][]byte { C.zsock_set_rcvtimeo(unsafe.Pointer(b.zactorT), C.int(timeout)) addrStr := C.zstr_recv(unsafe.Pointer(b.zactorT)) beaconStr := C.zstr_recv(unsafe.Pointer(b.zactorT)) return [][]byte{[]byte(C.GoString(addrStr)), []byte(C.GoString(beaconStr))} }
// Recv waits for the specific timeout in milliseconds to receive a beacon func (b *Beacon) Recv(timeout int) string { C.zsock_set_rcvtimeo(unsafe.Pointer(b.zactorT), C.int(timeout)) msg := C.zstr_recv(unsafe.Pointer(b.zactorT)) return C.GoString(msg) }