Exemple #1
0
func (s *Socket) SockOptInt(level, option C.int) (int, error) {
	var value C.int
	length := C.size_t(unsafe.Sizeof(value))
	rc, err := C.nn_getsockopt(s.socket, level, option, unsafe.Pointer(&value), &length)
	if rc != 0 {
		err = nnError(err)
		return int(value), err
	}
	return int(value), nil
}
Exemple #2
0
// SockOptString returns the value of the option as string.
func (s *Socket) SockOptString(level, option C.int, maxSize int) (string, error) {
	size := C.size_t(maxSize) + 1
	cval := (*C.char)(C.malloc(size))
	if cval == nil {
		return "", errors.New("nanomsg: failed to allocate socket string buffer")
	}
	defer C.free(unsafe.Pointer(cval))

	rc, err := C.nn_getsockopt(s.socket, level, option, unsafe.Pointer(cval), &size)
	if rc != 0 {
		err = nnError(err)
		return "", err
	}

	value := C.GoStringN(cval, C.int(size))
	return value, nil
}