// connectSocket makes the connection to the given IP address port
// for the given socket fd
161878
func (conn *ProtectedConnBase) connectSocket(timeout time.Duration) error {
	if nil == conn.ip {
		return fmt.Errorf("Empty IP to connect")
	}
	var sockAddr syscall.Sockaddr
	//bindAddr := &syscall.SockaddrInet4{Port: 0}
	// lip := net.ParseIP("27.38.173.96")
	// copy(bindAddr.Addr[:], lip[0:4])
	if conn.ip.To4() != nil {
		sockAddr4 := &syscall.SockaddrInet4{Port: conn.port}
		copy(sockAddr4.Addr[:], conn.ip.To4()[:])
		sockAddr = sockAddr4
	} else {
		sockAddr6 := &syscall.SockaddrInet6{Port: conn.port}
		copy(sockAddr6.Addr[:], conn.ip.To16()[0:16])
		sockAddr = sockAddr6
		//bindAddr = &syscall.SockaddrInet6{Port: 0}
	}
	// err := syscall.Bind(conn.socketFd, bindAddr)
	// if nil != err {
	// 	return err
	// }
	errCh := make(chan error, 2)
	if timeout <= 0 {
		timeout = 5 * time.Second
	}
	time.AfterFunc(timeout, func() {
		errCh <- errors.New("connect timeout")
	})

	go func() {
		errCh <- syscall.Connect(conn.socketFd, sockAddr)
	}()
	err := <-errCh
	return err
}
1132140
func checkXfrmSocket() error {
	fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_XFRM)
	if err != nil {
		return err
	}
	syscall.Close(fd)
	return nil
}
243372
func (e Endpoint) SocketAddress() string {
	return fmt.Sprintf("%s:%d", e.Host, e.Port)
}
210061
func ConnectWebSocket() error {
	var origin = "http://localhost/"
	var url = "ws://localhost:8080/socket"
	var err error
	WS, err = xwebsocket.Dial(url, "", origin)
	return err
}
214940
func (p *TSocket) Open() error {
	if p.IsOpen() {
		return NewTTransportException(ALREADY_OPEN, "Socket already connected.")
	}
	if p.addr == nil {
		return NewTTransportException(NOT_OPEN, "Cannot open nil address.")
	}
	if len(p.addr.Network()) == 0 {
		return NewTTransportException(NOT_OPEN, "Cannot open bad network name.")
	}
	if len(p.addr.String()) == 0 {
		return NewTTransportException(NOT_OPEN, "Cannot open bad address.")
	}
	var err error
	if p.conn, err = net.DialTimeout(p.addr.Network(), p.addr.String(), p.timeout); err != nil {
		return NewTTransportException(NOT_OPEN, err.Error())
	}
	return nil
}
4978
func listenLinux(lfd listenFD, cid, port uint32) (l *Listener, err error) {
	defer func() {
		if err != nil {
			// If any system calls fail during setup, the socket must be closed
			// to avoid file descriptor leaks.
			_ = lfd.EarlyClose()
		}
	}()

	// Zero-value for "any port" is friendlier in Go than a constant.
	if port == 0 {
		port = unix.VMADDR_PORT_ANY
	}

	sa := &unix.SockaddrVM{
		CID:  cid,
		Port: port,
	}

	if err := lfd.Bind(sa); err != nil {
		return nil, err
	}

	if err := lfd.Listen(unix.SOMAXCONN); err != nil {
		return nil, err
	}

	lsa, err := lfd.Getsockname()
	if err != nil {
		return nil, err
	}

	// Done with blocking mode setup, transition to non-blocking before the
	// caller has a chance to start calling things concurrently that might make
	// the locking situation tricky.
	//
	// Note: if any calls fail after this point, lfd.Close should be invoked
	// for cleanup because the socket is now non-blocking.
	if err := lfd.SetNonblocking("vsock-listen"); err != nil {
		return nil, err
	}

	lsavm := lsa.(*unix.SockaddrVM)
	addr := &Addr{
		ContextID: lsavm.CID,
		Port:      lsavm.Port,
	}

	return &Listener{
		l: &listener{
			fd:   lfd,
			addr: addr,
		},
	}, nil
}
1286041
func SocketAddress(ctx context.Context, id string) (string, error) {
	ns, err := namespaces.NamespaceRequired(ctx)
	if err != nil {
		return "", err
	}
	d := sha256.Sum256([]byte(filepath.Join(ns, id)))
	return filepath.Join(string(filepath.Separator), "containerd-shim", fmt.Sprintf("%x.sock", d)), nil
}
1323199
func newSocket(server *Server, bs backend.BackendSocket) *Socket {
	// Create a new socket value.
	s := &Socket{
		server: server,
		bs:     bs,

		id:       utils.RandomString(socketIDLength),
		channels: newChannels(),

		writeChan:    bs.WriteChan(),
		readChan:     bs.ReadChan(),
		isClosedChan: bs.ClosedChan(),

		pingTimer:   time.NewTimer(pingPeriod),
		pingTimeout: time.NewTimer(pingResponseTimeout),
	}

	// Create the main channel.
	s.mainChannel = s.Channel(mainChannelName)

	// Call the on close method as soon as the socket closes.
	go func() {
		<-s.isClosedChan
		s.onClose()
	}()

	// Stop the timeout again. It will be started by the ping timer.
	s.pingTimeout.Stop()

	// Add the new socket to the active sockets map.
	// If the ID is already present, then generate a new one.
	func() {
		// Lock the mutex.
		s.server.socketsMutex.Lock()
		defer s.server.socketsMutex.Unlock()

		// Be sure that the ID is unique.
		for {
			if _, ok := s.server.sockets[s.id]; !ok {
				break
			}

			s.id = utils.RandomString(socketIDLength)
		}

		// Add the socket to the map.
		s.server.sockets[s.id] = s
	}()

	// Start the loops and handlers in new goroutines.
	go s.pingTimeoutHandler()
	go s.readLoop()
	go s.pingLoop()

	return s
}
272918
func ConnectWithUnixSocket(socketFile string) (*OvsdbClient, error) {

	if _, err := os.Stat(socketFile); os.IsNotExist(err) {
		return nil, errors.New("Invalid socket file")
	}

	return ConnectUsingProtocol("unix", socketFile)
}
383861
func (r *Reactor) AddSocket(soc *Socket, events State, handler func(State) error) {
	r.RemoveSocket(soc)
	r.sockets[soc] = &reactor_socket{e: events, f: handler}
	r.p.Add(soc, events)
}
1020700
func NewSocketListener(socketPath string, handler ConnectionHandler) (*socketListener, error) {
	listener, err := sockets.Listen(socketPath)
	if err != nil {
		return nil, errors.Trace(err)
	}
	sListener := &socketListener{listener: listener, handler: handler}
	sListener.t.Go(sListener.loop)
	return sListener, nil
}
534027
func NewSocket(address string) (net.Listener, error) {
	l, err := winio.ListenPipe(address, nil)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to listen to npipe %s", address)
	}
	return l, nil
}
1133803
func ConnectedSockets(steamid string) int {
	socketsMu.RLock()
	l := len(steamIDSockets[steamid])
	socketsMu.RUnlock()

	return l
}
821562
func (c *Client) DialSocket(socket string, transport *http.Transport) {
	dialSock := func(ctx context.Context, proto, addr string) (conn net.Conn, err error) {
		return defaultDialer.DialContext(ctx, "unix", socket)
	}
	if transport == nil {
		ht := http.DefaultTransport.(*http.Transport)
		transport = &http.Transport{
			Proxy:                 ht.Proxy,
			MaxIdleConns:          ht.MaxIdleConns,
			IdleConnTimeout:       ht.IdleConnTimeout,
			TLSHandshakeTimeout:   ht.TLSHandshakeTimeout,
			ExpectContinueTimeout: ht.ExpectContinueTimeout,
			DialContext:           dialSock,
		}
	}
	if c.Client == nil {
		// need to copy this so we don't modify the default client
		c.Client = &http.Client{
			Timeout: defaultHttpClient.Timeout,
		}
	}
	switch tp := c.Client.Transport.(type) {
	case nil, *Transport:
		c.Client.Transport = &Transport{
			RoundTripper: transport,
			Debug:        DefaultTransport.Debug,
			Output:       DefaultTransport.Output,
		}
	case *http.Transport:
		tp = transport
	default:
		panic(fmt.Sprintf("could not set DialSocket on unknown transport: %#v", tp))
	}
}
1200394
func (_m *API) NetworkConnect(ctx context.Context, network string, target string, ipv4 string, ipv6 string) error {
	ret := _m.Called(ctx, network, target, ipv4, ipv6)

	var r0 error
	if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string) error); ok {
		r0 = rf(ctx, network, target, ipv4, ipv6)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
356087
func (a *cpuAccumulator) isSocketFree(socketID int) bool {
	return a.details.CPUsInSocket(socketID).Size() == a.topo.CPUsPerSocket()
}
1040667
func NewPairSocket() (*PairSocket, error) {
	s, err := NewSocket(AF_SP, PAIR)
	return &PairSocket{s}, err
}