Пример #1
0
func (h *TPacket) pollForFirstPacket(hdr header) error {
	for hdr.getStatus()&C.TP_STATUS_USER == 0 {
		h.pollset.fd = h.fd
		h.pollset.events = C.POLLIN
		h.pollset.revents = 0
		_, err := C.poll(&h.pollset, 1, -1)
		h.stats.Polls++
		if err != nil {
			return err
		}
	}
	h.shouldReleasePacket = true
	return nil
}
Пример #2
0
func (h *TPacket) pollForFirstPacket(hdr header) error {
	for hdr.getStatus()&C.TP_STATUS_USER == 0 {
		h.pollset.fd = h.fd
		h.pollset.events = C.POLLIN
		h.pollset.revents = 0
		timeout := C.int(h.opts.timeout / time.Millisecond)
		_, err := C.poll(&h.pollset, 1, timeout)
		h.stats.Polls++
		if err != nil {
			return err
		}
	}
	h.shouldReleasePacket = true
	return nil
}
// Read the specified number of bytes from the input stream or die trying.
func mustRead(in io.ReadCloser, bytes []byte) int {
	var offset = 0
	pollfd := &C.pollfd{
		fd:      C.int(in.(*os.File).Fd()),
		events:  C.POLLIN,
		revents: 0,
	}

	for offset < len(bytes) {
		rc := C.poll(pollfd, 1, -1)
		switch rc {
		case 0, 1:
			break
		default:
			log.Fatalf("Poll failed with rc = %d", rc)
		}
		n, err := in.Read(bytes[offset:])
		offset += n
		if err != nil {
			log.Fatalf("Unexpected error while reading %d bytes from input: %v", len(bytes), err)
		}
	}
	return len(bytes)
}