コード例 #1
0
ファイル: nflog.go プロジェクト: ncw/go-nflog-acctd
// Receive packets in a loop until quit
func (nflog *NfLog) Loop() {
	buflen := C.size_t(RecvBufferSize)
	pbuf := C.malloc(buflen)
	if pbuf == nil {
		log.Fatal("No memory for malloc")
	}
	defer C.free(pbuf)
	for {
		nr, err := C.recv(nflog.fd, pbuf, buflen, 0)
		select {
		case <-nflog.quit:
			return
		default:
		}
		if nr < 0 || err != nil {
			log.Printf("Recv failed: %s", err)
			nflog.errors++
		} else {
			// Handle messages in packet reusing memory
			ps := <-nflog.a.returnAddPackets
			nflog.packets.index = 0
			C.nflog_handle_packet(nflog.h, (*C.char)(pbuf), (C.int)(nr))
			nflog.a.processAddPackets <- nflog.processPackets(ps[:0])
		}
	}

}
コード例 #2
0
ファイル: nflog.go プロジェクト: andrewpwade/go-nflog-acctd
// Receive packets in a loop until quit
func (nflog *NfLog) Loop() {
	buf := make([]byte, RecvBufferSize)
	pbuf := unsafe.Pointer(&buf[0])
	buflen := C.size_t(len(buf))
	for !nflog.quit {
		nr := C.recv(nflog.fd, pbuf, buflen, 0)
		if nr < 0 {
			log.Printf("Recvfrom failed: %s", strerror())
			nflog.errors++
		} else {
			// Handle messages in packet reusing memory
			ps := <-nflog.a.returnAddPackets
			nflog.addPackets = ps[:0]
			C.nflog_handle_packet(nflog.h, (*C.char)(pbuf), (C.int)(nr))
			nflog.a.processAddPackets <- nflog.addPackets
			nflog.addPackets = nil
		}
	}

}
コード例 #3
0
ファイル: seq_android.go プロジェクト: Luci4r/mobile
// transact calls a method on a Java object instance.
// It blocks until the call is complete.
func transact(ref *seq.Ref, _ string, code int, inBuf *seq.Buffer) *seq.Buffer {
	var (
		out    *C.uint8_t = nil
		outLen C.size_t   = 0
		in     *C.uint8_t = nil
		inLen  C.size_t   = 0
	)

	if len(inBuf.Data) > 0 {
		in = (*C.uint8_t)(unsafe.Pointer(&inBuf.Data[0]))
		inLen = C.size_t(len(inBuf.Data))
	}

	C.recv(C.int32_t(ref.Num), C.int(code), in, inLen, &out, &outLen)
	if outLen > 0 {
		outBuf := &seq.Buffer{
			Data: make([]byte, outLen),
		}
		copy(outBuf.Data, (*[maxSliceLen]byte)(unsafe.Pointer(out))[:outLen])
		return outBuf
	}
	return nil
}