當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Buf.Unpack方法代碼示例

本文整理匯總了Golang中github.com/lunixbochs/usercorn/go/kernel/common.Buf.Unpack方法的典型用法代碼示例。如果您正苦於以下問題:Golang Buf.Unpack方法的具體用法?Golang Buf.Unpack怎麽用?Golang Buf.Unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/lunixbochs/usercorn/go/kernel/common.Buf的用法示例。


在下文中一共展示了Buf.Unpack方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Sendto

func (k *PosixKernel) Sendto(fd co.Fd, buf co.Buf, size co.Len, flags int, sa syscall.Sockaddr, socklen co.Len) uint64 {
	msg := make([]byte, size)
	if err := buf.Unpack(msg); err != nil {
		return UINT64_MAX // FIXME
	}
	return Errno(syscall.Sendto(int(fd), msg, flags, sa))
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:7,代碼來源:socket.go

示例2: Pwrite64

func (k *PosixKernel) Pwrite64(fd co.Fd, buf co.Buf, size co.Len, offset int64) uint64 {
	p := make([]byte, size)
	if err := buf.Unpack(p); err != nil {
		return UINT64_MAX // FIXME
	}
	n, err := syscall.Pwrite(int(fd), p, offset)
	if err != nil {
		return Errno(err)
	}
	return uint64(n)
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:11,代碼來源:io.go

示例3: Write

func (k *PosixKernel) Write(fd co.Fd, buf co.Buf, size co.Len) uint64 {
	tmp := make([]byte, size)
	if err := buf.Unpack(tmp); err != nil {
		return UINT64_MAX // FIXME
	}
	n, err := syscall.Write(int(fd), tmp)
	if err != nil {
		return Errno(err)
	}
	return uint64(n)
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:11,代碼來源:io.go

示例4: Setsockopt

func (k *PosixKernel) Setsockopt(fd co.Fd, level, opt int, valueIn co.Buf, size int) uint64 {
	// TODO: dispatch/support all setsockopt types
	if size != 4 {
		fmt.Fprintf(os.Stderr, "WARNING: unsupported Setsockopt type %d\n", size)
		return UINT64_MAX // FIXME
	}
	var value int32
	if err := valueIn.Unpack(&value); err != nil {
		return UINT64_MAX // FIXME
	}
	if err := syscall.SetsockoptInt(int(fd), level, opt, opt); err != nil {
		return Errno(err)
	}
	return 0
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:15,代碼來源:socket.go

示例5: Socketcall

func (k *LinuxKernel) Socketcall(index int, params co.Buf) uint64 {
	if name, ok := socketCallMap[index]; ok {
		if sys := co.Lookup(k.U, k, name); sys != nil {
			rawArgs := make([]uint32, len(sys.In))
			if err := params.Unpack(rawArgs); err != nil {
				return posix.UINT64_MAX
			}
			args := make([]uint64, len(rawArgs))
			for i, v := range rawArgs {
				args[i] = uint64(v)
			}
			return sys.Call(args)
		}
	}
	return posix.UINT64_MAX // FIXME
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:16,代碼來源:linux.go

示例6: Sendfile

func (k *LinuxKernel) Sendfile(out, in co.Fd, off co.Buf, count uint64) uint64 {
	// TODO: the in_fd argument must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket).
	outFile := out.File()
	inFile := in.File()
	var offset struc.Off_t
	if off.Addr != 0 {
		if err := off.Unpack(&offset); err != nil {
			return UINT64_MAX // FIXME
		}
	}
	written, err := io.CopyN(outFile, inFile, int64(count))
	// TODO: is EOF handling correct here?
	if (err != nil && err != io.EOF) || written < 0 {
		return UINT64_MAX // FIXME
	}
	return uint64(written)
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:17,代碼來源:io.go

示例7: iovecIter

func iovecIter(stream co.Buf, count uint64, bits uint) <-chan Iovec64 {
	ret := make(chan Iovec64)
	go func() {
		for i := uint64(0); i < count; i++ {
			if bits == 64 {
				var iovec Iovec64
				stream.Unpack(&iovec)
				ret <- iovec
			} else {
				var iv32 Iovec32
				stream.Unpack(&iv32)
				ret <- Iovec64{uint64(iv32.Base), uint64(iv32.Len)}
			}
		}
		close(ret)
	}()
	return ret
}
開發者ID:practicalswift,項目名稱:usercorn,代碼行數:18,代碼來源:iovec.go

示例8: Sockaddr

func Sockaddr(buf common.Buf, length int) syscall.Sockaddr {
	var port [2]byte
	order := buf.K.U.ByteOrder()
	// TODO: handle insufficient length
	var family uint16
	if err := buf.Unpack(&family); err != nil {
		return nil
	}
	// TODO: handle errors?
	st := buf.Struc()
	switch family {
	case AF_LOCAL:
		var a SockaddrUnix
		st.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_INET:
		var a SockaddrInet4
		st.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_INET6:
		var a SockaddrInet6
		st.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_PACKET:
		var a SockaddrLinklayer
		st.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_NETLINK:
		var a SockaddrNetlink
		st.Unpack(&a)
		return sockaddrToNative(&a)
	}
	return nil
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:38,代碼來源:sockaddr.go

示例9: Fdwait

func (k *CgcKernel) Fdwait(nfds int, reads, writes, timeoutBuf co.Buf, readyFds co.Obuf) int {
	var readSet, writeSet *native.Fdset32
	var timeout native.Timespec
	reads.Unpack(&readSet)
	writes.Unpack(&writeSet)
	timeoutBuf.Unpack(&timeout)

	readNative := readSet.Native()
	writeNative := writeSet.Native()

	n, err := native.Select(nfds, readNative, writeNative, &timeout)
	if err != nil {
		return -1 // FIXME?
	} else {
		readyFds.Pack(int32(n))
	}
	return 0
}
開發者ID:lunixbochs,項目名稱:usercorn,代碼行數:18,代碼來源:cgc.go

示例10: Sockaddr

func Sockaddr(buf common.Buf, length int) syscall.Sockaddr {
	var port [2]byte
	order := buf.U.ByteOrder()
	// TODO: handle insufficient length
	var family uint16
	buf.Unpack(&family)
	buf = buf.Copy()
	switch family {
	case AF_LOCAL:
		var a SockaddrUnix
		buf.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_INET:
		var a SockaddrInet4
		buf.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_INET6:
		var a SockaddrInet6
		buf.Unpack(&a)
		order.PutUint16(port[:], a.Port)
		a.Port = binary.BigEndian.Uint16(port[:])
		return sockaddrToNative(&a)
	case AF_PACKET:
		var a SockaddrLinklayer
		buf.Unpack(&a)
		return sockaddrToNative(&a)
	case AF_NETLINK:
		var a SockaddrNetlink
		buf.Unpack(&a)
		return sockaddrToNative(&a)
	}
	return nil
}
開發者ID:practicalswift,項目名稱:usercorn,代碼行數:35,代碼來源:sockaddr.go


注:本文中的github.com/lunixbochs/usercorn/go/kernel/common.Buf.Unpack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。