// tiosToSyscall copies a x/sys/unix.Termios to a syscall.Termios.
507213
func tiosToSyscall(ut *unix.Termios) *syscall.Termios {
	return &syscall.Termios{
		Iflag:  ut.Iflag,
		Oflag:  ut.Oflag,
		Cflag:  ut.Cflag,
		Lflag:  ut.Lflag,
		Cc:     ut.Cc,
	}
}
1136762
func NewTabletServer(config tabletenv.TabletConfig, topoServer *topo.Server, alias topodatapb.TabletAlias) *TabletServer {
	tsv := &TabletServer{
		QueryTimeout:           sync2.NewAtomicDuration(time.Duration(config.QueryTimeout * 1e9)),
		BeginTimeout:           sync2.NewAtomicDuration(time.Duration(config.TxPoolTimeout * 1e9)),
		TerseErrors:            config.TerseErrors,
		enableHotRowProtection: config.EnableHotRowProtection || config.EnableHotRowProtectionDryRun,
		checkMySQLThrottler:    sync2.NewSemaphore(1, 0),
		streamHealthMap:        make(map[int]chan<- *querypb.StreamHealthResponse),
		history:                history.New(10),
		topoServer:             topoServer,
		alias:                  alias,
	}
	tsv.se = schema.NewEngine(tsv, config)
	tsv.qe = NewQueryEngine(tsv, tsv.se, config)
	tsv.te = NewTxEngine(tsv, config)
	tsv.teCtrl = tsv.te
	tsv.hw = heartbeat.NewWriter(tsv, alias, config)
	tsv.hr = heartbeat.NewReader(tsv, config)
	tsv.txThrottler = txthrottler.CreateTxThrottlerFromTabletConfig(topoServer)
	tsv.messager = messager.NewEngine(tsv, tsv.se, config)
	tsv.watcher = NewReplicationWatcher(tsv.se, config)
	tsv.updateStreamList = &binlog.StreamList{}
	// FIXME(alainjobart) could we move this to the Register method below?
	// So that vtcombo doesn't even call it once, on the first tablet.
	// And we can remove the tsOnce variable.
	tsOnce.Do(func() {
		srvTopoServer = srvtopo.NewResilientServer(topoServer, "TabletSrvTopo")
		stats.NewGaugeFunc("TabletState", "Tablet server state", func() int64 {
			tsv.mu.Lock()
			state := tsv.state
			tsv.mu.Unlock()
			return state
		})
		stats.Publish("TabletStateName", stats.StringFunc(tsv.GetState))

		// TabletServerState exports the same information as the above two stats (TabletState / TabletStateName),
		// but exported with TabletStateName as a label for Prometheus, which doesn't support exporting strings as stat values.
		stats.NewGaugesFuncWithMultiLabels("TabletServerState", "Tablet server state labeled by state name", []string{"name"}, func() map[string]int64 {
			return map[string]int64{tsv.GetState(): 1}
		})
		stats.NewGaugeDurationFunc("QueryTimeout", "Tablet server query timeout", tsv.QueryTimeout.Get)
		stats.NewGaugeDurationFunc("QueryPoolTimeout", "Tablet server timeout to get a connection from the query pool", tsv.qe.connTimeout.Get)
		stats.NewGaugeDurationFunc("BeginTimeout", "Tablet server begin timeout", tsv.BeginTimeout.Get)
	})
	// TODO(sougou): move this up once the stats naming problem is fixed.
	tsv.vstreamer = vstreamer.NewEngine(srvTopoServer, tsv.se)
	return tsv
}
355832
func (ns *NatsRPCClient) Call(
	ctx context.Context,
	rpcType protos.RPCType,
	route *route.Route,
	session *session.Session,
	msg *message.Message,
	server *Server,
) (*protos.Response, error) {
	parent, err := tracing.ExtractSpan(ctx)
	if err != nil {
		logger.Log.Warnf("failed to retrieve parent span: %s", err.Error())
	}
	tags := opentracing.Tags{
		"span.kind":       "client",
		"local.id":        ns.server.ID,
		"peer.serverType": server.Type,
		"peer.id":         server.ID,
	}
	ctx = tracing.StartSpan(ctx, "RPC Call", tags, parent)
	defer tracing.FinishSpan(ctx, err)

	if !ns.running {
		err = constants.ErrRPCClientNotInitialized
		return nil, err
	}
	req, err := buildRequest(ctx, rpcType, route, session, msg, ns.server)
	if err != nil {
		return nil, err
	}
	marshalledData, err := proto.Marshal(&req)
	if err != nil {
		return nil, err
	}

	var m *nats.Msg

	if ns.metricsReporters != nil {
		startTime := time.Now()
		ctx = pcontext.AddToPropagateCtx(ctx, constants.StartTimeKey, startTime.UnixNano())
		ctx = pcontext.AddToPropagateCtx(ctx, constants.RouteKey, route.String())
		defer func() {
			typ := "rpc"
			metrics.ReportTimingFromCtx(ctx, ns.metricsReporters, typ, err)
		}()
	}
	m, err = ns.conn.Request(getChannel(server.Type, server.ID), marshalledData, ns.reqTimeout)
	if err != nil {
		return nil, err
	}

	res := &protos.Response{}
	err = proto.Unmarshal(m.Data, res)
	if err != nil {
		return nil, err
	}

	if res.Error != nil {
		if res.Error.Code == "" {
			res.Error.Code = errors.ErrUnknownCode
		}
		err = &errors.Error{
			Code:     res.Error.Code,
			Message:  res.Error.Msg,
			Metadata: res.Error.Metadata,
		}
		return nil, err
	}
	return res, nil
}
990980
func (mr *MockFacadeCallerMockRecorder) FacadeCall(arg0, arg1, arg2 interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FacadeCall", reflect.TypeOf((*MockFacadeCaller)(nil).FacadeCall), arg0, arg1, arg2)
}
816843
func GoSilentCall(title string, fx func(), cb func(interface{})) {
	go SilentRecoveryHandlerCallback(title, func() error {
		fx()
		return nil
	}, cb)
}
354553
func NewStaticCall(Class node.Node, Call node.Node, ArgumentList *node.ArgumentList) *StaticCall {
	return &StaticCall{
		FreeFloating: nil,
		Class:        Class,
		Call:         Call,
		ArgumentList: ArgumentList,
	}
}
445917
func (d *Context) SafeCall(fn, args *[0]byte, nargs, nrets int) int {
	return int(C.duk_safe_call(
		d.duk_context,
		fn,
		unsafe.Pointer(&args),
		C.duk_idx_t(nargs),
		C.duk_idx_t(nrets),
	))
}
347722
func (p *Param) SyscallArgList() []string {
	t := p.HelperType()
	var s string
	switch {
	case t[0] == '*':
		s = fmt.Sprintf("unsafe.Pointer(%s)", p.Name)
	case t == "bool":
		s = p.tmpVar()
	case strings.HasPrefix(t, "[]"):
		return []string{
			fmt.Sprintf("uintptr(unsafe.Pointer(%s))", p.tmpVar()),
			fmt.Sprintf("uintptr(len(%s))", p.Name),
		}
	default:
		s = p.Name
	}
	return []string{fmt.Sprintf("uintptr(%s)", s)}
}
301569
func tiosToUnix(st *syscall.Termios) *unix.Termios {
	return &unix.Termios{
		Iflag:  st.Iflag,
		Oflag:  st.Oflag,
		Cflag:  st.Cflag,
		Lflag:  st.Lflag,
		Cc:     st.Cc,
	}
}
28141
func DstHostIs(host string) ReqConditionFunc {
	return func(req *http.Request, ctx *ProxyCtx) bool {
		return req.URL.Host == host
	}
}
805300
func Call(o dbus.BusObject) (*Node, error) {
	var xmldata string
	var node Node

	err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata)
	if err != nil {
		return nil, err
	}
	err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node)
	if err != nil {
		return nil, err
	}
	if node.Name == "" {
		node.Name = string(o.Path())
	}
	return &node, nil
}
550770
func (mr *MockRPCClientMockRecorder) RemoteCall(contextID, methodName, req, resp interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RemoteCall", reflect.TypeOf((*MockRPCClient)(nil).RemoteCall), contextID, methodName, req, resp)
}
1054184
func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call {
	ctrl.T.Helper()

	recv := reflect.ValueOf(receiver)
	for i := 0; i < recv.Type().NumMethod(); i++ {
		if recv.Type().Method(i).Name == method {
			return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...)
		}
	}
	ctrl.T.Fatalf("gomock: failed finding method %s on %T", method, receiver)
	panic("unreachable")
}
562895
func (mock *MyInterfaceMock) ThreeCalls() []struct {
} {
	var calls []struct {
	}
	lockMyInterfaceMockThree.RLock()
	calls = mock.calls.Three
	lockMyInterfaceMockThree.RUnlock()
	return calls
}
665495
func (mock *MyInterfaceMock) TwoCalls() []struct {
} {
	var calls []struct {
	}
	lockMyInterfaceMockTwo.RLock()
	calls = mock.calls.Two
	lockMyInterfaceMockTwo.RUnlock()
	return calls
}
1212057
func callGas(gasTable params.GasTable, availableGas, base uint64, callCost *big.Int) (uint64, error) {
	if gasTable.CreateBySuicide > 0 {
		availableGas = availableGas - base
		gas := availableGas - availableGas/64
		// If the bit length exceeds 64 bit we know that the newly calculated "gas" for EIP150
		// is smaller than the requested amount. Therefor we return the new gas instead
		// of returning an error.
		if !callCost.IsUint64() || gas < callCost.Uint64() {
			return gas, nil
		}
	}
	if !callCost.IsUint64() {
		return 0, errGasUintOverflow
	}

	return callCost.Uint64(), nil
}
873885
func (d *DNSProvider) rpcCall(call *methodCall, resp response) error {
	// marshal
	b, err := xml.MarshalIndent(call, "", "  ")
	if err != nil {
		return fmt.Errorf("marshal error: %v", err)
	}

	// post
	b = append([]byte(`<?xml version="1.0"?>`+"\n"), b...)
	respBody, err := d.httpPost(d.config.BaseURL, "text/xml", bytes.NewReader(b))
	if err != nil {
		return err
	}

	// unmarshal
	err = xml.Unmarshal(respBody, resp)
	if err != nil {
		return fmt.Errorf("unmarshal error: %v", err)
	}
	if resp.faultCode() != 0 {
		return rpcError{
			faultCode: resp.faultCode(), faultString: resp.faultString()}
	}
	return nil
}