// newNpipeIO creates connected upstream io for task/exec `tid,eid`. It is the
// callers responsibility to validate that `if terminal == true`, `stderr ==
// ""`.
497130
func newNpipeIO(ctx context.Context, tid, eid string, stdin, stdout, stderr string, terminal bool) (_ upstreamIO, err error) {
	logrus.WithFields(logrus.Fields{
		"tid":      tid,
		"eid":      eid,
		"stdin":    stdin,
		"stdout":   stdout,
		"stderr":   stderr,
		"terminal": terminal,
	}).Debug("npipeio::New")

	nio := &npipeio{
		stdin:    stdin,
		stdout:   stdout,
		stderr:   stderr,
		terminal: terminal,
		eid:      eid,
		tid:      tid,
	}
	defer func() {
		if err != nil {
			nio.Close()
		}
	}()
	if stdin != "" {
		c, err := winio.DialPipe(stdin, nil)
		if err != nil {
			return nil, err
		}
		nio.sin = c
	}
	if stdout != "" {
		c, err := winio.DialPipe(stdout, nil)
		if err != nil {
			return nil, err
		}
		nio.sout = c
	}
	if stderr != "" {
		c, err := winio.DialPipe(stderr, nil)
		if err != nil {
			return nil, err
		}
		nio.serr = c
	}
	return nio, nil
}
178363
func (c *client) newStdioPipes(fifos *cio.FIFOSet) (_ *stdioPipes, err error) {
	p := &stdioPipes{}
	if fifos.Stdin != "" {
		c.logger.WithFields(logrus.Fields{"stdin": fifos.Stdin}).Debug("listen")
		l, err := winio.ListenPipe(fifos.Stdin, nil)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to create stdin pipe %s", fifos.Stdin)
		}
		dc := &delayedConnection{
			l: l,
		}
		dc.wg.Add(1)
		defer func() {
			if err != nil {
				dc.Close()
			}
		}()
		p.stdin = dc

		go func() {
			c.logger.WithFields(logrus.Fields{"stdin": fifos.Stdin}).Debug("accept")
			conn, err := l.Accept()
			if err != nil {
				dc.Close()
				if err != winio.ErrPipeListenerClosed {
					c.logger.WithError(err).Errorf("failed to accept stdin connection on %s", fifos.Stdin)
				}
				return
			}
			c.logger.WithFields(logrus.Fields{"stdin": fifos.Stdin}).Debug("connected")
			dc.con = conn
			dc.unblockConnectionWaiters()
		}()
	}

	if fifos.Stdout != "" {
		c.logger.WithFields(logrus.Fields{"stdout": fifos.Stdout}).Debug("listen")
		l, err := winio.ListenPipe(fifos.Stdout, nil)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to create stdout pipe %s", fifos.Stdout)
		}
		dc := &delayedConnection{
			l: l,
		}
		dc.wg.Add(1)
		defer func() {
			if err != nil {
				dc.Close()
			}
		}()
		p.stdout = dc

		go func() {
			c.logger.WithFields(logrus.Fields{"stdout": fifos.Stdout}).Debug("accept")
			conn, err := l.Accept()
			if err != nil {
				dc.Close()
				if err != winio.ErrPipeListenerClosed {
					c.logger.WithError(err).Errorf("failed to accept stdout connection on %s", fifos.Stdout)
				}
				return
			}
			c.logger.WithFields(logrus.Fields{"stdout": fifos.Stdout}).Debug("connected")
			dc.con = conn
			dc.unblockConnectionWaiters()
		}()
	}

	if fifos.Stderr != "" {
		c.logger.WithFields(logrus.Fields{"stderr": fifos.Stderr}).Debug("listen")
		l, err := winio.ListenPipe(fifos.Stderr, nil)
		if err != nil {
			return nil, errors.Wrapf(err, "failed to create stderr pipe %s", fifos.Stderr)
		}
		dc := &delayedConnection{
			l: l,
		}
		dc.wg.Add(1)
		defer func() {
			if err != nil {
				dc.Close()
			}
		}()
		p.stderr = dc

		go func() {
			c.logger.WithFields(logrus.Fields{"stderr": fifos.Stderr}).Debug("accept")
			conn, err := l.Accept()
			if err != nil {
				dc.Close()
				if err != winio.ErrPipeListenerClosed {
					c.logger.WithError(err).Errorf("failed to accept stderr connection on %s", fifos.Stderr)
				}
				return
			}
			c.logger.WithFields(logrus.Fields{"stderr": fifos.Stderr}).Debug("connected")
			dc.con = conn
			dc.unblockConnectionWaiters()
		}()
	}
	return p, nil
}
1293628
func NewIPCredential(client *TwilioIPMessagingClient, friendlyName string, kind string, sandbox bool, apnsCert string, apnsPrivateKey string,
	gcmApiKey string) (*IPCredential, error) {
	var credential *IPCredential

	params := url.Values{}
	params.Set("FriendlyName", friendlyName)
	params.Set("Type", kind)
	if sandbox {
		params.Set("Sandbox", "true")
	} else {
		params.Set("Sandbox", "false")
	}
	if apnsCert != "" {
		params.Set("Certificate", apnsCert)
	}
	if apnsPrivateKey != "" {
		params.Set("PrivateKey", apnsPrivateKey)
	}
	if gcmApiKey != "" {
		params.Set("ApiKey", gcmApiKey)
	}

	res, err := client.post(params, "/Credentials.json")

	if err != nil {
		return credential, err
	}

	credential = new(IPCredential)
	err = json.Unmarshal(res, credential)

	return credential, err
}
846001
func WithNewFIFOs(root string, tty, stdin bool) ContainerIOOpts {
	return func(c *ContainerIO) error {
		fifos, err := newFifos(root, c.id, tty, stdin)
		if err != nil {
			return err
		}
		return WithFIFOs(fifos)(c)
	}
}
1047866
func NewMockPathio(ctrl *gomock.Controller) *MockPathio {
	mock := &MockPathio{ctrl: ctrl}
	mock.recorder = &MockPathioMockRecorder{mock}
	return mock
}
993331
func New(endpoint string, socket bool) DnstapIO {
	return &dnstapIO{
		endpoint: endpoint,
		socket:   socket,
		enc: newDnstapEncoder(&fs.EncoderOptions{
			ContentType:   []byte("protobuf:dnstap.Dnstap"),
			Bidirectional: true,
		}),
		queue: make(chan tap.Dnstap, queueSize),
		quit:  make(chan struct{}),
	}
}
1180454
func NewOutPointFromProto(op *lnrpc.OutPoint) OutPoint {
	return OutPoint(fmt.Sprintf("%s:%d", op.TxidStr, op.OutputIndex))
}
412892
func NewBundleAPI(
	st Backend,
	auth facade.Authorizer,
	tag names.ModelTag,
) (*BundleAPI, error) {
	if !auth.AuthClient() {
		return nil, common.ErrPerm
	}

	return &BundleAPI{
		backend:    st,
		authorizer: auth,
		modelTag:   tag,
	}, nil
}
956431
func (s *Service) CloseIO(ctx context.Context, r *shimapi.CloseIORequest) (*ptypes.Empty, error) {
	p, err := s.getExecProcess(r.ID)
	if err != nil {
		return nil, err
	}
	if stdin := p.Stdin(); stdin != nil {
		if err := stdin.Close(); err != nil {
			return nil, errors.Wrap(err, "close stdin")
		}
	}
	return empty, nil
}
442517
func NewPWMPin(key interface{}) (PWMPin, error) {
	if err := InitGPIO(); err != nil {
		return nil, err
	}

	return gpioDriverInstance.PWMPin(key)
}
655613
func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) {
	switch l := len(name); {
	case l == 0:
		return nil, errors.New("cannot have empty name")
	case l > maxWindowsNamedPipeLength:
		return nil, errors.Reason("name exceeds maximum length %d", maxWindowsNamedPipeLength).
			InternalReason("name(%s)", name).Err()
	}

	ctx = log.SetField(ctx, "name", name)
	return &listenerStreamServer{
		Context: ctx,
		gen: func() (net.Listener, string, error) {
			address := "net.pipe:" + name
			pipePath := streamclient.LocalNamedPipePath(name)
			log.Fields{
				"addr":     address,
				"pipePath": pipePath,
			}.Debugf(ctx, "Creating Windows server socket Listener.")

			l, err := winio.ListenPipe(pipePath, nil)
			if err != nil {
				return nil, "", errors.Annotate(err, "failed to listen on named pipe").Err()
			}
			return l, address, nil
		},
	}, nil
}
263624
func NewIAM(endpoint string) *Credentials {
	p := &IAM{
		Client: &http.Client{
			Transport: http.DefaultTransport,
		},
		endpoint: endpoint,
	}
	return New(p)
}
1302881
func (p *Process) CloseIO(ctx context.Context) error {
	_, err := p.t.shim.CloseIO(ctx, &shim.CloseIORequest{
		ID:    p.id,
		Stdin: true,
	})
	if err != nil {
		return errdefs.FromGRPC(err)
	}
	return nil
}
287388
func NewGPIO(
	rs, en, d4, d5, d6, d7, backlight interface{},
	blPolarity BacklightPolarity,
	rowAddr RowAddress,
	modes ...ModeSetter,
) (*HD44780, error) {
	pinKeys := []interface{}{rs, en, d4, d5, d6, d7, backlight}
	pins := [7]embd.DigitalPin{}
	for idx, key := range pinKeys {
		if key == nil {
			continue
		}
		var digitalPin embd.DigitalPin
		if pin, ok := key.(embd.DigitalPin); ok {
			digitalPin = pin
		} else {
			var err error
			digitalPin, err = embd.NewDigitalPin(key)
			if err != nil {
				glog.V(1).Infof("hd44780: error creating digital pin %+v: %s", key, err)
				return nil, err
			}
		}
		pins[idx] = digitalPin
	}
	for _, pin := range pins {
		if pin == nil {
			continue
		}
		err := pin.SetDirection(embd.Out)
		if err != nil {
			glog.Errorf("hd44780: error setting pin %+v to out direction: %s", pin, err)
			return nil, err
		}
	}
	return New(
		NewGPIOConnection(
			pins[0],
			pins[1],
			pins[2],
			pins[3],
			pins[4],
			pins[5],
			pins[6],
			blPolarity),
		rowAddr,
		modes...,
	)
}
763375
func NewGreeterAPI(spec *loads.Document) *GreeterAPI {
	return &GreeterAPI{
		handlers:            make(map[string]map[string]http.Handler),
		formats:             strfmt.Default,
		defaultConsumes:     "application/json",
		defaultProduces:     "application/json",
		customConsumers:     make(map[string]runtime.Consumer),
		customProducers:     make(map[string]runtime.Producer),
		ServerShutdown:      func() {},
		spec:                spec,
		ServeError:          errors.ServeError,
		BasicAuthenticator:  security.BasicAuth,
		APIKeyAuthenticator: security.APIKeyAuth,
		BearerAuthenticator: security.BearerAuth,
		JSONConsumer:        runtime.JSONConsumer(),
		TxtProducer:         runtime.TextProducer(),
		GetGreetingHandler: GetGreetingHandlerFunc(func(params GetGreetingParams) middleware.Responder {
			return middleware.NotImplemented("operation GetGreeting has not yet been implemented")
		}),
	}
}
318095
func NewPublicNetAPI(net *p2p.Server, networkVersion uint64) *PublicNetAPI {
	return &PublicNetAPI{net, networkVersion}
}
988913
func InitGPIO() error {
	if gpioDriverInitialized {
		return nil
	}

	desc, err := DescribeHost()
	if err != nil {
		return err
	}

	if desc.GPIODriver == nil {
		return ErrFeatureNotSupported
	}

	gpioDriverInstance = desc.GPIODriver()
	gpioDriverInitialized = true

	return nil
}