本文整理匯總了Golang中syscall.Closesocket函數的典型用法代碼示例。如果您正苦於以下問題:Golang Closesocket函數的具體用法?Golang Closesocket怎麽用?Golang Closesocket使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Closesocket函數的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Closesocket
// Closesocket wraps syscall.Closesocket.
func (sw *Switch) Closesocket(s syscall.Handle) (err error) {
so := sw.sockso(s)
if so == nil {
return syscall.Closesocket(s)
}
sw.fmu.RLock()
f, _ := sw.fltab[FilterClose]
sw.fmu.RUnlock()
af, err := f.apply(so)
if err != nil {
return err
}
so.Err = syscall.Closesocket(s)
if err = af.apply(so); err != nil {
return err
}
sw.smu.Lock()
defer sw.smu.Unlock()
if so.Err != nil {
sw.stats.getLocked(so.Cookie).CloseFailed++
return so.Err
}
delete(sw.sotab, s)
sw.stats.getLocked(so.Cookie).Closed++
return nil
}
示例2: Socket
// Socket wraps syscall.Socket.
func (sw *Switch) Socket(family, sotype, proto int) (s syscall.Handle, err error) {
so := &Status{Cookie: cookie(family, sotype, proto)}
sw.fmu.RLock()
f, _ := sw.fltab[FilterSocket]
sw.fmu.RUnlock()
af, err := f.apply(so)
if err != nil {
return syscall.InvalidHandle, err
}
s, so.Err = syscall.Socket(family, sotype, proto)
if err = af.apply(so); err != nil {
if so.Err == nil {
syscall.Closesocket(s)
}
return syscall.InvalidHandle, err
}
sw.smu.Lock()
defer sw.smu.Unlock()
if so.Err != nil {
sw.stats.getLocked(so.Cookie).OpenFailed++
return syscall.InvalidHandle, so.Err
}
nso := sw.addLocked(s, family, sotype, proto)
sw.stats.getLocked(nso.Cookie).Opened++
return s, nil
}
示例3: getInterfaceList
func getInterfaceList() ([]syscall.InterfaceInfo, os.Error) {
s, e := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
if e != 0 {
return nil, os.NewSyscallError("Socket", e)
}
defer syscall.Closesocket(s)
ii := [20]syscall.InterfaceInfo{}
ret := uint32(0)
size := uint32(unsafe.Sizeof(ii))
e = syscall.WSAIoctl(s, syscall.SIO_GET_INTERFACE_LIST, nil, 0, (*byte)(unsafe.Pointer(&ii[0])), size, &ret, nil, 0)
if e != 0 {
return nil, os.NewSyscallError("WSAIoctl", e)
}
c := ret / uint32(unsafe.Sizeof(ii[0]))
return ii[:c-1], nil
}
示例4: getInterfaceInfos
func getInterfaceInfos() ([]syscall.InterfaceInfo, error) {
s, err := sysSocket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
if err != nil {
return nil, os.NewSyscallError("Socket", err)
}
defer syscall.Closesocket(s)
iia := [20]syscall.InterfaceInfo{}
ret := uint32(0)
size := uint32(unsafe.Sizeof(iia))
err = syscall.WSAIoctl(s, syscall.SIO_GET_INTERFACE_LIST, nil, 0, (*byte)(unsafe.Pointer(&iia[0])), size, &ret, nil, 0)
if err != nil {
return nil, os.NewSyscallError("WSAIoctl", err)
}
iilen := ret / uint32(unsafe.Sizeof(iia[0]))
return iia[:iilen-1], nil
}
示例5: skipRawSocketTests
func skipRawSocketTests() (skip bool, skipmsg string, err error) {
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
// Note: To use a socket of type SOCK_RAW requires administrative privileges.
// Users running Winsock applications that use raw sockets must be a member of
// the Administrators group on the local computer, otherwise raw socket calls
// will fail with an error code of WSAEACCES. On Windows Vista and later, access
// for raw sockets is enforced at socket creation. In earlier versions of Windows,
// access for raw sockets is enforced during other socket operations.
s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
if err == syscall.WSAEACCES {
return true, "skipping test; no access to raw socket allowed", nil
}
if err != nil {
return true, "", err
}
defer syscall.Closesocket(s)
return false, "", nil
}
示例6: supportsRawIPSocket
func supportsRawIPSocket() (string, bool) {
// From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
// Note: To use a socket of type SOCK_RAW requires administrative privileges.
// Users running Winsock applications that use raw sockets must be a member of
// the Administrators group on the local computer, otherwise raw socket calls
// will fail with an error code of WSAEACCES. On Windows Vista and later, access
// for raw sockets is enforced at socket creation. In earlier versions of Windows,
// access for raw sockets is enforced during other socket operations.
s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
if err == syscall.WSAEACCES {
return fmt.Sprintf("no access to raw socket allowed on %s", runtime.GOOS), false
}
if err != nil {
return err.Error(), false
}
syscall.Closesocket(s)
return "", true
}
示例7: createSocket
func (s *Ssdp) createSocket() error {
// create the socket
var err error
s.socket.socket, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
if err != nil {
return err
}
// make sure we can reuse it / share it
if err := syscall.SetsockoptInt(s.socket.socket, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
return err
}
// going to broadcast
if err := syscall.SetsockoptInt(s.socket.socket, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
return err
}
// bind it to the ssdp port
lsa := &syscall.SockaddrInet4{Port: 1900, Addr: [4]byte{0, 0, 0, 0}}
err = syscall.Bind(s.socket.socket, lsa)
if err != nil {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
return err
}
iter, err := net.Interfaces()
if err != nil {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
return err
}
wasFound := false
for i := range iter {
if iter[i].Flags&net.FlagMulticast == 0 {
continue
}
addrs, err := iter[i].Addrs()
if err != nil {
continue
}
for k := range addrs {
as4 := addrs[k].(*net.IPAddr).IP.To4()
// join the multicast group
mreq := &syscall.IPMreq{Multiaddr: [4]byte{239, 255, 255, 250}, Interface: [4]byte{as4[0], as4[1], as4[2], as4[3]}}
if err := syscall.SetsockoptIPMreq(s.socket.socket, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq); err != nil {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
return err
}
wasFound = true
}
}
// if we couldn't join a group, fall back to just 0.0.0.0
if !wasFound {
mreq := &syscall.IPMreq{Multiaddr: [4]byte{239, 255, 255, 250}, Interface: [4]byte{0, 0, 0, 0}}
if err := syscall.SetsockoptIPMreq(s.socket.socket, syscall.IPPROTO_IP, syscall.IP_ADD_MEMBERSHIP, mreq); err != nil {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
return err
}
}
s.socket.readBytes = make([]byte, 2048)
return nil
}
示例8: closeSocket
func (s *Ssdp) closeSocket() {
syscall.Closesocket(s.socket.socket)
s.socket.socket = 0
}
示例9: closesocket
func closesocket(s syscall.Handle) error {
return syscall.Closesocket(s)
}
示例10: closesocket
func closesocket(s int) (errno int) {
return syscall.Closesocket(int32(s))
}
示例11: closesocket
func closesocket(s syscall.Handle) (errno int) {
return syscall.Closesocket(s)
}
示例12: closesocket
func closesocket(s syscall.Handle) (err error) {
return syscall.Closesocket(s)
}