本文整理汇总了Golang中golang.org/x/net/internal/netreflect.SocketOf函数的典型用法代码示例。如果您正苦于以下问题:Golang SocketOf函数的具体用法?Golang SocketOf怎么用?Golang SocketOf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SocketOf函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetTTL
// SetTTL sets the time-to-live field value for future outgoing
// packets.
func (c *genericOpt) SetTTL(ttl int) error {
if !c.ok() {
return syscall.EINVAL
}
s, err := netreflect.SocketOf(c.Conn)
if err != nil {
return err
}
return setInt(s, &sockOpts[ssoTTL], ttl)
}
示例2: TTL
// TTL returns the time-to-live field value for outgoing packets.
func (c *genericOpt) TTL() (int, error) {
if !c.ok() {
return 0, syscall.EINVAL
}
s, err := netreflect.SocketOf(c.Conn)
if err != nil {
return 0, err
}
return getInt(s, &sockOpts[ssoTTL])
}
示例3: SetHopLimit
// SetHopLimit sets the hop limit field value for future outgoing
// packets.
func (c *genericOpt) SetHopLimit(hoplim int) error {
if !c.ok() {
return syscall.EINVAL
}
s, err := netreflect.SocketOf(c.Conn)
if err != nil {
return err
}
return setInt(s, &sockOpts[ssoHopLimit], hoplim)
}
示例4: SetTrafficClass
// SetTrafficClass sets the traffic class field value for future
// outgoing packets.
func (c *genericOpt) SetTrafficClass(tclass int) error {
if !c.ok() {
return syscall.EINVAL
}
s, err := netreflect.SocketOf(c.Conn)
if err != nil {
return err
}
return setInt(s, &sockOpts[ssoTrafficClass], tclass)
}
示例5: PathMTU
// PathMTU returns a path MTU value for the destination associated
// with the endpoint.
func (c *Conn) PathMTU() (int, error) {
if !c.genericOpt.ok() {
return 0, syscall.EINVAL
}
s, err := netreflect.SocketOf(c.genericOpt.Conn)
if err != nil {
return 0, err
}
_, mtu, err := getMTUInfo(s, &sockOpts[ssoPathMTU])
if err != nil {
return 0, err
}
return mtu, nil
}
示例6: TestSocketOf
func TestSocketOf(t *testing.T) {
for _, network := range []string{"tcp", "unix", "unixpacket"} {
switch network {
case "unix":
switch runtime.GOOS {
case "nacl", "plan9", "windows":
continue
}
case "unixpacket":
switch runtime.GOOS {
case "darwin", "nacl", "plan9", "windows":
continue
}
}
ln, err := newLocalListener(network)
if err != nil {
t.Error(err)
continue
}
defer func() {
path := ln.Addr().String()
ln.Close()
if network == "unix" || network == "unixpacket" {
os.Remove(path)
}
}()
c, err := net.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
t.Error(err)
continue
}
defer c.Close()
if _, err := netreflect.SocketOf(c); err != nil {
t.Error(err)
continue
}
}
}