Esempio n. 1
0
func messageProcess(private *keys.PrivateKey, peerPublic *keys.PublicKey, message []byte, is_wrap bool) ([]byte, error) {
	if nil == message {
		return nil, errors.New("No message was provided")
	}

	var priv, pub unsafe.Pointer
	var privLen, pubLen C.size_t

	if nil != private {
		priv = unsafe.Pointer(&private.Value[0])
		privLen = C.size_t(len(private.Value))
	}

	if nil != peerPublic {
		pub = unsafe.Pointer(&peerPublic.Value[0])
		pubLen = C.size_t(len(peerPublic.Value))
	}

	var output_length C.size_t
	if !bool(C.get_message_size(priv,
		privLen,
		pub,
		pubLen,
		unsafe.Pointer(&message[0]),
		C.size_t(len(message)),
		C.bool(is_wrap),
		&output_length)) {
		return nil, errors.New("Failed to get ouput size")
	}

	output := make([]byte, int(output_length), int(output_length))
	if !bool(C.process(priv,
		privLen,
		pub,
		pubLen,
		unsafe.Pointer(&message[0]),
		C.size_t(len(message)),
		C.bool(is_wrap),
		unsafe.Pointer(&output[0]),
		output_length)) {
		return nil, errors.New("Failed to wrap message")
	}

	return output, nil
}
Esempio n. 2
0
func (ctx *context) DoWork() {
	queue := make([]call, 0, workbufLen)
	for {
		// Wait until at least one piece of work is ready.
		// Accumulate work until a piece is marked as blocking.
		select {
		case w := <-ctx.work:
			queue = append(queue, w)
		default:
			return
		}
		blocking := queue[len(queue)-1].blocking
	enqueue:
		for len(queue) < cap(queue) && !blocking {
			select {
			case w := <-ctx.work:
				queue = append(queue, w)
				blocking = queue[len(queue)-1].blocking
			default:
				break enqueue
			}
		}

		// Process the queued GL functions.
		for i, q := range queue {
			ctx.cargs[i] = q.args
			ctx.parg[i] = (*C.char)(q.parg)
		}
		ret := C.process(&ctx.cargs[0], ctx.parg[0], ctx.parg[1], ctx.parg[2], C.int(len(queue)))

		// Cleanup and signal.
		queue = queue[:0]
		if blocking {
			ctx.retvalue <- ret
		}
	}
}
Esempio n. 3
0
// DoWork performs any pending OpenGL calls.
//
// This is an internal implementation detail and should only be used by the
// github.com/c-darwin/mobile/app package.
func DoWork() {
	queue := make([]call, 0, len(work))
	for {
		// Wait until at least one piece of work is ready.
		// Accumulate work until a piece is marked as blocking.
		select {
		case w := <-work:
			queue = append(queue, w)
		default:
			return
		}
		blocking := queue[len(queue)-1].blocking
	enqueue:
		for len(queue) < cap(queue) && !blocking {
			select {
			case w := <-work:
				queue = append(queue, w)
				blocking = queue[len(queue)-1].blocking
			default:
				break enqueue
			}
		}

		// Process the queued GL functions.
		for i, q := range queue {
			C.cargs[i] = q.args
		}
		C.process(C.int(len(queue)))

		// Cleanup and signal.
		queue = queue[:0]
		if blocking {
			retvalue <- C.ret
		}
	}
}