本文整理匯總了Golang中syscall.Errno函數的典型用法代碼示例。如果您正苦於以下問題:Golang Errno函數的具體用法?Golang Errno怎麽用?Golang Errno使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Errno函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Tcsetpgrp
func Tcsetpgrp(fd int, pid int) error {
i := syscall.Errno(C.f(C.int(fd), C.pid_t(pid)))
if i != 0 {
return syscall.Errno(i)
}
return nil
}
示例2: Run
func (s *resultSrv) Run() {
var o *syscall.Overlapped
var key uint32
var r ioResult
for {
r.err = syscall.GetQueuedCompletionStatus(s.iocp, &(r.qty), &key, &o, 0)
if r.err == syscall.Errno(syscall.WAIT_TIMEOUT) && o == nil {
runtime_blockingSyscallHint()
r.err = syscall.GetQueuedCompletionStatus(s.iocp, &(r.qty), &key, &o, syscall.INFINITE)
}
switch {
case r.err == nil:
// Dequeued successfully completed IO packet.
case r.err == syscall.Errno(syscall.WAIT_TIMEOUT) && o == nil:
// Wait has timed out (should not happen now, but might be used in the future).
panic("GetQueuedCompletionStatus timed out")
case o == nil:
// Failed to dequeue anything -> report the error.
panic("GetQueuedCompletionStatus failed " + r.err.Error())
default:
// Dequeued failed IO packet.
}
(*anOp)(unsafe.Pointer(o)).resultc <- r
}
}
示例3: GetsockoptInt
// GetsockoptInt wraps syscall.GetsockoptInt.
func (sw *Switch) GetsockoptInt(s, level, opt int) (soerr int, err error) {
so := sw.sockso(s)
if so == nil {
return syscall.GetsockoptInt(s, level, opt)
}
sw.fmu.RLock()
f, _ := sw.fltab[FilterGetsockoptInt]
sw.fmu.RUnlock()
af, err := f.apply(so)
if err != nil {
return -1, err
}
soerr, so.Err = syscall.GetsockoptInt(s, level, opt)
so.SocketErr = syscall.Errno(soerr)
if err = af.apply(so); err != nil {
return -1, err
}
if so.Err != nil {
return -1, so.Err
}
if opt == syscall.SO_ERROR && (so.SocketErr == syscall.Errno(0) || so.SocketErr == syscall.EISCONN) {
sw.smu.Lock()
sw.stats.getLocked(so.Cookie).Connected++
sw.smu.Unlock()
}
return soerr, nil
}
示例4: TestIsError
func TestIsError(t *testing.T) {
if !IsErrorTemporary(ErrTimeout) {
t.Fatal("ErrTimeout not temporary!")
}
if !IsErrorTimeout(ErrTimeout) {
t.Fatal("ErrTimeout not timeout!")
}
if !IsErrorTemporary(syscall.Errno(syscall.EINTR)) {
t.Fatal("EINTR not temporary!")
}
if IsErrorTimeout(syscall.Errno(syscall.EINTR)) {
t.Fatal("EINTR is timeout!")
}
if IsErrorTemporary(ErrClosing) {
t.Fatal("ErrClosing is temporary!")
}
if IsErrorTimeout(ErrClosing) {
t.Fatal("ErrClosing is timeout!")
}
if IsErrorTemporary(syscall.Errno(syscall.EFAULT)) {
t.Fatal("EFAULT is temporary!")
}
if IsErrorTimeout(syscall.Errno(syscall.EFAULT)) {
t.Fatal("EFAULT is timeout!")
}
}
示例5: addRuleWrapper
// DOES NOT LOCK OR CHECK VALIDITY
// Assumes caller has already done this
// Wrapper for seccomp_rule_add_... functions
func (f *ScmpFilter) addRuleWrapper(call ScmpSyscall, action ScmpAction, exact bool, cond C.scmp_cast_t) error {
var length C.uint
if cond != nil {
length = 1
} else {
length = 0
}
var retCode C.int
if exact {
retCode = C.seccomp_rule_add_exact_array(f.filterCtx, action.toNative(), C.int(call), length, cond)
} else {
retCode = C.seccomp_rule_add_array(f.filterCtx, action.toNative(), C.int(call), length, cond)
}
if syscall.Errno(-1*retCode) == syscall.EFAULT {
return fmt.Errorf("unrecognized syscall")
} else if syscall.Errno(-1*retCode) == syscall.EPERM {
return fmt.Errorf("requested action matches default action of filter")
} else if retCode != 0 {
return syscall.Errno(-1 * retCode)
}
return nil
}
示例6: MsglvlSet
// MsglvlSet returns the read-msglvl, post-set-msglvl of the given interface.
func (e *Ethtool) MsglvlSet(intf string, valset uint32) (uint32, uint32, error) {
edata := ethtoolValue{
cmd: ETHTOOL_GMSGLVL,
}
var name [IFNAMSIZ]byte
copy(name[:], []byte(intf))
ifr := ifreq{
ifr_name: name,
ifr_data: uintptr(unsafe.Pointer(&edata)),
}
_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(e.fd),
SIOCETHTOOL, uintptr(unsafe.Pointer(&ifr)))
if ep != 0 {
return 0, 0, syscall.Errno(ep)
}
readval := edata.data
edata.cmd = ETHTOOL_SMSGLVL
edata.data = valset
_, _, ep = syscall.Syscall(syscall.SYS_IOCTL, uintptr(e.fd),
SIOCETHTOOL, uintptr(unsafe.Pointer(&ifr)))
if ep != 0 {
return 0, 0, syscall.Errno(ep)
}
return readval, edata.data, nil
}
示例7: connect
func (fd *netFD) connect(la, ra syscall.Sockaddr, deadline time.Time) error {
// Do not need to call fd.writeLock here,
// because fd is not yet accessible to user,
// so no concurrent operations are possible.
switch err := connectFunc(fd.sysfd, ra); err {
case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR:
case nil, syscall.EISCONN:
if !deadline.IsZero() && deadline.Before(time.Now()) {
return errTimeout
}
if err := fd.init(); err != nil {
return err
}
return nil
case syscall.EINVAL:
// On Solaris we can see EINVAL if the socket has
// already been accepted and closed by the server.
// Treat this as a successful connection--writes to
// the socket will see EOF. For details and a test
// case in C see https://golang.org/issue/6828.
if runtime.GOOS == "solaris" {
return nil
}
fallthrough
default:
return os.NewSyscallError("connect", err)
}
if err := fd.init(); err != nil {
return err
}
if !deadline.IsZero() {
fd.setWriteDeadline(deadline)
defer fd.setWriteDeadline(noDeadline)
}
for {
// Performing multiple connect system calls on a
// non-blocking socket under Unix variants does not
// necessarily result in earlier errors being
// returned. Instead, once runtime-integrated network
// poller tells us that the socket is ready, get the
// SO_ERROR socket option to see if the connection
// succeeded or failed. See issue 7474 for further
// details.
if err := fd.pd.WaitWrite(); err != nil {
return err
}
nerr, err := getsockoptIntFunc(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_ERROR)
if err != nil {
return os.NewSyscallError("getsockopt", err)
}
switch err := syscall.Errno(nerr); err {
case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR:
case syscall.Errno(0), syscall.EISCONN:
return nil
default:
return os.NewSyscallError("getsockopt", err)
}
}
}
示例8: lookup
func lookup(gid int, groupname string, lookupByName bool) (*Group, error) {
var (
grp C.struct_group
result *C.struct_group
)
var bufSize C.long
if runtime.GOOS == "freebsd" {
// FreeBSD doesn't have _SC_GETPW_R_SIZE_MAX
// and just returns -1. So just use the same
// size that Linux returns
bufSize = 1024
} else {
bufSize = C.sysconf(C._SC_GETPW_R_SIZE_MAX)
if bufSize <= 0 || bufSize > 1<<20 {
return nil, fmt.Errorf(
"user: unreasonable _SC_GETPW_R_SIZE_MAX of %d", bufSize)
}
}
buf := C.malloc(C.size_t(bufSize))
defer C.free(buf)
var rv C.int
if lookupByName {
nameC := C.CString(groupname)
defer C.free(unsafe.Pointer(nameC))
rv = C.getgrnam_r(nameC,
&grp,
(*C.char)(buf),
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf(
"group: lookup groupname %s: %s", groupname, syscall.Errno(rv))
}
if result == nil {
return nil, UnknownGroupError(groupname)
}
} else {
rv = C.mygetgrgid_r(C.int(gid),
&grp,
(*C.char)(buf),
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf("group: lookup groupid %d: %s", gid, syscall.Errno(rv))
}
if result == nil {
return nil, UnknownGroupIdError(gid)
}
}
g := &Group{
Gid: strconv.Itoa(int(grp.gr_gid)),
Name: C.GoString(grp.gr_name),
Members: getMembers(grp),
}
return g, nil
}
示例9: SetMask
// Change the coloring to c, but only in those bits where m is 1.
func (w *Wrapper) SetMask(c Color, m uint16) error {
current := w32.GetConsoleScreenBufferInfo(w.h)
if current == nil {
return syscall.Errno(w32.GetLastError())
}
if !w32.SetConsoleTextAttribute(w.h, apply(current.WAttributes, uint16(c), uint16(m))) {
return syscall.Errno(w32.GetLastError())
}
return nil
}
示例10: GetUniqueValues
// GetUniqueValues returns all unique values for a given field.
func (j *Journal) GetUniqueValues(field string) ([]string, error) {
var result []string
sd_journal_query_unique, err := getFunction("sd_journal_query_unique")
if err != nil {
return nil, err
}
sd_journal_enumerate_unique, err := getFunction("sd_journal_enumerate_unique")
if err != nil {
return nil, err
}
sd_journal_restart_unique, err := getFunction("sd_journal_restart_unique")
if err != nil {
return nil, err
}
j.mu.Lock()
defer j.mu.Unlock()
f := C.CString(field)
defer C.free(unsafe.Pointer(f))
r := C.my_sd_journal_query_unique(sd_journal_query_unique, j.cjournal, f)
if r < 0 {
return nil, fmt.Errorf("failed to query journal: %d", syscall.Errno(-r))
}
// Implements the SD_JOURNAL_FOREACH_UNIQUE macro from sd-journal.h
var d unsafe.Pointer
var l C.size_t
C.my_sd_journal_restart_unique(sd_journal_restart_unique, j.cjournal)
for {
r = C.my_sd_journal_enumerate_unique(sd_journal_enumerate_unique, j.cjournal, &d, &l)
if r == 0 {
break
}
if r < 0 {
return nil, fmt.Errorf("failed to read message field: %d", syscall.Errno(-r))
}
msg := C.GoStringN((*C.char)(d), C.int(l))
kv := strings.SplitN(msg, "=", 2)
if len(kv) < 2 {
return nil, fmt.Errorf("failed to parse field")
}
result = append(result, kv[1])
}
return result, nil
}
示例11: getTCPTable
// netstat -ano | findstr 202.89.233.104
func getTCPTable() *MIB_TCPTABLE2 {
getTCPTable2 := syscall.NewLazyDLL("Iphlpapi.dll").NewProc("GetTcpTable2")
var n uint32
if err, _, _ := getTCPTable2.Call(uintptr(unsafe.Pointer(&MIB_TCPTABLE2{})), uintptr(unsafe.Pointer(&n)), 1); syscall.Errno(err) != syscall.ERROR_INSUFFICIENT_BUFFER {
common.Error("Error calling GetTcpTable2: %v", syscall.Errno(err))
}
b := make([]byte, n)
if err, _, _ := getTCPTable2.Call(uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&n)), 1); err != 0 {
common.Error("Error calling GetTcpTable2: %v", syscall.Errno(err))
}
table := newTCPTable(NewClassReader(b))
return table
}
示例12: GetExtendedTcpTableIPv4
// The GetExtendedTcpTableIPv4 function retrieves a table that contains a list of TCP
// endpoints available to the application.
func GetExtendedTcpTableIPv4() (MIB_TCPTABLE_OWNER_PID, error) {
var (
TcpTable MIB_TCPTABLE_OWNER_PID
TcpTableSize uint32
)
TcpTableSize = uint32(unsafe.Sizeof(TcpTable))
tableSlice := make([]byte, TcpTableSize)
r, _, _ := procGetExtendedTcpTable.Call(
uintptr(unsafe.Pointer(&tableSlice[0])),
uintptr(unsafe.Pointer(&TcpTableSize)),
uintptr(0),
uintptr(syscall.AF_INET),
uintptr(TCP_TABLE_OWNER_PID_ALL),
uintptr(0))
if syscall.Errno(r) == syscall.ERROR_INSUFFICIENT_BUFFER {
tableSlice = make([]byte, TcpTableSize)
r, _, _ = procGetExtendedTcpTable.Call(
uintptr(unsafe.Pointer(&tableSlice[0])),
uintptr(unsafe.Pointer(&TcpTableSize)),
uintptr(0),
uintptr(syscall.AF_INET),
uintptr(TCP_TABLE_OWNER_PID_ALL),
uintptr(0))
}
buf := bytes.NewReader(tableSlice)
err := binary.Read(buf, binary.LittleEndian, &TcpTable.NumEntries)
if err != nil {
return TcpTable, err
}
TcpTable.Table = make([]MIB_TCPROW_OWNER_PID, TcpTable.NumEntries)
for i := 0; i < int(TcpTable.NumEntries); i++ {
err := binary.Read(buf, binary.LittleEndian, &TcpTable.Table[i])
if err != nil {
break
}
}
if r != 0 {
return TcpTable, syscall.Errno(r)
}
return TcpTable, nil
}
示例13: lookupUnix
func lookupUnix(gid int, groupname string, lookupByName bool) (*Group, error) {
var grp C.struct_group
var result *C.struct_group
var bufSize C.long
if runtime.GOOS == "freebsd" {
panic("Don't know how to deal with freebsd.")
} else {
bufSize = C.sysconf(C._SC_GETGR_R_SIZE_MAX) * 20
if bufSize <= 0 || bufSize > 1<<20 {
return nil, fmt.Errorf("group: unreasonable _SC_GETGR_R_SIZE_MAX of %d", bufSize)
}
}
buf := C.malloc(C.size_t(bufSize))
defer C.free(buf)
var rv C.int
if lookupByName {
nameC := C.CString(groupname)
defer C.free(unsafe.Pointer(nameC))
rv = C.mygetgrnam_r(nameC,
&grp,
(*C.char)(buf),
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf("group: lookup groupname %s: %s", groupname, syscall.Errno(rv))
}
if result == nil {
return nil, UnknownGroupError(groupname)
}
} else {
rv = C.mygetgrgid_r(C.int(gid),
&grp,
(*C.char)(buf),
C.size_t(bufSize),
&result)
if rv != 0 {
return nil, fmt.Errorf("group: lookup groupid %d: %s", gid, syscall.Errno(rv))
}
if result == nil {
return nil, UnknownGroupIdError(gid)
}
}
u := &Group{
Gid: strconv.Itoa(int(grp.gr_gid)),
Groupname: C.GoString(grp.gr_name),
}
return u, nil
}
示例14: connect
// this is close to the connect() function inside stdlib/net
func connect(fd int, ra syscall.Sockaddr, deadline time.Time) error {
switch err := syscall.Connect(fd, ra); err {
case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR:
case nil, syscall.EISCONN:
if !deadline.IsZero() && deadline.Before(time.Now()) {
return errTimeout
}
return nil
default:
return err
}
poller, err := poll.New(fd)
if err != nil {
return err
}
defer poller.Close()
for {
if err = poller.WaitWrite(deadline); err != nil {
return err
}
// if err := fd.pd.WaitWrite(); err != nil {
// return err
// }
// i'd use the above fd.pd.WaitWrite to poll io correctly, just like net sockets...
// but of course, it uses the damn runtime_* functions that _cannot_ be used by
// non-go-stdlib source... seriously guys, this is not nice.
// we're relegated to using syscall.Select (what nightmare that is) or using
// a simple but totally bogus time-based wait. such garbage.
var nerr int
nerr, err = syscall.GetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_ERROR)
if err != nil {
return err
}
switch err = syscall.Errno(nerr); err {
case syscall.EINPROGRESS, syscall.EALREADY, syscall.EINTR:
continue
case syscall.Errno(0), syscall.EISCONN:
if !deadline.IsZero() && deadline.Before(time.Now()) {
return errTimeout
}
return nil
default:
return err
}
}
}
示例15: makeFlushFS
func makeFlushFS() (server fuse.Server, err error) {
// Check the flags.
if *fFlushesFile == 0 || *fFsyncsFile == 0 {
err = fmt.Errorf("You must set the flushfs flags.")
return
}
// Set up the files.
flushes := os.NewFile(uintptr(*fFlushesFile), "(flushes file)")
fsyncs := os.NewFile(uintptr(*fFsyncsFile), "(fsyncs file)")
// Set up errors.
var flushErr error
var fsyncErr error
if *fFlushError != 0 {
flushErr = syscall.Errno(*fFlushError)
}
if *fFsyncError != 0 {
fsyncErr = syscall.Errno(*fFsyncError)
}
// Report flushes and fsyncs by writing the contents followed by a newline.
report := func(f *os.File, outErr error) func(string) error {
return func(s string) (err error) {
buf := []byte(s)
buf = append(buf, '\n')
_, err = f.Write(buf)
if err != nil {
err = fmt.Errorf("Write: %v", err)
return
}
err = outErr
return
}
}
reportFlush := report(flushes, flushErr)
reportFsync := report(fsyncs, fsyncErr)
// Create the file system.
server, err = flushfs.NewFileSystem(reportFlush, reportFsync)
return
}