repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
uber/tchannel-go
peer.go
BeginCall
func (p *Peer) BeginCall(ctx context.Context, serviceName, methodName string, callOptions *CallOptions) (*OutboundCall, error) { if callOptions == nil { callOptions = defaultCallOptions } callOptions.RequestState.AddSelectedPeer(p.HostPort()) if err := validateCall(ctx, serviceName, methodName, callOptions); err != nil { return nil, err } conn, err := p.GetConnection(ctx) if err != nil { return nil, err } call, err := conn.beginCall(ctx, serviceName, methodName, callOptions) if err != nil { return nil, err } return call, err }
go
func (p *Peer) BeginCall(ctx context.Context, serviceName, methodName string, callOptions *CallOptions) (*OutboundCall, error) { if callOptions == nil { callOptions = defaultCallOptions } callOptions.RequestState.AddSelectedPeer(p.HostPort()) if err := validateCall(ctx, serviceName, methodName, callOptions); err != nil { return nil, err } conn, err := p.GetConnection(ctx) if err != nil { return nil, err } call, err := conn.beginCall(ctx, serviceName, methodName, callOptions) if err != nil { return nil, err } return call, err }
[ "func", "(", "p", "*", "Peer", ")", "BeginCall", "(", "ctx", "context", ".", "Context", ",", "serviceName", ",", "methodName", "string", ",", "callOptions", "*", "CallOptions", ")", "(", "*", "OutboundCall", ",", "error", ")", "{", "if", "callOptions", "==", "nil", "{", "callOptions", "=", "defaultCallOptions", "\n", "}", "\n", "callOptions", ".", "RequestState", ".", "AddSelectedPeer", "(", "p", ".", "HostPort", "(", ")", ")", "\n", "if", "err", ":=", "validateCall", "(", "ctx", ",", "serviceName", ",", "methodName", ",", "callOptions", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "conn", ",", "err", ":=", "p", ".", "GetConnection", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "call", ",", "err", ":=", "conn", ".", "beginCall", "(", "ctx", ",", "serviceName", ",", "methodName", ",", "callOptions", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "call", ",", "err", "\n", "}" ]
// BeginCall starts a new call to this specific peer, returning an OutboundCall that can // be used to write the arguments of the call.
[ "BeginCall", "starts", "a", "new", "call", "to", "this", "specific", "peer", "returning", "an", "OutboundCall", "that", "can", "be", "used", "to", "write", "the", "arguments", "of", "the", "call", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer.go#L540-L561
test
uber/tchannel-go
peer.go
NumConnections
func (p *Peer) NumConnections() (inbound int, outbound int) { p.RLock() inbound = len(p.inboundConnections) outbound = len(p.outboundConnections) p.RUnlock() return inbound, outbound }
go
func (p *Peer) NumConnections() (inbound int, outbound int) { p.RLock() inbound = len(p.inboundConnections) outbound = len(p.outboundConnections) p.RUnlock() return inbound, outbound }
[ "func", "(", "p", "*", "Peer", ")", "NumConnections", "(", ")", "(", "inbound", "int", ",", "outbound", "int", ")", "{", "p", ".", "RLock", "(", ")", "\n", "inbound", "=", "len", "(", "p", ".", "inboundConnections", ")", "\n", "outbound", "=", "len", "(", "p", ".", "outboundConnections", ")", "\n", "p", ".", "RUnlock", "(", ")", "\n", "return", "inbound", ",", "outbound", "\n", "}" ]
// NumConnections returns the number of inbound and outbound connections for this peer.
[ "NumConnections", "returns", "the", "number", "of", "inbound", "and", "outbound", "connections", "for", "this", "peer", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer.go#L564-L570
test
uber/tchannel-go
peer.go
NumPendingOutbound
func (p *Peer) NumPendingOutbound() int { count := 0 p.RLock() for _, c := range p.outboundConnections { count += c.outbound.count() } for _, c := range p.inboundConnections { count += c.outbound.count() } p.RUnlock() return count }
go
func (p *Peer) NumPendingOutbound() int { count := 0 p.RLock() for _, c := range p.outboundConnections { count += c.outbound.count() } for _, c := range p.inboundConnections { count += c.outbound.count() } p.RUnlock() return count }
[ "func", "(", "p", "*", "Peer", ")", "NumPendingOutbound", "(", ")", "int", "{", "count", ":=", "0", "\n", "p", ".", "RLock", "(", ")", "\n", "for", "_", ",", "c", ":=", "range", "p", ".", "outboundConnections", "{", "count", "+=", "c", ".", "outbound", ".", "count", "(", ")", "\n", "}", "\n", "for", "_", ",", "c", ":=", "range", "p", ".", "inboundConnections", "{", "count", "+=", "c", ".", "outbound", ".", "count", "(", ")", "\n", "}", "\n", "p", ".", "RUnlock", "(", ")", "\n", "return", "count", "\n", "}" ]
// NumPendingOutbound returns the number of pending outbound calls.
[ "NumPendingOutbound", "returns", "the", "number", "of", "pending", "outbound", "calls", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer.go#L573-L585
test
uber/tchannel-go
peer.go
isEphemeralHostPort
func isEphemeralHostPort(hostPort string) bool { return hostPort == "" || hostPort == ephemeralHostPort || strings.HasSuffix(hostPort, ":0") }
go
func isEphemeralHostPort(hostPort string) bool { return hostPort == "" || hostPort == ephemeralHostPort || strings.HasSuffix(hostPort, ":0") }
[ "func", "isEphemeralHostPort", "(", "hostPort", "string", ")", "bool", "{", "return", "hostPort", "==", "\"\"", "||", "hostPort", "==", "ephemeralHostPort", "||", "strings", ".", "HasSuffix", "(", "hostPort", ",", "\":0\"", ")", "\n", "}" ]
// isEphemeralHostPort returns if hostPort is the default ephemeral hostPort.
[ "isEphemeralHostPort", "returns", "if", "hostPort", "is", "the", "default", "ephemeral", "hostPort", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/peer.go#L612-L614
test
uber/tchannel-go
examples/keyvalue/server/server.go
Get
func (h *kvHandler) Get(ctx thrift.Context, key string) (string, error) { if err := isValidKey(key); err != nil { return "", err } h.RLock() defer h.RUnlock() if val, ok := h.vals[key]; ok { return val, nil } return "", &keyvalue.KeyNotFound{Key: key} }
go
func (h *kvHandler) Get(ctx thrift.Context, key string) (string, error) { if err := isValidKey(key); err != nil { return "", err } h.RLock() defer h.RUnlock() if val, ok := h.vals[key]; ok { return val, nil } return "", &keyvalue.KeyNotFound{Key: key} }
[ "func", "(", "h", "*", "kvHandler", ")", "Get", "(", "ctx", "thrift", ".", "Context", ",", "key", "string", ")", "(", "string", ",", "error", ")", "{", "if", "err", ":=", "isValidKey", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "h", ".", "RLock", "(", ")", "\n", "defer", "h", ".", "RUnlock", "(", ")", "\n", "if", "val", ",", "ok", ":=", "h", ".", "vals", "[", "key", "]", ";", "ok", "{", "return", "val", ",", "nil", "\n", "}", "\n", "return", "\"\"", ",", "&", "keyvalue", ".", "KeyNotFound", "{", "Key", ":", "key", "}", "\n", "}" ]
// Get returns the value stored for the given key.
[ "Get", "returns", "the", "value", "stored", "for", "the", "given", "key", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/examples/keyvalue/server/server.go#L91-L104
test
uber/tchannel-go
examples/keyvalue/server/server.go
Set
func (h *kvHandler) Set(ctx thrift.Context, key, value string) error { if err := isValidKey(key); err != nil { return err } h.Lock() defer h.Unlock() h.vals[key] = value // Example of how to use response headers. Normally, these values should be passed via result structs. ctx.SetResponseHeaders(map[string]string{"count": fmt.Sprint(len(h.vals))}) return nil }
go
func (h *kvHandler) Set(ctx thrift.Context, key, value string) error { if err := isValidKey(key); err != nil { return err } h.Lock() defer h.Unlock() h.vals[key] = value // Example of how to use response headers. Normally, these values should be passed via result structs. ctx.SetResponseHeaders(map[string]string{"count": fmt.Sprint(len(h.vals))}) return nil }
[ "func", "(", "h", "*", "kvHandler", ")", "Set", "(", "ctx", "thrift", ".", "Context", ",", "key", ",", "value", "string", ")", "error", "{", "if", "err", ":=", "isValidKey", "(", "key", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "h", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "Unlock", "(", ")", "\n", "h", ".", "vals", "[", "key", "]", "=", "value", "\n", "ctx", ".", "SetResponseHeaders", "(", "map", "[", "string", "]", "string", "{", "\"count\"", ":", "fmt", ".", "Sprint", "(", "len", "(", "h", ".", "vals", ")", ")", "}", ")", "\n", "return", "nil", "\n", "}" ]
// Set sets the value for a given key.
[ "Set", "sets", "the", "value", "for", "a", "given", "key", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/examples/keyvalue/server/server.go#L107-L119
test
uber/tchannel-go
examples/keyvalue/server/server.go
ClearAll
func (h *kvHandler) ClearAll(ctx thrift.Context) error { if !isAdmin(ctx) { return &keyvalue.NotAuthorized{} } h.Lock() defer h.Unlock() h.vals = make(map[string]string) return nil }
go
func (h *kvHandler) ClearAll(ctx thrift.Context) error { if !isAdmin(ctx) { return &keyvalue.NotAuthorized{} } h.Lock() defer h.Unlock() h.vals = make(map[string]string) return nil }
[ "func", "(", "h", "*", "kvHandler", ")", "ClearAll", "(", "ctx", "thrift", ".", "Context", ")", "error", "{", "if", "!", "isAdmin", "(", "ctx", ")", "{", "return", "&", "keyvalue", ".", "NotAuthorized", "{", "}", "\n", "}", "\n", "h", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "Unlock", "(", ")", "\n", "h", ".", "vals", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "return", "nil", "\n", "}" ]
// ClearAll clears all the keys.
[ "ClearAll", "clears", "all", "the", "keys", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/examples/keyvalue/server/server.go#L127-L137
test
uber/tchannel-go
channel.go
NewChannel
func NewChannel(serviceName string, opts *ChannelOptions) (*Channel, error) { if serviceName == "" { return nil, ErrNoServiceName } if opts == nil { opts = &ChannelOptions{} } processName := opts.ProcessName if processName == "" { processName = fmt.Sprintf("%s[%d]", filepath.Base(os.Args[0]), os.Getpid()) } logger := opts.Logger if logger == nil { logger = NullLogger } statsReporter := opts.StatsReporter if statsReporter == nil { statsReporter = NullStatsReporter } timeNow := opts.TimeNow if timeNow == nil { timeNow = time.Now } timeTicker := opts.TimeTicker if timeTicker == nil { timeTicker = time.NewTicker } chID := _nextChID.Inc() logger = logger.WithFields( LogField{"serviceName", serviceName}, LogField{"process", processName}, LogField{"chID", chID}, ) if err := opts.validateIdleCheck(); err != nil { return nil, err } ch := &Channel{ channelConnectionCommon: channelConnectionCommon{ log: logger, relayLocal: toStringSet(opts.RelayLocalHandlers), statsReporter: statsReporter, subChannels: &subChannelMap{}, timeNow: timeNow, timeTicker: timeTicker, tracer: opts.Tracer, }, chID: chID, connectionOptions: opts.DefaultConnectionOptions.withDefaults(), relayHost: opts.RelayHost, relayMaxTimeout: validateRelayMaxTimeout(opts.RelayMaxTimeout, logger), relayTimerVerify: opts.RelayTimerVerification, closed: make(chan struct{}), } ch.peers = newRootPeerList(ch, opts.OnPeerStatusChanged).newChild() if opts.Handler != nil { ch.handler = opts.Handler } else { ch.handler = channelHandler{ch} } ch.mutable.peerInfo = LocalPeerInfo{ PeerInfo: PeerInfo{ ProcessName: processName, HostPort: ephemeralHostPort, IsEphemeral: true, Version: PeerVersion{ Language: "go", LanguageVersion: strings.TrimPrefix(runtime.Version(), "go"), TChannelVersion: VersionInfo, }, }, ServiceName: serviceName, } ch.mutable.state = ChannelClient ch.mutable.conns = make(map[uint32]*Connection) ch.createCommonStats() // Register internal unless the root handler has been overridden, since // Register will panic. if opts.Handler == nil { ch.registerInternal() } registerNewChannel(ch) if opts.RelayHost != nil { opts.RelayHost.SetChannel(ch) } // Start the idle connection timer. ch.mutable.idleSweep = startIdleSweep(ch, opts) return ch, nil }
go
func NewChannel(serviceName string, opts *ChannelOptions) (*Channel, error) { if serviceName == "" { return nil, ErrNoServiceName } if opts == nil { opts = &ChannelOptions{} } processName := opts.ProcessName if processName == "" { processName = fmt.Sprintf("%s[%d]", filepath.Base(os.Args[0]), os.Getpid()) } logger := opts.Logger if logger == nil { logger = NullLogger } statsReporter := opts.StatsReporter if statsReporter == nil { statsReporter = NullStatsReporter } timeNow := opts.TimeNow if timeNow == nil { timeNow = time.Now } timeTicker := opts.TimeTicker if timeTicker == nil { timeTicker = time.NewTicker } chID := _nextChID.Inc() logger = logger.WithFields( LogField{"serviceName", serviceName}, LogField{"process", processName}, LogField{"chID", chID}, ) if err := opts.validateIdleCheck(); err != nil { return nil, err } ch := &Channel{ channelConnectionCommon: channelConnectionCommon{ log: logger, relayLocal: toStringSet(opts.RelayLocalHandlers), statsReporter: statsReporter, subChannels: &subChannelMap{}, timeNow: timeNow, timeTicker: timeTicker, tracer: opts.Tracer, }, chID: chID, connectionOptions: opts.DefaultConnectionOptions.withDefaults(), relayHost: opts.RelayHost, relayMaxTimeout: validateRelayMaxTimeout(opts.RelayMaxTimeout, logger), relayTimerVerify: opts.RelayTimerVerification, closed: make(chan struct{}), } ch.peers = newRootPeerList(ch, opts.OnPeerStatusChanged).newChild() if opts.Handler != nil { ch.handler = opts.Handler } else { ch.handler = channelHandler{ch} } ch.mutable.peerInfo = LocalPeerInfo{ PeerInfo: PeerInfo{ ProcessName: processName, HostPort: ephemeralHostPort, IsEphemeral: true, Version: PeerVersion{ Language: "go", LanguageVersion: strings.TrimPrefix(runtime.Version(), "go"), TChannelVersion: VersionInfo, }, }, ServiceName: serviceName, } ch.mutable.state = ChannelClient ch.mutable.conns = make(map[uint32]*Connection) ch.createCommonStats() // Register internal unless the root handler has been overridden, since // Register will panic. if opts.Handler == nil { ch.registerInternal() } registerNewChannel(ch) if opts.RelayHost != nil { opts.RelayHost.SetChannel(ch) } // Start the idle connection timer. ch.mutable.idleSweep = startIdleSweep(ch, opts) return ch, nil }
[ "func", "NewChannel", "(", "serviceName", "string", ",", "opts", "*", "ChannelOptions", ")", "(", "*", "Channel", ",", "error", ")", "{", "if", "serviceName", "==", "\"\"", "{", "return", "nil", ",", "ErrNoServiceName", "\n", "}", "\n", "if", "opts", "==", "nil", "{", "opts", "=", "&", "ChannelOptions", "{", "}", "\n", "}", "\n", "processName", ":=", "opts", ".", "ProcessName", "\n", "if", "processName", "==", "\"\"", "{", "processName", "=", "fmt", ".", "Sprintf", "(", "\"%s[%d]\"", ",", "filepath", ".", "Base", "(", "os", ".", "Args", "[", "0", "]", ")", ",", "os", ".", "Getpid", "(", ")", ")", "\n", "}", "\n", "logger", ":=", "opts", ".", "Logger", "\n", "if", "logger", "==", "nil", "{", "logger", "=", "NullLogger", "\n", "}", "\n", "statsReporter", ":=", "opts", ".", "StatsReporter", "\n", "if", "statsReporter", "==", "nil", "{", "statsReporter", "=", "NullStatsReporter", "\n", "}", "\n", "timeNow", ":=", "opts", ".", "TimeNow", "\n", "if", "timeNow", "==", "nil", "{", "timeNow", "=", "time", ".", "Now", "\n", "}", "\n", "timeTicker", ":=", "opts", ".", "TimeTicker", "\n", "if", "timeTicker", "==", "nil", "{", "timeTicker", "=", "time", ".", "NewTicker", "\n", "}", "\n", "chID", ":=", "_nextChID", ".", "Inc", "(", ")", "\n", "logger", "=", "logger", ".", "WithFields", "(", "LogField", "{", "\"serviceName\"", ",", "serviceName", "}", ",", "LogField", "{", "\"process\"", ",", "processName", "}", ",", "LogField", "{", "\"chID\"", ",", "chID", "}", ",", ")", "\n", "if", "err", ":=", "opts", ".", "validateIdleCheck", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ch", ":=", "&", "Channel", "{", "channelConnectionCommon", ":", "channelConnectionCommon", "{", "log", ":", "logger", ",", "relayLocal", ":", "toStringSet", "(", "opts", ".", "RelayLocalHandlers", ")", ",", "statsReporter", ":", "statsReporter", ",", "subChannels", ":", "&", "subChannelMap", "{", "}", ",", "timeNow", ":", "timeNow", ",", "timeTicker", ":", "timeTicker", ",", "tracer", ":", "opts", ".", "Tracer", ",", "}", ",", "chID", ":", "chID", ",", "connectionOptions", ":", "opts", ".", "DefaultConnectionOptions", ".", "withDefaults", "(", ")", ",", "relayHost", ":", "opts", ".", "RelayHost", ",", "relayMaxTimeout", ":", "validateRelayMaxTimeout", "(", "opts", ".", "RelayMaxTimeout", ",", "logger", ")", ",", "relayTimerVerify", ":", "opts", ".", "RelayTimerVerification", ",", "closed", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "ch", ".", "peers", "=", "newRootPeerList", "(", "ch", ",", "opts", ".", "OnPeerStatusChanged", ")", ".", "newChild", "(", ")", "\n", "if", "opts", ".", "Handler", "!=", "nil", "{", "ch", ".", "handler", "=", "opts", ".", "Handler", "\n", "}", "else", "{", "ch", ".", "handler", "=", "channelHandler", "{", "ch", "}", "\n", "}", "\n", "ch", ".", "mutable", ".", "peerInfo", "=", "LocalPeerInfo", "{", "PeerInfo", ":", "PeerInfo", "{", "ProcessName", ":", "processName", ",", "HostPort", ":", "ephemeralHostPort", ",", "IsEphemeral", ":", "true", ",", "Version", ":", "PeerVersion", "{", "Language", ":", "\"go\"", ",", "LanguageVersion", ":", "strings", ".", "TrimPrefix", "(", "runtime", ".", "Version", "(", ")", ",", "\"go\"", ")", ",", "TChannelVersion", ":", "VersionInfo", ",", "}", ",", "}", ",", "ServiceName", ":", "serviceName", ",", "}", "\n", "ch", ".", "mutable", ".", "state", "=", "ChannelClient", "\n", "ch", ".", "mutable", ".", "conns", "=", "make", "(", "map", "[", "uint32", "]", "*", "Connection", ")", "\n", "ch", ".", "createCommonStats", "(", ")", "\n", "if", "opts", ".", "Handler", "==", "nil", "{", "ch", ".", "registerInternal", "(", ")", "\n", "}", "\n", "registerNewChannel", "(", "ch", ")", "\n", "if", "opts", ".", "RelayHost", "!=", "nil", "{", "opts", ".", "RelayHost", ".", "SetChannel", "(", "ch", ")", "\n", "}", "\n", "ch", ".", "mutable", ".", "idleSweep", "=", "startIdleSweep", "(", "ch", ",", "opts", ")", "\n", "return", "ch", ",", "nil", "\n", "}" ]
// NewChannel creates a new Channel. The new channel can be used to send outbound requests // to peers, but will not listen or handling incoming requests until one of ListenAndServe // or Serve is called. The local service name should be passed to serviceName.
[ "NewChannel", "creates", "a", "new", "Channel", ".", "The", "new", "channel", "can", "be", "used", "to", "send", "outbound", "requests", "to", "peers", "but", "will", "not", "listen", "or", "handling", "incoming", "requests", "until", "one", "of", "ListenAndServe", "or", "Serve", "is", "called", ".", "The", "local", "service", "name", "should", "be", "passed", "to", "serviceName", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L201-L304
test
uber/tchannel-go
channel.go
Serve
func (ch *Channel) Serve(l net.Listener) error { mutable := &ch.mutable mutable.Lock() defer mutable.Unlock() if mutable.l != nil { return errAlreadyListening } mutable.l = tnet.Wrap(l) if mutable.state != ChannelClient { return errInvalidStateForOp } mutable.state = ChannelListening mutable.peerInfo.HostPort = l.Addr().String() mutable.peerInfo.IsEphemeral = false ch.log = ch.log.WithFields(LogField{"hostPort", mutable.peerInfo.HostPort}) ch.log.Info("Channel is listening.") go ch.serve() return nil }
go
func (ch *Channel) Serve(l net.Listener) error { mutable := &ch.mutable mutable.Lock() defer mutable.Unlock() if mutable.l != nil { return errAlreadyListening } mutable.l = tnet.Wrap(l) if mutable.state != ChannelClient { return errInvalidStateForOp } mutable.state = ChannelListening mutable.peerInfo.HostPort = l.Addr().String() mutable.peerInfo.IsEphemeral = false ch.log = ch.log.WithFields(LogField{"hostPort", mutable.peerInfo.HostPort}) ch.log.Info("Channel is listening.") go ch.serve() return nil }
[ "func", "(", "ch", "*", "Channel", ")", "Serve", "(", "l", "net", ".", "Listener", ")", "error", "{", "mutable", ":=", "&", "ch", ".", "mutable", "\n", "mutable", ".", "Lock", "(", ")", "\n", "defer", "mutable", ".", "Unlock", "(", ")", "\n", "if", "mutable", ".", "l", "!=", "nil", "{", "return", "errAlreadyListening", "\n", "}", "\n", "mutable", ".", "l", "=", "tnet", ".", "Wrap", "(", "l", ")", "\n", "if", "mutable", ".", "state", "!=", "ChannelClient", "{", "return", "errInvalidStateForOp", "\n", "}", "\n", "mutable", ".", "state", "=", "ChannelListening", "\n", "mutable", ".", "peerInfo", ".", "HostPort", "=", "l", ".", "Addr", "(", ")", ".", "String", "(", ")", "\n", "mutable", ".", "peerInfo", ".", "IsEphemeral", "=", "false", "\n", "ch", ".", "log", "=", "ch", ".", "log", ".", "WithFields", "(", "LogField", "{", "\"hostPort\"", ",", "mutable", ".", "peerInfo", ".", "HostPort", "}", ")", "\n", "ch", ".", "log", ".", "Info", "(", "\"Channel is listening.\"", ")", "\n", "go", "ch", ".", "serve", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Serve serves incoming requests using the provided listener. // The local peer info is set synchronously, but the actual socket listening is done in // a separate goroutine.
[ "Serve", "serves", "incoming", "requests", "using", "the", "provided", "listener", ".", "The", "local", "peer", "info", "is", "set", "synchronously", "but", "the", "actual", "socket", "listening", "is", "done", "in", "a", "separate", "goroutine", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L314-L335
test
uber/tchannel-go
channel.go
ListenAndServe
func (ch *Channel) ListenAndServe(hostPort string) error { mutable := &ch.mutable mutable.RLock() if mutable.l != nil { mutable.RUnlock() return errAlreadyListening } l, err := net.Listen("tcp", hostPort) if err != nil { mutable.RUnlock() return err } mutable.RUnlock() return ch.Serve(l) }
go
func (ch *Channel) ListenAndServe(hostPort string) error { mutable := &ch.mutable mutable.RLock() if mutable.l != nil { mutable.RUnlock() return errAlreadyListening } l, err := net.Listen("tcp", hostPort) if err != nil { mutable.RUnlock() return err } mutable.RUnlock() return ch.Serve(l) }
[ "func", "(", "ch", "*", "Channel", ")", "ListenAndServe", "(", "hostPort", "string", ")", "error", "{", "mutable", ":=", "&", "ch", ".", "mutable", "\n", "mutable", ".", "RLock", "(", ")", "\n", "if", "mutable", ".", "l", "!=", "nil", "{", "mutable", ".", "RUnlock", "(", ")", "\n", "return", "errAlreadyListening", "\n", "}", "\n", "l", ",", "err", ":=", "net", ".", "Listen", "(", "\"tcp\"", ",", "hostPort", ")", "\n", "if", "err", "!=", "nil", "{", "mutable", ".", "RUnlock", "(", ")", "\n", "return", "err", "\n", "}", "\n", "mutable", ".", "RUnlock", "(", ")", "\n", "return", "ch", ".", "Serve", "(", "l", ")", "\n", "}" ]
// ListenAndServe listens on the given address and serves incoming requests. // The port may be 0, in which case the channel will use an OS assigned port // This method does not block as the handling of connections is done in a goroutine.
[ "ListenAndServe", "listens", "on", "the", "given", "address", "and", "serves", "incoming", "requests", ".", "The", "port", "may", "be", "0", "in", "which", "case", "the", "channel", "will", "use", "an", "OS", "assigned", "port", "This", "method", "does", "not", "block", "as", "the", "handling", "of", "connections", "is", "done", "in", "a", "goroutine", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L340-L357
test
uber/tchannel-go
channel.go
Register
func (ch *Channel) Register(h Handler, methodName string) { if _, ok := ch.handler.(channelHandler); !ok { panic("can't register handler when channel configured with alternate root handler") } ch.GetSubChannel(ch.PeerInfo().ServiceName).Register(h, methodName) }
go
func (ch *Channel) Register(h Handler, methodName string) { if _, ok := ch.handler.(channelHandler); !ok { panic("can't register handler when channel configured with alternate root handler") } ch.GetSubChannel(ch.PeerInfo().ServiceName).Register(h, methodName) }
[ "func", "(", "ch", "*", "Channel", ")", "Register", "(", "h", "Handler", ",", "methodName", "string", ")", "{", "if", "_", ",", "ok", ":=", "ch", ".", "handler", ".", "(", "channelHandler", ")", ";", "!", "ok", "{", "panic", "(", "\"can't register handler when channel configured with alternate root handler\"", ")", "\n", "}", "\n", "ch", ".", "GetSubChannel", "(", "ch", ".", "PeerInfo", "(", ")", ".", "ServiceName", ")", ".", "Register", "(", "h", ",", "methodName", ")", "\n", "}" ]
// Register registers a handler for a method. // // The handler is registered with the service name used when the Channel was // created. To register a handler with a different service name, obtain a // SubChannel for that service with GetSubChannel, and Register a handler // under that. You may also use SetHandler on a SubChannel to set up a // catch-all Handler for that service. See the docs for SetHandler for more // information. // // Register panics if the channel was constructed with an alternate root // handler.
[ "Register", "registers", "a", "handler", "for", "a", "method", ".", "The", "handler", "is", "registered", "with", "the", "service", "name", "used", "when", "the", "Channel", "was", "created", ".", "To", "register", "a", "handler", "with", "a", "different", "service", "name", "obtain", "a", "SubChannel", "for", "that", "service", "with", "GetSubChannel", "and", "Register", "a", "handler", "under", "that", ".", "You", "may", "also", "use", "SetHandler", "on", "a", "SubChannel", "to", "set", "up", "a", "catch", "-", "all", "Handler", "for", "that", "service", ".", "See", "the", "docs", "for", "SetHandler", "for", "more", "information", ".", "Register", "panics", "if", "the", "channel", "was", "constructed", "with", "an", "alternate", "root", "handler", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L392-L397
test
uber/tchannel-go
channel.go
PeerInfo
func (ch *Channel) PeerInfo() LocalPeerInfo { ch.mutable.RLock() peerInfo := ch.mutable.peerInfo ch.mutable.RUnlock() return peerInfo }
go
func (ch *Channel) PeerInfo() LocalPeerInfo { ch.mutable.RLock() peerInfo := ch.mutable.peerInfo ch.mutable.RUnlock() return peerInfo }
[ "func", "(", "ch", "*", "Channel", ")", "PeerInfo", "(", ")", "LocalPeerInfo", "{", "ch", ".", "mutable", ".", "RLock", "(", ")", "\n", "peerInfo", ":=", "ch", ".", "mutable", ".", "peerInfo", "\n", "ch", ".", "mutable", ".", "RUnlock", "(", ")", "\n", "return", "peerInfo", "\n", "}" ]
// PeerInfo returns the current peer info for the channel
[ "PeerInfo", "returns", "the", "current", "peer", "info", "for", "the", "channel" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L400-L406
test
uber/tchannel-go
channel.go
GetSubChannel
func (ch *Channel) GetSubChannel(serviceName string, opts ...SubChannelOption) *SubChannel { sub, added := ch.subChannels.getOrAdd(serviceName, ch) if added { for _, opt := range opts { opt(sub) } } return sub }
go
func (ch *Channel) GetSubChannel(serviceName string, opts ...SubChannelOption) *SubChannel { sub, added := ch.subChannels.getOrAdd(serviceName, ch) if added { for _, opt := range opts { opt(sub) } } return sub }
[ "func", "(", "ch", "*", "Channel", ")", "GetSubChannel", "(", "serviceName", "string", ",", "opts", "...", "SubChannelOption", ")", "*", "SubChannel", "{", "sub", ",", "added", ":=", "ch", ".", "subChannels", ".", "getOrAdd", "(", "serviceName", ",", "ch", ")", "\n", "if", "added", "{", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", "(", "sub", ")", "\n", "}", "\n", "}", "\n", "return", "sub", "\n", "}" ]
// GetSubChannel returns a SubChannel for the given service name. If the subchannel does not // exist, it is created.
[ "GetSubChannel", "returns", "a", "SubChannel", "for", "the", "given", "service", "name", ".", "If", "the", "subchannel", "does", "not", "exist", "it", "is", "created", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L424-L432
test
uber/tchannel-go
channel.go
serve
func (ch *Channel) serve() { acceptBackoff := 0 * time.Millisecond for { netConn, err := ch.mutable.l.Accept() if err != nil { // Backoff from new accepts if this is a temporary error if ne, ok := err.(net.Error); ok && ne.Temporary() { if acceptBackoff == 0 { acceptBackoff = 5 * time.Millisecond } else { acceptBackoff *= 2 } if max := 1 * time.Second; acceptBackoff > max { acceptBackoff = max } ch.log.WithFields( ErrField(err), LogField{"backoff", acceptBackoff}, ).Warn("Accept error, will wait and retry.") time.Sleep(acceptBackoff) continue } else { // Only log an error if this didn't happen due to a Close. if ch.State() >= ChannelStartClose { return } ch.log.WithFields(ErrField(err)).Fatal("Unrecoverable accept error, closing server.") return } } acceptBackoff = 0 // Perform the connection handshake in a background goroutine. go func() { // Register the connection in the peer once the channel is set up. events := connectionEvents{ OnActive: ch.inboundConnectionActive, OnCloseStateChange: ch.connectionCloseStateChange, OnExchangeUpdated: ch.exchangeUpdated, } if _, err := ch.inboundHandshake(context.Background(), netConn, events); err != nil { netConn.Close() } }() } }
go
func (ch *Channel) serve() { acceptBackoff := 0 * time.Millisecond for { netConn, err := ch.mutable.l.Accept() if err != nil { // Backoff from new accepts if this is a temporary error if ne, ok := err.(net.Error); ok && ne.Temporary() { if acceptBackoff == 0 { acceptBackoff = 5 * time.Millisecond } else { acceptBackoff *= 2 } if max := 1 * time.Second; acceptBackoff > max { acceptBackoff = max } ch.log.WithFields( ErrField(err), LogField{"backoff", acceptBackoff}, ).Warn("Accept error, will wait and retry.") time.Sleep(acceptBackoff) continue } else { // Only log an error if this didn't happen due to a Close. if ch.State() >= ChannelStartClose { return } ch.log.WithFields(ErrField(err)).Fatal("Unrecoverable accept error, closing server.") return } } acceptBackoff = 0 // Perform the connection handshake in a background goroutine. go func() { // Register the connection in the peer once the channel is set up. events := connectionEvents{ OnActive: ch.inboundConnectionActive, OnCloseStateChange: ch.connectionCloseStateChange, OnExchangeUpdated: ch.exchangeUpdated, } if _, err := ch.inboundHandshake(context.Background(), netConn, events); err != nil { netConn.Close() } }() } }
[ "func", "(", "ch", "*", "Channel", ")", "serve", "(", ")", "{", "acceptBackoff", ":=", "0", "*", "time", ".", "Millisecond", "\n", "for", "{", "netConn", ",", "err", ":=", "ch", ".", "mutable", ".", "l", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "ne", ",", "ok", ":=", "err", ".", "(", "net", ".", "Error", ")", ";", "ok", "&&", "ne", ".", "Temporary", "(", ")", "{", "if", "acceptBackoff", "==", "0", "{", "acceptBackoff", "=", "5", "*", "time", ".", "Millisecond", "\n", "}", "else", "{", "acceptBackoff", "*=", "2", "\n", "}", "\n", "if", "max", ":=", "1", "*", "time", ".", "Second", ";", "acceptBackoff", ">", "max", "{", "acceptBackoff", "=", "max", "\n", "}", "\n", "ch", ".", "log", ".", "WithFields", "(", "ErrField", "(", "err", ")", ",", "LogField", "{", "\"backoff\"", ",", "acceptBackoff", "}", ",", ")", ".", "Warn", "(", "\"Accept error, will wait and retry.\"", ")", "\n", "time", ".", "Sleep", "(", "acceptBackoff", ")", "\n", "continue", "\n", "}", "else", "{", "if", "ch", ".", "State", "(", ")", ">=", "ChannelStartClose", "{", "return", "\n", "}", "\n", "ch", ".", "log", ".", "WithFields", "(", "ErrField", "(", "err", ")", ")", ".", "Fatal", "(", "\"Unrecoverable accept error, closing server.\"", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "acceptBackoff", "=", "0", "\n", "go", "func", "(", ")", "{", "events", ":=", "connectionEvents", "{", "OnActive", ":", "ch", ".", "inboundConnectionActive", ",", "OnCloseStateChange", ":", "ch", ".", "connectionCloseStateChange", ",", "OnExchangeUpdated", ":", "ch", ".", "exchangeUpdated", ",", "}", "\n", "if", "_", ",", "err", ":=", "ch", ".", "inboundHandshake", "(", "context", ".", "Background", "(", ")", ",", "netConn", ",", "events", ")", ";", "err", "!=", "nil", "{", "netConn", ".", "Close", "(", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}", "\n", "}" ]
// serve runs the listener to accept and manage new incoming connections, blocking // until the channel is closed.
[ "serve", "runs", "the", "listener", "to", "accept", "and", "manage", "new", "incoming", "connections", "blocking", "until", "the", "channel", "is", "closed", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L456-L503
test
uber/tchannel-go
channel.go
Ping
func (ch *Channel) Ping(ctx context.Context, hostPort string) error { peer := ch.RootPeers().GetOrAdd(hostPort) conn, err := peer.GetConnection(ctx) if err != nil { return err } return conn.ping(ctx) }
go
func (ch *Channel) Ping(ctx context.Context, hostPort string) error { peer := ch.RootPeers().GetOrAdd(hostPort) conn, err := peer.GetConnection(ctx) if err != nil { return err } return conn.ping(ctx) }
[ "func", "(", "ch", "*", "Channel", ")", "Ping", "(", "ctx", "context", ".", "Context", ",", "hostPort", "string", ")", "error", "{", "peer", ":=", "ch", ".", "RootPeers", "(", ")", ".", "GetOrAdd", "(", "hostPort", ")", "\n", "conn", ",", "err", ":=", "peer", ".", "GetConnection", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "conn", ".", "ping", "(", "ctx", ")", "\n", "}" ]
// Ping sends a ping message to the given hostPort and waits for a response.
[ "Ping", "sends", "a", "ping", "message", "to", "the", "given", "hostPort", "and", "waits", "for", "a", "response", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L506-L514
test
uber/tchannel-go
channel.go
StatsTags
func (ch *Channel) StatsTags() map[string]string { m := make(map[string]string) for k, v := range ch.commonStatsTags { m[k] = v } return m }
go
func (ch *Channel) StatsTags() map[string]string { m := make(map[string]string) for k, v := range ch.commonStatsTags { m[k] = v } return m }
[ "func", "(", "ch", "*", "Channel", ")", "StatsTags", "(", ")", "map", "[", "string", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "for", "k", ",", "v", ":=", "range", "ch", ".", "commonStatsTags", "{", "m", "[", "k", "]", "=", "v", "\n", "}", "\n", "return", "m", "\n", "}" ]
// StatsTags returns the common tags that should be used when reporting stats. // It returns a new map for each call.
[ "StatsTags", "returns", "the", "common", "tags", "that", "should", "be", "used", "when", "reporting", "stats", ".", "It", "returns", "a", "new", "map", "for", "each", "call", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L528-L534
test
uber/tchannel-go
channel.go
Connect
func (ch *Channel) Connect(ctx context.Context, hostPort string) (*Connection, error) { switch state := ch.State(); state { case ChannelClient, ChannelListening: break default: ch.log.Debugf("Connect rejecting new connection as state is %v", state) return nil, errInvalidStateForOp } // The context timeout applies to the whole call, but users may want a lower // connect timeout (e.g. for streams). if params := getTChannelParams(ctx); params != nil && params.connectTimeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, params.connectTimeout) defer cancel() } events := connectionEvents{ OnActive: ch.outboundConnectionActive, OnCloseStateChange: ch.connectionCloseStateChange, OnExchangeUpdated: ch.exchangeUpdated, } if err := ctx.Err(); err != nil { return nil, GetContextError(err) } timeout := getTimeout(ctx) tcpConn, err := dialContext(ctx, hostPort) if err != nil { if ne, ok := err.(net.Error); ok && ne.Timeout() { ch.log.WithFields( LogField{"remoteHostPort", hostPort}, LogField{"timeout", timeout}, ).Info("Outbound net.Dial timed out.") err = ErrTimeout } else if ctx.Err() == context.Canceled { ch.log.WithFields( LogField{"remoteHostPort", hostPort}, ).Info("Outbound net.Dial was cancelled.") err = GetContextError(ErrRequestCancelled) } else { ch.log.WithFields( ErrField(err), LogField{"remoteHostPort", hostPort}, ).Info("Outbound net.Dial failed.") } return nil, err } conn, err := ch.outboundHandshake(ctx, tcpConn, hostPort, events) if conn != nil { // It's possible that the connection we just created responds with a host:port // that is not what we tried to connect to. E.g., we may have connected to // 127.0.0.1:1234, but the returned host:port may be 10.0.0.1:1234. // In this case, the connection won't be added to 127.0.0.1:1234 peer // and so future calls to that peer may end up creating new connections. To // avoid this issue, and to avoid clients being aware of any TCP relays, we // add the connection to the intended peer. if hostPort != conn.remotePeerInfo.HostPort { conn.log.Debugf("Outbound connection host:port mismatch, adding to peer %v", conn.remotePeerInfo.HostPort) ch.addConnectionToPeer(hostPort, conn, outbound) } } return conn, err }
go
func (ch *Channel) Connect(ctx context.Context, hostPort string) (*Connection, error) { switch state := ch.State(); state { case ChannelClient, ChannelListening: break default: ch.log.Debugf("Connect rejecting new connection as state is %v", state) return nil, errInvalidStateForOp } // The context timeout applies to the whole call, but users may want a lower // connect timeout (e.g. for streams). if params := getTChannelParams(ctx); params != nil && params.connectTimeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, params.connectTimeout) defer cancel() } events := connectionEvents{ OnActive: ch.outboundConnectionActive, OnCloseStateChange: ch.connectionCloseStateChange, OnExchangeUpdated: ch.exchangeUpdated, } if err := ctx.Err(); err != nil { return nil, GetContextError(err) } timeout := getTimeout(ctx) tcpConn, err := dialContext(ctx, hostPort) if err != nil { if ne, ok := err.(net.Error); ok && ne.Timeout() { ch.log.WithFields( LogField{"remoteHostPort", hostPort}, LogField{"timeout", timeout}, ).Info("Outbound net.Dial timed out.") err = ErrTimeout } else if ctx.Err() == context.Canceled { ch.log.WithFields( LogField{"remoteHostPort", hostPort}, ).Info("Outbound net.Dial was cancelled.") err = GetContextError(ErrRequestCancelled) } else { ch.log.WithFields( ErrField(err), LogField{"remoteHostPort", hostPort}, ).Info("Outbound net.Dial failed.") } return nil, err } conn, err := ch.outboundHandshake(ctx, tcpConn, hostPort, events) if conn != nil { // It's possible that the connection we just created responds with a host:port // that is not what we tried to connect to. E.g., we may have connected to // 127.0.0.1:1234, but the returned host:port may be 10.0.0.1:1234. // In this case, the connection won't be added to 127.0.0.1:1234 peer // and so future calls to that peer may end up creating new connections. To // avoid this issue, and to avoid clients being aware of any TCP relays, we // add the connection to the intended peer. if hostPort != conn.remotePeerInfo.HostPort { conn.log.Debugf("Outbound connection host:port mismatch, adding to peer %v", conn.remotePeerInfo.HostPort) ch.addConnectionToPeer(hostPort, conn, outbound) } } return conn, err }
[ "func", "(", "ch", "*", "Channel", ")", "Connect", "(", "ctx", "context", ".", "Context", ",", "hostPort", "string", ")", "(", "*", "Connection", ",", "error", ")", "{", "switch", "state", ":=", "ch", ".", "State", "(", ")", ";", "state", "{", "case", "ChannelClient", ",", "ChannelListening", ":", "break", "\n", "default", ":", "ch", ".", "log", ".", "Debugf", "(", "\"Connect rejecting new connection as state is %v\"", ",", "state", ")", "\n", "return", "nil", ",", "errInvalidStateForOp", "\n", "}", "\n", "if", "params", ":=", "getTChannelParams", "(", "ctx", ")", ";", "params", "!=", "nil", "&&", "params", ".", "connectTimeout", ">", "0", "{", "var", "cancel", "context", ".", "CancelFunc", "\n", "ctx", ",", "cancel", "=", "context", ".", "WithTimeout", "(", "ctx", ",", "params", ".", "connectTimeout", ")", "\n", "defer", "cancel", "(", ")", "\n", "}", "\n", "events", ":=", "connectionEvents", "{", "OnActive", ":", "ch", ".", "outboundConnectionActive", ",", "OnCloseStateChange", ":", "ch", ".", "connectionCloseStateChange", ",", "OnExchangeUpdated", ":", "ch", ".", "exchangeUpdated", ",", "}", "\n", "if", "err", ":=", "ctx", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "GetContextError", "(", "err", ")", "\n", "}", "\n", "timeout", ":=", "getTimeout", "(", "ctx", ")", "\n", "tcpConn", ",", "err", ":=", "dialContext", "(", "ctx", ",", "hostPort", ")", "\n", "if", "err", "!=", "nil", "{", "if", "ne", ",", "ok", ":=", "err", ".", "(", "net", ".", "Error", ")", ";", "ok", "&&", "ne", ".", "Timeout", "(", ")", "{", "ch", ".", "log", ".", "WithFields", "(", "LogField", "{", "\"remoteHostPort\"", ",", "hostPort", "}", ",", "LogField", "{", "\"timeout\"", ",", "timeout", "}", ",", ")", ".", "Info", "(", "\"Outbound net.Dial timed out.\"", ")", "\n", "err", "=", "ErrTimeout", "\n", "}", "else", "if", "ctx", ".", "Err", "(", ")", "==", "context", ".", "Canceled", "{", "ch", ".", "log", ".", "WithFields", "(", "LogField", "{", "\"remoteHostPort\"", ",", "hostPort", "}", ",", ")", ".", "Info", "(", "\"Outbound net.Dial was cancelled.\"", ")", "\n", "err", "=", "GetContextError", "(", "ErrRequestCancelled", ")", "\n", "}", "else", "{", "ch", ".", "log", ".", "WithFields", "(", "ErrField", "(", "err", ")", ",", "LogField", "{", "\"remoteHostPort\"", ",", "hostPort", "}", ",", ")", ".", "Info", "(", "\"Outbound net.Dial failed.\"", ")", "\n", "}", "\n", "return", "nil", ",", "err", "\n", "}", "\n", "conn", ",", "err", ":=", "ch", ".", "outboundHandshake", "(", "ctx", ",", "tcpConn", ",", "hostPort", ",", "events", ")", "\n", "if", "conn", "!=", "nil", "{", "if", "hostPort", "!=", "conn", ".", "remotePeerInfo", ".", "HostPort", "{", "conn", ".", "log", ".", "Debugf", "(", "\"Outbound connection host:port mismatch, adding to peer %v\"", ",", "conn", ".", "remotePeerInfo", ".", "HostPort", ")", "\n", "ch", ".", "addConnectionToPeer", "(", "hostPort", ",", "conn", ",", "outbound", ")", "\n", "}", "\n", "}", "\n", "return", "conn", ",", "err", "\n", "}" ]
// Connect creates a new outbound connection to hostPort.
[ "Connect", "creates", "a", "new", "outbound", "connection", "to", "hostPort", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L542-L608
test
uber/tchannel-go
channel.go
exchangeUpdated
func (ch *Channel) exchangeUpdated(c *Connection) { if c.remotePeerInfo.HostPort == "" { // Hostport is unknown until we get init resp. return } p, ok := ch.RootPeers().Get(c.remotePeerInfo.HostPort) if !ok { return } ch.updatePeer(p) }
go
func (ch *Channel) exchangeUpdated(c *Connection) { if c.remotePeerInfo.HostPort == "" { // Hostport is unknown until we get init resp. return } p, ok := ch.RootPeers().Get(c.remotePeerInfo.HostPort) if !ok { return } ch.updatePeer(p) }
[ "func", "(", "ch", "*", "Channel", ")", "exchangeUpdated", "(", "c", "*", "Connection", ")", "{", "if", "c", ".", "remotePeerInfo", ".", "HostPort", "==", "\"\"", "{", "return", "\n", "}", "\n", "p", ",", "ok", ":=", "ch", ".", "RootPeers", "(", ")", ".", "Get", "(", "c", ".", "remotePeerInfo", ".", "HostPort", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n", "ch", ".", "updatePeer", "(", "p", ")", "\n", "}" ]
// exchangeUpdated updates the peer heap.
[ "exchangeUpdated", "updates", "the", "peer", "heap", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L611-L623
test
uber/tchannel-go
channel.go
updatePeer
func (ch *Channel) updatePeer(p *Peer) { ch.peers.onPeerChange(p) ch.subChannels.updatePeer(p) p.callOnUpdateComplete() }
go
func (ch *Channel) updatePeer(p *Peer) { ch.peers.onPeerChange(p) ch.subChannels.updatePeer(p) p.callOnUpdateComplete() }
[ "func", "(", "ch", "*", "Channel", ")", "updatePeer", "(", "p", "*", "Peer", ")", "{", "ch", ".", "peers", ".", "onPeerChange", "(", "p", ")", "\n", "ch", ".", "subChannels", ".", "updatePeer", "(", "p", ")", "\n", "p", ".", "callOnUpdateComplete", "(", ")", "\n", "}" ]
// updatePeer updates the score of the peer and update it's position in heap as well.
[ "updatePeer", "updates", "the", "score", "of", "the", "peer", "and", "update", "it", "s", "position", "in", "heap", "as", "well", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L626-L630
test
uber/tchannel-go
channel.go
addConnection
func (ch *Channel) addConnection(c *Connection, direction connectionDirection) bool { ch.mutable.Lock() defer ch.mutable.Unlock() if c.readState() != connectionActive { return false } switch state := ch.mutable.state; state { case ChannelClient, ChannelListening: break default: return false } ch.mutable.conns[c.connID] = c return true }
go
func (ch *Channel) addConnection(c *Connection, direction connectionDirection) bool { ch.mutable.Lock() defer ch.mutable.Unlock() if c.readState() != connectionActive { return false } switch state := ch.mutable.state; state { case ChannelClient, ChannelListening: break default: return false } ch.mutable.conns[c.connID] = c return true }
[ "func", "(", "ch", "*", "Channel", ")", "addConnection", "(", "c", "*", "Connection", ",", "direction", "connectionDirection", ")", "bool", "{", "ch", ".", "mutable", ".", "Lock", "(", ")", "\n", "defer", "ch", ".", "mutable", ".", "Unlock", "(", ")", "\n", "if", "c", ".", "readState", "(", ")", "!=", "connectionActive", "{", "return", "false", "\n", "}", "\n", "switch", "state", ":=", "ch", ".", "mutable", ".", "state", ";", "state", "{", "case", "ChannelClient", ",", "ChannelListening", ":", "break", "\n", "default", ":", "return", "false", "\n", "}", "\n", "ch", ".", "mutable", ".", "conns", "[", "c", ".", "connID", "]", "=", "c", "\n", "return", "true", "\n", "}" ]
// addConnection adds the connection to the channel's list of connection // if the channel is in a valid state to accept this connection. It returns // whether the connection was added.
[ "addConnection", "adds", "the", "connection", "to", "the", "channel", "s", "list", "of", "connection", "if", "the", "channel", "is", "in", "a", "valid", "state", "to", "accept", "this", "connection", ".", "It", "returns", "whether", "the", "connection", "was", "added", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L635-L652
test
uber/tchannel-go
channel.go
removeClosedConn
func (ch *Channel) removeClosedConn(c *Connection) { if c.readState() != connectionClosed { return } ch.mutable.Lock() delete(ch.mutable.conns, c.connID) ch.mutable.Unlock() }
go
func (ch *Channel) removeClosedConn(c *Connection) { if c.readState() != connectionClosed { return } ch.mutable.Lock() delete(ch.mutable.conns, c.connID) ch.mutable.Unlock() }
[ "func", "(", "ch", "*", "Channel", ")", "removeClosedConn", "(", "c", "*", "Connection", ")", "{", "if", "c", ".", "readState", "(", ")", "!=", "connectionClosed", "{", "return", "\n", "}", "\n", "ch", ".", "mutable", ".", "Lock", "(", ")", "\n", "delete", "(", "ch", ".", "mutable", ".", "conns", ",", "c", ".", "connID", ")", "\n", "ch", ".", "mutable", ".", "Unlock", "(", ")", "\n", "}" ]
// removeClosedConn removes a connection if it's closed. // Until a connection is fully closed, the channel must keep track of it.
[ "removeClosedConn", "removes", "a", "connection", "if", "it", "s", "closed", ".", "Until", "a", "connection", "is", "fully", "closed", "the", "channel", "must", "keep", "track", "of", "it", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L689-L697
test
uber/tchannel-go
channel.go
connectionCloseStateChange
func (ch *Channel) connectionCloseStateChange(c *Connection) { ch.removeClosedConn(c) if peer, ok := ch.RootPeers().Get(c.remotePeerInfo.HostPort); ok { peer.connectionCloseStateChange(c) ch.updatePeer(peer) } if c.outboundHP != "" && c.outboundHP != c.remotePeerInfo.HostPort { // Outbound connections may be in multiple peers. if peer, ok := ch.RootPeers().Get(c.outboundHP); ok { peer.connectionCloseStateChange(c) ch.updatePeer(peer) } } chState := ch.State() if chState != ChannelStartClose && chState != ChannelInboundClosed { return } ch.mutable.RLock() minState := ch.getMinConnectionState() ch.mutable.RUnlock() var updateTo ChannelState if minState >= connectionClosed { updateTo = ChannelClosed } else if minState >= connectionInboundClosed && chState == ChannelStartClose { updateTo = ChannelInboundClosed } var updatedToState ChannelState if updateTo > 0 { ch.mutable.Lock() // Recheck the state as it's possible another goroutine changed the state // from what we expected, and so we might make a stale change. if ch.mutable.state == chState { ch.mutable.state = updateTo updatedToState = updateTo } ch.mutable.Unlock() chState = updateTo } c.log.Debugf("ConnectionCloseStateChange channel state = %v connection minState = %v", chState, minState) if updatedToState == ChannelClosed { ch.onClosed() } }
go
func (ch *Channel) connectionCloseStateChange(c *Connection) { ch.removeClosedConn(c) if peer, ok := ch.RootPeers().Get(c.remotePeerInfo.HostPort); ok { peer.connectionCloseStateChange(c) ch.updatePeer(peer) } if c.outboundHP != "" && c.outboundHP != c.remotePeerInfo.HostPort { // Outbound connections may be in multiple peers. if peer, ok := ch.RootPeers().Get(c.outboundHP); ok { peer.connectionCloseStateChange(c) ch.updatePeer(peer) } } chState := ch.State() if chState != ChannelStartClose && chState != ChannelInboundClosed { return } ch.mutable.RLock() minState := ch.getMinConnectionState() ch.mutable.RUnlock() var updateTo ChannelState if minState >= connectionClosed { updateTo = ChannelClosed } else if minState >= connectionInboundClosed && chState == ChannelStartClose { updateTo = ChannelInboundClosed } var updatedToState ChannelState if updateTo > 0 { ch.mutable.Lock() // Recheck the state as it's possible another goroutine changed the state // from what we expected, and so we might make a stale change. if ch.mutable.state == chState { ch.mutable.state = updateTo updatedToState = updateTo } ch.mutable.Unlock() chState = updateTo } c.log.Debugf("ConnectionCloseStateChange channel state = %v connection minState = %v", chState, minState) if updatedToState == ChannelClosed { ch.onClosed() } }
[ "func", "(", "ch", "*", "Channel", ")", "connectionCloseStateChange", "(", "c", "*", "Connection", ")", "{", "ch", ".", "removeClosedConn", "(", "c", ")", "\n", "if", "peer", ",", "ok", ":=", "ch", ".", "RootPeers", "(", ")", ".", "Get", "(", "c", ".", "remotePeerInfo", ".", "HostPort", ")", ";", "ok", "{", "peer", ".", "connectionCloseStateChange", "(", "c", ")", "\n", "ch", ".", "updatePeer", "(", "peer", ")", "\n", "}", "\n", "if", "c", ".", "outboundHP", "!=", "\"\"", "&&", "c", ".", "outboundHP", "!=", "c", ".", "remotePeerInfo", ".", "HostPort", "{", "if", "peer", ",", "ok", ":=", "ch", ".", "RootPeers", "(", ")", ".", "Get", "(", "c", ".", "outboundHP", ")", ";", "ok", "{", "peer", ".", "connectionCloseStateChange", "(", "c", ")", "\n", "ch", ".", "updatePeer", "(", "peer", ")", "\n", "}", "\n", "}", "\n", "chState", ":=", "ch", ".", "State", "(", ")", "\n", "if", "chState", "!=", "ChannelStartClose", "&&", "chState", "!=", "ChannelInboundClosed", "{", "return", "\n", "}", "\n", "ch", ".", "mutable", ".", "RLock", "(", ")", "\n", "minState", ":=", "ch", ".", "getMinConnectionState", "(", ")", "\n", "ch", ".", "mutable", ".", "RUnlock", "(", ")", "\n", "var", "updateTo", "ChannelState", "\n", "if", "minState", ">=", "connectionClosed", "{", "updateTo", "=", "ChannelClosed", "\n", "}", "else", "if", "minState", ">=", "connectionInboundClosed", "&&", "chState", "==", "ChannelStartClose", "{", "updateTo", "=", "ChannelInboundClosed", "\n", "}", "\n", "var", "updatedToState", "ChannelState", "\n", "if", "updateTo", ">", "0", "{", "ch", ".", "mutable", ".", "Lock", "(", ")", "\n", "if", "ch", ".", "mutable", ".", "state", "==", "chState", "{", "ch", ".", "mutable", ".", "state", "=", "updateTo", "\n", "updatedToState", "=", "updateTo", "\n", "}", "\n", "ch", ".", "mutable", ".", "Unlock", "(", ")", "\n", "chState", "=", "updateTo", "\n", "}", "\n", "c", ".", "log", ".", "Debugf", "(", "\"ConnectionCloseStateChange channel state = %v connection minState = %v\"", ",", "chState", ",", "minState", ")", "\n", "if", "updatedToState", "==", "ChannelClosed", "{", "ch", ".", "onClosed", "(", ")", "\n", "}", "\n", "}" ]
// connectionCloseStateChange is called when a connection's close state changes.
[ "connectionCloseStateChange", "is", "called", "when", "a", "connection", "s", "close", "state", "changes", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L710-L759
test
uber/tchannel-go
channel.go
State
func (ch *Channel) State() ChannelState { ch.mutable.RLock() state := ch.mutable.state ch.mutable.RUnlock() return state }
go
func (ch *Channel) State() ChannelState { ch.mutable.RLock() state := ch.mutable.state ch.mutable.RUnlock() return state }
[ "func", "(", "ch", "*", "Channel", ")", "State", "(", ")", "ChannelState", "{", "ch", ".", "mutable", ".", "RLock", "(", ")", "\n", "state", ":=", "ch", ".", "mutable", ".", "state", "\n", "ch", ".", "mutable", ".", "RUnlock", "(", ")", "\n", "return", "state", "\n", "}" ]
// State returns the current channel state.
[ "State", "returns", "the", "current", "channel", "state", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/channel.go#L780-L786
test
uber/tchannel-go
typed/reader.go
NewReader
func NewReader(reader io.Reader) *Reader { r := readerPool.Get().(*Reader) r.reader = reader r.err = nil return r }
go
func NewReader(reader io.Reader) *Reader { r := readerPool.Get().(*Reader) r.reader = reader r.err = nil return r }
[ "func", "NewReader", "(", "reader", "io", ".", "Reader", ")", "*", "Reader", "{", "r", ":=", "readerPool", ".", "Get", "(", ")", ".", "(", "*", "Reader", ")", "\n", "r", ".", "reader", "=", "reader", "\n", "r", ".", "err", "=", "nil", "\n", "return", "r", "\n", "}" ]
// NewReader returns a reader that reads typed values from the reader.
[ "NewReader", "returns", "a", "reader", "that", "reads", "typed", "values", "from", "the", "reader", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/reader.go#L45-L50
test
uber/tchannel-go
typed/reader.go
ReadUint16
func (r *Reader) ReadUint16() uint16 { if r.err != nil { return 0 } buf := r.buf[:2] var readN int readN, r.err = io.ReadFull(r.reader, buf) if readN < 2 { return 0 } return binary.BigEndian.Uint16(buf) }
go
func (r *Reader) ReadUint16() uint16 { if r.err != nil { return 0 } buf := r.buf[:2] var readN int readN, r.err = io.ReadFull(r.reader, buf) if readN < 2 { return 0 } return binary.BigEndian.Uint16(buf) }
[ "func", "(", "r", "*", "Reader", ")", "ReadUint16", "(", ")", "uint16", "{", "if", "r", ".", "err", "!=", "nil", "{", "return", "0", "\n", "}", "\n", "buf", ":=", "r", ".", "buf", "[", ":", "2", "]", "\n", "var", "readN", "int", "\n", "readN", ",", "r", ".", "err", "=", "io", ".", "ReadFull", "(", "r", ".", "reader", ",", "buf", ")", "\n", "if", "readN", "<", "2", "{", "return", "0", "\n", "}", "\n", "return", "binary", ".", "BigEndian", ".", "Uint16", "(", "buf", ")", "\n", "}" ]
// ReadUint16 reads a uint16.
[ "ReadUint16", "reads", "a", "uint16", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/reader.go#L53-L66
test
uber/tchannel-go
typed/reader.go
ReadString
func (r *Reader) ReadString(n int) string { if r.err != nil { return "" } var buf []byte if n <= maxPoolStringLen { buf = r.buf[:n] } else { buf = make([]byte, n) } var readN int readN, r.err = io.ReadFull(r.reader, buf) if readN < n { return "" } s := string(buf) return s }
go
func (r *Reader) ReadString(n int) string { if r.err != nil { return "" } var buf []byte if n <= maxPoolStringLen { buf = r.buf[:n] } else { buf = make([]byte, n) } var readN int readN, r.err = io.ReadFull(r.reader, buf) if readN < n { return "" } s := string(buf) return s }
[ "func", "(", "r", "*", "Reader", ")", "ReadString", "(", "n", "int", ")", "string", "{", "if", "r", ".", "err", "!=", "nil", "{", "return", "\"\"", "\n", "}", "\n", "var", "buf", "[", "]", "byte", "\n", "if", "n", "<=", "maxPoolStringLen", "{", "buf", "=", "r", ".", "buf", "[", ":", "n", "]", "\n", "}", "else", "{", "buf", "=", "make", "(", "[", "]", "byte", ",", "n", ")", "\n", "}", "\n", "var", "readN", "int", "\n", "readN", ",", "r", ".", "err", "=", "io", ".", "ReadFull", "(", "r", ".", "reader", ",", "buf", ")", "\n", "if", "readN", "<", "n", "{", "return", "\"\"", "\n", "}", "\n", "s", ":=", "string", "(", "buf", ")", "\n", "return", "s", "\n", "}" ]
// ReadString reads a string of length n.
[ "ReadString", "reads", "a", "string", "of", "length", "n", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/reader.go#L69-L89
test
uber/tchannel-go
typed/reader.go
ReadLen16String
func (r *Reader) ReadLen16String() string { len := r.ReadUint16() return r.ReadString(int(len)) }
go
func (r *Reader) ReadLen16String() string { len := r.ReadUint16() return r.ReadString(int(len)) }
[ "func", "(", "r", "*", "Reader", ")", "ReadLen16String", "(", ")", "string", "{", "len", ":=", "r", ".", "ReadUint16", "(", ")", "\n", "return", "r", ".", "ReadString", "(", "int", "(", "len", ")", ")", "\n", "}" ]
// ReadLen16String reads a uint16-length prefixed string.
[ "ReadLen16String", "reads", "a", "uint16", "-", "length", "prefixed", "string", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/reader.go#L92-L95
test
uber/tchannel-go
crossdock/behavior/trace/behavior.go
Register
func (b *Behavior) Register(ch *tchannel.Channel) { b.registerThrift(ch) b.registerJSON(ch) }
go
func (b *Behavior) Register(ch *tchannel.Channel) { b.registerThrift(ch) b.registerJSON(ch) }
[ "func", "(", "b", "*", "Behavior", ")", "Register", "(", "ch", "*", "tchannel", ".", "Channel", ")", "{", "b", ".", "registerThrift", "(", "ch", ")", "\n", "b", ".", "registerJSON", "(", "ch", ")", "\n", "}" ]
// Register function adds JSON and Thrift handlers to the server channel ch
[ "Register", "function", "adds", "JSON", "and", "Thrift", "handlers", "to", "the", "server", "channel", "ch" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/crossdock/behavior/trace/behavior.go#L60-L63
test
uber/tchannel-go
crossdock/behavior/trace/behavior.go
Run
func (b *Behavior) Run(t crossdock.T) { logParams(t) sampled, err := strconv.ParseBool(t.Param(sampledParam)) if err != nil { t.Fatalf("Malformed param %s: %s", sampledParam, err) } baggage := randomBaggage() level1 := &Request{ ServerRole: RoleS1, } server1 := t.Param(server1NameParam) level2 := &Downstream{ ServiceName: t.Param(server2NameParam), ServerRole: RoleS2, HostPort: fmt.Sprintf("%s:%s", b.serviceToHost(t.Param(server2NameParam)), b.ServerPort, ), Encoding: t.Param(server2EncodingParam), } level1.Downstream = level2 level3 := &Downstream{ ServiceName: t.Param(server3NameParam), ServerRole: RoleS3, HostPort: fmt.Sprintf("%s:%s", b.serviceToHost(t.Param(server3NameParam)), b.ServerPort, ), Encoding: t.Param(server3EncodingParam), } level2.Downstream = level3 resp, err := b.startTrace(t, level1, sampled, baggage) if err != nil { t.Errorf("Failed to startTrace in S1(%s): %s", server1, err.Error()) return } log.Printf("Response: span=%+v, downstream=%+v", resp.Span, resp.Downstream) traceID := resp.Span.TraceID require := crossdock.Require(t) require.NotEmpty(traceID, "Trace ID should not be empty in S1(%s)", server1) if validateTrace(t, level1.Downstream, resp, server1, 1, traceID, sampled, baggage) { t.Successf("trace checks out") log.Println("PASS") } else { log.Println("FAIL") } }
go
func (b *Behavior) Run(t crossdock.T) { logParams(t) sampled, err := strconv.ParseBool(t.Param(sampledParam)) if err != nil { t.Fatalf("Malformed param %s: %s", sampledParam, err) } baggage := randomBaggage() level1 := &Request{ ServerRole: RoleS1, } server1 := t.Param(server1NameParam) level2 := &Downstream{ ServiceName: t.Param(server2NameParam), ServerRole: RoleS2, HostPort: fmt.Sprintf("%s:%s", b.serviceToHost(t.Param(server2NameParam)), b.ServerPort, ), Encoding: t.Param(server2EncodingParam), } level1.Downstream = level2 level3 := &Downstream{ ServiceName: t.Param(server3NameParam), ServerRole: RoleS3, HostPort: fmt.Sprintf("%s:%s", b.serviceToHost(t.Param(server3NameParam)), b.ServerPort, ), Encoding: t.Param(server3EncodingParam), } level2.Downstream = level3 resp, err := b.startTrace(t, level1, sampled, baggage) if err != nil { t.Errorf("Failed to startTrace in S1(%s): %s", server1, err.Error()) return } log.Printf("Response: span=%+v, downstream=%+v", resp.Span, resp.Downstream) traceID := resp.Span.TraceID require := crossdock.Require(t) require.NotEmpty(traceID, "Trace ID should not be empty in S1(%s)", server1) if validateTrace(t, level1.Downstream, resp, server1, 1, traceID, sampled, baggage) { t.Successf("trace checks out") log.Println("PASS") } else { log.Println("FAIL") } }
[ "func", "(", "b", "*", "Behavior", ")", "Run", "(", "t", "crossdock", ".", "T", ")", "{", "logParams", "(", "t", ")", "\n", "sampled", ",", "err", ":=", "strconv", ".", "ParseBool", "(", "t", ".", "Param", "(", "sampledParam", ")", ")", "\n", "if", "err", "!=", "nil", "{", "t", ".", "Fatalf", "(", "\"Malformed param %s: %s\"", ",", "sampledParam", ",", "err", ")", "\n", "}", "\n", "baggage", ":=", "randomBaggage", "(", ")", "\n", "level1", ":=", "&", "Request", "{", "ServerRole", ":", "RoleS1", ",", "}", "\n", "server1", ":=", "t", ".", "Param", "(", "server1NameParam", ")", "\n", "level2", ":=", "&", "Downstream", "{", "ServiceName", ":", "t", ".", "Param", "(", "server2NameParam", ")", ",", "ServerRole", ":", "RoleS2", ",", "HostPort", ":", "fmt", ".", "Sprintf", "(", "\"%s:%s\"", ",", "b", ".", "serviceToHost", "(", "t", ".", "Param", "(", "server2NameParam", ")", ")", ",", "b", ".", "ServerPort", ",", ")", ",", "Encoding", ":", "t", ".", "Param", "(", "server2EncodingParam", ")", ",", "}", "\n", "level1", ".", "Downstream", "=", "level2", "\n", "level3", ":=", "&", "Downstream", "{", "ServiceName", ":", "t", ".", "Param", "(", "server3NameParam", ")", ",", "ServerRole", ":", "RoleS3", ",", "HostPort", ":", "fmt", ".", "Sprintf", "(", "\"%s:%s\"", ",", "b", ".", "serviceToHost", "(", "t", ".", "Param", "(", "server3NameParam", ")", ")", ",", "b", ".", "ServerPort", ",", ")", ",", "Encoding", ":", "t", ".", "Param", "(", "server3EncodingParam", ")", ",", "}", "\n", "level2", ".", "Downstream", "=", "level3", "\n", "resp", ",", "err", ":=", "b", ".", "startTrace", "(", "t", ",", "level1", ",", "sampled", ",", "baggage", ")", "\n", "if", "err", "!=", "nil", "{", "t", ".", "Errorf", "(", "\"Failed to startTrace in S1(%s): %s\"", ",", "server1", ",", "err", ".", "Error", "(", ")", ")", "\n", "return", "\n", "}", "\n", "log", ".", "Printf", "(", "\"Response: span=%+v, downstream=%+v\"", ",", "resp", ".", "Span", ",", "resp", ".", "Downstream", ")", "\n", "traceID", ":=", "resp", ".", "Span", ".", "TraceID", "\n", "require", ":=", "crossdock", ".", "Require", "(", "t", ")", "\n", "require", ".", "NotEmpty", "(", "traceID", ",", "\"Trace ID should not be empty in S1(%s)\"", ",", "server1", ")", "\n", "if", "validateTrace", "(", "t", ",", "level1", ".", "Downstream", ",", "resp", ",", "server1", ",", "1", ",", "traceID", ",", "sampled", ",", "baggage", ")", "{", "t", ".", "Successf", "(", "\"trace checks out\"", ")", "\n", "log", ".", "Println", "(", "\"PASS\"", ")", "\n", "}", "else", "{", "log", ".", "Println", "(", "\"FAIL\"", ")", "\n", "}", "\n", "}" ]
// Run executes the trace behavior
[ "Run", "executes", "the", "trace", "behavior" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/crossdock/behavior/trace/behavior.go#L66-L119
test
uber/tchannel-go
relay_timer_pool.go
Get
func (tp *relayTimerPool) Get() *relayTimer { timer, ok := tp.pool.Get().(*relayTimer) if ok { timer.released = false return timer } rt := &relayTimer{ pool: tp, } // Go timers are started by default. However, we need to separate creating // the timer and starting the timer for use in the relay code paths. // To make this work without more locks in the relayTimer, we create a Go timer // with a huge timeout so it doesn't run, then stop it so we can start it later. rt.timer = time.AfterFunc(time.Duration(math.MaxInt64), rt.OnTimer) if !rt.timer.Stop() { panic("relayTimer requires timers in stopped state, but failed to stop underlying timer") } return rt }
go
func (tp *relayTimerPool) Get() *relayTimer { timer, ok := tp.pool.Get().(*relayTimer) if ok { timer.released = false return timer } rt := &relayTimer{ pool: tp, } // Go timers are started by default. However, we need to separate creating // the timer and starting the timer for use in the relay code paths. // To make this work without more locks in the relayTimer, we create a Go timer // with a huge timeout so it doesn't run, then stop it so we can start it later. rt.timer = time.AfterFunc(time.Duration(math.MaxInt64), rt.OnTimer) if !rt.timer.Stop() { panic("relayTimer requires timers in stopped state, but failed to stop underlying timer") } return rt }
[ "func", "(", "tp", "*", "relayTimerPool", ")", "Get", "(", ")", "*", "relayTimer", "{", "timer", ",", "ok", ":=", "tp", ".", "pool", ".", "Get", "(", ")", ".", "(", "*", "relayTimer", ")", "\n", "if", "ok", "{", "timer", ".", "released", "=", "false", "\n", "return", "timer", "\n", "}", "\n", "rt", ":=", "&", "relayTimer", "{", "pool", ":", "tp", ",", "}", "\n", "rt", ".", "timer", "=", "time", ".", "AfterFunc", "(", "time", ".", "Duration", "(", "math", ".", "MaxInt64", ")", ",", "rt", ".", "OnTimer", ")", "\n", "if", "!", "rt", ".", "timer", ".", "Stop", "(", ")", "{", "panic", "(", "\"relayTimer requires timers in stopped state, but failed to stop underlying timer\"", ")", "\n", "}", "\n", "return", "rt", "\n", "}" ]
// Get returns a relay timer that has not started. Timers must be started explicitly // using the Start function.
[ "Get", "returns", "a", "relay", "timer", "that", "has", "not", "started", ".", "Timers", "must", "be", "started", "explicitly", "using", "the", "Start", "function", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_timer_pool.go#L66-L85
test
uber/tchannel-go
relay_timer_pool.go
Put
func (tp *relayTimerPool) Put(rt *relayTimer) { if tp.verify { // If we are trying to verify correct pool behavior, then we don't release // the timer, and instead ensure no methods are called after being released. return } tp.pool.Put(rt) }
go
func (tp *relayTimerPool) Put(rt *relayTimer) { if tp.verify { // If we are trying to verify correct pool behavior, then we don't release // the timer, and instead ensure no methods are called after being released. return } tp.pool.Put(rt) }
[ "func", "(", "tp", "*", "relayTimerPool", ")", "Put", "(", "rt", "*", "relayTimer", ")", "{", "if", "tp", ".", "verify", "{", "return", "\n", "}", "\n", "tp", ".", "pool", ".", "Put", "(", "rt", ")", "\n", "}" ]
// Put returns a relayTimer back to the pool.
[ "Put", "returns", "a", "relayTimer", "back", "to", "the", "pool", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_timer_pool.go#L88-L95
test
uber/tchannel-go
relay_timer_pool.go
Start
func (rt *relayTimer) Start(d time.Duration, items *relayItems, id uint32, isOriginator bool) { rt.verifyNotReleased() if rt.active { panic("Tried to start an already-active timer") } rt.active = true rt.items = items rt.id = id rt.isOriginator = isOriginator if wasActive := rt.timer.Reset(d); wasActive { panic("relayTimer's underlying timer was Started multiple times without Stop") } }
go
func (rt *relayTimer) Start(d time.Duration, items *relayItems, id uint32, isOriginator bool) { rt.verifyNotReleased() if rt.active { panic("Tried to start an already-active timer") } rt.active = true rt.items = items rt.id = id rt.isOriginator = isOriginator if wasActive := rt.timer.Reset(d); wasActive { panic("relayTimer's underlying timer was Started multiple times without Stop") } }
[ "func", "(", "rt", "*", "relayTimer", ")", "Start", "(", "d", "time", ".", "Duration", ",", "items", "*", "relayItems", ",", "id", "uint32", ",", "isOriginator", "bool", ")", "{", "rt", ".", "verifyNotReleased", "(", ")", "\n", "if", "rt", ".", "active", "{", "panic", "(", "\"Tried to start an already-active timer\"", ")", "\n", "}", "\n", "rt", ".", "active", "=", "true", "\n", "rt", ".", "items", "=", "items", "\n", "rt", ".", "id", "=", "id", "\n", "rt", ".", "isOriginator", "=", "isOriginator", "\n", "if", "wasActive", ":=", "rt", ".", "timer", ".", "Reset", "(", "d", ")", ";", "wasActive", "{", "panic", "(", "\"relayTimer's underlying timer was Started multiple times without Stop\"", ")", "\n", "}", "\n", "}" ]
// Start starts a timer with the given duration for the specified ID.
[ "Start", "starts", "a", "timer", "with", "the", "given", "duration", "for", "the", "specified", "ID", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_timer_pool.go#L98-L112
test
uber/tchannel-go
relay_timer_pool.go
Release
func (rt *relayTimer) Release() { rt.verifyNotReleased() if rt.active { panic("only stopped or completed timers can be released") } rt.released = true rt.pool.Put(rt) }
go
func (rt *relayTimer) Release() { rt.verifyNotReleased() if rt.active { panic("only stopped or completed timers can be released") } rt.released = true rt.pool.Put(rt) }
[ "func", "(", "rt", "*", "relayTimer", ")", "Release", "(", ")", "{", "rt", ".", "verifyNotReleased", "(", ")", "\n", "if", "rt", ".", "active", "{", "panic", "(", "\"only stopped or completed timers can be released\"", ")", "\n", "}", "\n", "rt", ".", "released", "=", "true", "\n", "rt", ".", "pool", ".", "Put", "(", "rt", ")", "\n", "}" ]
// Release releases a timer back to the timer pool. The timer MUST have run or be // stopped before Release is called.
[ "Release", "releases", "a", "timer", "back", "to", "the", "timer", "pool", ".", "The", "timer", "MUST", "have", "run", "or", "be", "stopped", "before", "Release", "is", "called", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/relay_timer_pool.go#L137-L144
test
uber/tchannel-go
logger.go
NewLogger
func NewLogger(writer io.Writer, fields ...LogField) Logger { return &writerLogger{writer, fields} }
go
func NewLogger(writer io.Writer, fields ...LogField) Logger { return &writerLogger{writer, fields} }
[ "func", "NewLogger", "(", "writer", "io", ".", "Writer", ",", "fields", "...", "LogField", ")", "Logger", "{", "return", "&", "writerLogger", "{", "writer", ",", "fields", "}", "\n", "}" ]
// NewLogger returns a Logger that writes to the given writer.
[ "NewLogger", "returns", "a", "Logger", "that", "writes", "to", "the", "given", "writer", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/logger.go#L119-L121
test
uber/tchannel-go
benchmark/tcp_frame_relay.go
NewTCPFrameRelay
func NewTCPFrameRelay(dests []string, modifier func(bool, *tchannel.Frame) *tchannel.Frame) (Relay, error) { var err error r := &tcpFrameRelay{modifier: modifier} r.tcpRelay, err = newTCPRelay(dests, r.handleConnFrameRelay) if err != nil { return nil, err } return r, nil }
go
func NewTCPFrameRelay(dests []string, modifier func(bool, *tchannel.Frame) *tchannel.Frame) (Relay, error) { var err error r := &tcpFrameRelay{modifier: modifier} r.tcpRelay, err = newTCPRelay(dests, r.handleConnFrameRelay) if err != nil { return nil, err } return r, nil }
[ "func", "NewTCPFrameRelay", "(", "dests", "[", "]", "string", ",", "modifier", "func", "(", "bool", ",", "*", "tchannel", ".", "Frame", ")", "*", "tchannel", ".", "Frame", ")", "(", "Relay", ",", "error", ")", "{", "var", "err", "error", "\n", "r", ":=", "&", "tcpFrameRelay", "{", "modifier", ":", "modifier", "}", "\n", "r", ".", "tcpRelay", ",", "err", "=", "newTCPRelay", "(", "dests", ",", "r", ".", "handleConnFrameRelay", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// NewTCPFrameRelay relays frames from one connection to another. It reads // and writes frames using the TChannel frame functions.
[ "NewTCPFrameRelay", "relays", "frames", "from", "one", "connection", "to", "another", ".", "It", "reads", "and", "writes", "frames", "using", "the", "TChannel", "frame", "functions", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/benchmark/tcp_frame_relay.go#L36-L46
test
uber/tchannel-go
stats/tally.go
tallyTags
func (kt knownTags) tallyTags() map[string]string { tallyTags := make(map[string]string, 5) if kt.dest != "" { tallyTags["dest"] = kt.dest } if kt.source != "" { tallyTags["source"] = kt.source } if kt.procedure != "" { tallyTags["procedure"] = kt.procedure } if kt.retryCount != "" { tallyTags["retry-count"] = kt.retryCount } return tallyTags }
go
func (kt knownTags) tallyTags() map[string]string { tallyTags := make(map[string]string, 5) if kt.dest != "" { tallyTags["dest"] = kt.dest } if kt.source != "" { tallyTags["source"] = kt.source } if kt.procedure != "" { tallyTags["procedure"] = kt.procedure } if kt.retryCount != "" { tallyTags["retry-count"] = kt.retryCount } return tallyTags }
[ "func", "(", "kt", "knownTags", ")", "tallyTags", "(", ")", "map", "[", "string", "]", "string", "{", "tallyTags", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "5", ")", "\n", "if", "kt", ".", "dest", "!=", "\"\"", "{", "tallyTags", "[", "\"dest\"", "]", "=", "kt", ".", "dest", "\n", "}", "\n", "if", "kt", ".", "source", "!=", "\"\"", "{", "tallyTags", "[", "\"source\"", "]", "=", "kt", ".", "source", "\n", "}", "\n", "if", "kt", ".", "procedure", "!=", "\"\"", "{", "tallyTags", "[", "\"procedure\"", "]", "=", "kt", ".", "procedure", "\n", "}", "\n", "if", "kt", ".", "retryCount", "!=", "\"\"", "{", "tallyTags", "[", "\"retry-count\"", "]", "=", "kt", ".", "retryCount", "\n", "}", "\n", "return", "tallyTags", "\n", "}" ]
// Create a sub-scope for this set of known tags.
[ "Create", "a", "sub", "-", "scope", "for", "this", "set", "of", "known", "tags", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/stats/tally.go#L117-L134
test
uber/tchannel-go
subchannel.go
Isolated
func Isolated(s *SubChannel) { s.Lock() s.peers = s.topChannel.peers.newSibling() s.peers.SetStrategy(newLeastPendingCalculator()) s.Unlock() }
go
func Isolated(s *SubChannel) { s.Lock() s.peers = s.topChannel.peers.newSibling() s.peers.SetStrategy(newLeastPendingCalculator()) s.Unlock() }
[ "func", "Isolated", "(", "s", "*", "SubChannel", ")", "{", "s", ".", "Lock", "(", ")", "\n", "s", ".", "peers", "=", "s", ".", "topChannel", ".", "peers", ".", "newSibling", "(", ")", "\n", "s", ".", "peers", ".", "SetStrategy", "(", "newLeastPendingCalculator", "(", ")", ")", "\n", "s", ".", "Unlock", "(", ")", "\n", "}" ]
// Isolated is a SubChannelOption that creates an isolated subchannel.
[ "Isolated", "is", "a", "SubChannelOption", "that", "creates", "an", "isolated", "subchannel", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L35-L40
test
uber/tchannel-go
subchannel.go
Isolated
func (c *SubChannel) Isolated() bool { c.RLock() defer c.RUnlock() return c.topChannel.Peers() != c.peers }
go
func (c *SubChannel) Isolated() bool { c.RLock() defer c.RUnlock() return c.topChannel.Peers() != c.peers }
[ "func", "(", "c", "*", "SubChannel", ")", "Isolated", "(", ")", "bool", "{", "c", ".", "RLock", "(", ")", "\n", "defer", "c", ".", "RUnlock", "(", ")", "\n", "return", "c", ".", "topChannel", ".", "Peers", "(", ")", "!=", "c", ".", "peers", "\n", "}" ]
// Isolated returns whether this subchannel is an isolated subchannel.
[ "Isolated", "returns", "whether", "this", "subchannel", "is", "an", "isolated", "subchannel", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L100-L104
test
uber/tchannel-go
subchannel.go
Register
func (c *SubChannel) Register(h Handler, methodName string) { handlers, ok := c.handler.(*handlerMap) if !ok { panic(fmt.Sprintf( "handler for SubChannel(%v) was changed to disallow method registration", c.ServiceName(), )) } handlers.register(h, methodName) }
go
func (c *SubChannel) Register(h Handler, methodName string) { handlers, ok := c.handler.(*handlerMap) if !ok { panic(fmt.Sprintf( "handler for SubChannel(%v) was changed to disallow method registration", c.ServiceName(), )) } handlers.register(h, methodName) }
[ "func", "(", "c", "*", "SubChannel", ")", "Register", "(", "h", "Handler", ",", "methodName", "string", ")", "{", "handlers", ",", "ok", ":=", "c", ".", "handler", ".", "(", "*", "handlerMap", ")", "\n", "if", "!", "ok", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"handler for SubChannel(%v) was changed to disallow method registration\"", ",", "c", ".", "ServiceName", "(", ")", ",", ")", ")", "\n", "}", "\n", "handlers", ".", "register", "(", "h", ",", "methodName", ")", "\n", "}" ]
// Register registers a handler on the subchannel for the given method. // // This function panics if the Handler for the SubChannel was overwritten with // SetHandler.
[ "Register", "registers", "a", "handler", "on", "the", "subchannel", "for", "the", "given", "method", ".", "This", "function", "panics", "if", "the", "Handler", "for", "the", "SubChannel", "was", "overwritten", "with", "SetHandler", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L110-L119
test
uber/tchannel-go
subchannel.go
GetHandlers
func (c *SubChannel) GetHandlers() map[string]Handler { handlers, ok := c.handler.(*handlerMap) if !ok { panic(fmt.Sprintf( "handler for SubChannel(%v) was changed to disallow method registration", c.ServiceName(), )) } handlers.RLock() handlersMap := make(map[string]Handler, len(handlers.handlers)) for k, v := range handlers.handlers { handlersMap[k] = v } handlers.RUnlock() return handlersMap }
go
func (c *SubChannel) GetHandlers() map[string]Handler { handlers, ok := c.handler.(*handlerMap) if !ok { panic(fmt.Sprintf( "handler for SubChannel(%v) was changed to disallow method registration", c.ServiceName(), )) } handlers.RLock() handlersMap := make(map[string]Handler, len(handlers.handlers)) for k, v := range handlers.handlers { handlersMap[k] = v } handlers.RUnlock() return handlersMap }
[ "func", "(", "c", "*", "SubChannel", ")", "GetHandlers", "(", ")", "map", "[", "string", "]", "Handler", "{", "handlers", ",", "ok", ":=", "c", ".", "handler", ".", "(", "*", "handlerMap", ")", "\n", "if", "!", "ok", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"handler for SubChannel(%v) was changed to disallow method registration\"", ",", "c", ".", "ServiceName", "(", ")", ",", ")", ")", "\n", "}", "\n", "handlers", ".", "RLock", "(", ")", "\n", "handlersMap", ":=", "make", "(", "map", "[", "string", "]", "Handler", ",", "len", "(", "handlers", ".", "handlers", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "handlers", ".", "handlers", "{", "handlersMap", "[", "k", "]", "=", "v", "\n", "}", "\n", "handlers", ".", "RUnlock", "(", ")", "\n", "return", "handlersMap", "\n", "}" ]
// GetHandlers returns all handlers registered on this subchannel by method name. // // This function panics if the Handler for the SubChannel was overwritten with // SetHandler.
[ "GetHandlers", "returns", "all", "handlers", "registered", "on", "this", "subchannel", "by", "method", "name", ".", "This", "function", "panics", "if", "the", "Handler", "for", "the", "SubChannel", "was", "overwritten", "with", "SetHandler", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L125-L141
test
uber/tchannel-go
subchannel.go
StatsTags
func (c *SubChannel) StatsTags() map[string]string { tags := c.topChannel.StatsTags() tags["subchannel"] = c.serviceName return tags }
go
func (c *SubChannel) StatsTags() map[string]string { tags := c.topChannel.StatsTags() tags["subchannel"] = c.serviceName return tags }
[ "func", "(", "c", "*", "SubChannel", ")", "StatsTags", "(", ")", "map", "[", "string", "]", "string", "{", "tags", ":=", "c", ".", "topChannel", ".", "StatsTags", "(", ")", "\n", "tags", "[", "\"subchannel\"", "]", "=", "c", ".", "serviceName", "\n", "return", "tags", "\n", "}" ]
// StatsTags returns the stats tags for this subchannel.
[ "StatsTags", "returns", "the", "stats", "tags", "for", "this", "subchannel", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L164-L168
test
uber/tchannel-go
subchannel.go
registerNewSubChannel
func (subChMap *subChannelMap) registerNewSubChannel(serviceName string, ch *Channel) (_ *SubChannel, added bool) { subChMap.Lock() defer subChMap.Unlock() if subChMap.subchannels == nil { subChMap.subchannels = make(map[string]*SubChannel) } if sc, ok := subChMap.subchannels[serviceName]; ok { return sc, false } sc := newSubChannel(serviceName, ch) subChMap.subchannels[serviceName] = sc return sc, true }
go
func (subChMap *subChannelMap) registerNewSubChannel(serviceName string, ch *Channel) (_ *SubChannel, added bool) { subChMap.Lock() defer subChMap.Unlock() if subChMap.subchannels == nil { subChMap.subchannels = make(map[string]*SubChannel) } if sc, ok := subChMap.subchannels[serviceName]; ok { return sc, false } sc := newSubChannel(serviceName, ch) subChMap.subchannels[serviceName] = sc return sc, true }
[ "func", "(", "subChMap", "*", "subChannelMap", ")", "registerNewSubChannel", "(", "serviceName", "string", ",", "ch", "*", "Channel", ")", "(", "_", "*", "SubChannel", ",", "added", "bool", ")", "{", "subChMap", ".", "Lock", "(", ")", "\n", "defer", "subChMap", ".", "Unlock", "(", ")", "\n", "if", "subChMap", ".", "subchannels", "==", "nil", "{", "subChMap", ".", "subchannels", "=", "make", "(", "map", "[", "string", "]", "*", "SubChannel", ")", "\n", "}", "\n", "if", "sc", ",", "ok", ":=", "subChMap", ".", "subchannels", "[", "serviceName", "]", ";", "ok", "{", "return", "sc", ",", "false", "\n", "}", "\n", "sc", ":=", "newSubChannel", "(", "serviceName", ",", "ch", ")", "\n", "subChMap", ".", "subchannels", "[", "serviceName", "]", "=", "sc", "\n", "return", "sc", ",", "true", "\n", "}" ]
// Register a new subchannel for the given serviceName
[ "Register", "a", "new", "subchannel", "for", "the", "given", "serviceName" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L176-L191
test
uber/tchannel-go
subchannel.go
get
func (subChMap *subChannelMap) get(serviceName string) (*SubChannel, bool) { subChMap.RLock() sc, ok := subChMap.subchannels[serviceName] subChMap.RUnlock() return sc, ok }
go
func (subChMap *subChannelMap) get(serviceName string) (*SubChannel, bool) { subChMap.RLock() sc, ok := subChMap.subchannels[serviceName] subChMap.RUnlock() return sc, ok }
[ "func", "(", "subChMap", "*", "subChannelMap", ")", "get", "(", "serviceName", "string", ")", "(", "*", "SubChannel", ",", "bool", ")", "{", "subChMap", ".", "RLock", "(", ")", "\n", "sc", ",", "ok", ":=", "subChMap", ".", "subchannels", "[", "serviceName", "]", "\n", "subChMap", ".", "RUnlock", "(", ")", "\n", "return", "sc", ",", "ok", "\n", "}" ]
// Get subchannel if, we have one
[ "Get", "subchannel", "if", "we", "have", "one" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L194-L199
test
uber/tchannel-go
subchannel.go
getOrAdd
func (subChMap *subChannelMap) getOrAdd(serviceName string, ch *Channel) (_ *SubChannel, added bool) { if sc, ok := subChMap.get(serviceName); ok { return sc, false } return subChMap.registerNewSubChannel(serviceName, ch) }
go
func (subChMap *subChannelMap) getOrAdd(serviceName string, ch *Channel) (_ *SubChannel, added bool) { if sc, ok := subChMap.get(serviceName); ok { return sc, false } return subChMap.registerNewSubChannel(serviceName, ch) }
[ "func", "(", "subChMap", "*", "subChannelMap", ")", "getOrAdd", "(", "serviceName", "string", ",", "ch", "*", "Channel", ")", "(", "_", "*", "SubChannel", ",", "added", "bool", ")", "{", "if", "sc", ",", "ok", ":=", "subChMap", ".", "get", "(", "serviceName", ")", ";", "ok", "{", "return", "sc", ",", "false", "\n", "}", "\n", "return", "subChMap", ".", "registerNewSubChannel", "(", "serviceName", ",", "ch", ")", "\n", "}" ]
// GetOrAdd a subchannel for the given serviceName on the map
[ "GetOrAdd", "a", "subchannel", "for", "the", "given", "serviceName", "on", "the", "map" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/subchannel.go#L202-L208
test
uber/tchannel-go
hyperbahn/discover.go
Discover
func (c *Client) Discover(serviceName string) ([]string, error) { ctx, cancel := thrift.NewContext(time.Second) defer cancel() result, err := c.hyperbahnClient.Discover(ctx, &hyperbahn.DiscoveryQuery{ServiceName: serviceName}) if err != nil { return nil, err } var hostPorts []string for _, peer := range result.GetPeers() { hostPorts = append(hostPorts, servicePeerToHostPort(peer)) } return hostPorts, nil }
go
func (c *Client) Discover(serviceName string) ([]string, error) { ctx, cancel := thrift.NewContext(time.Second) defer cancel() result, err := c.hyperbahnClient.Discover(ctx, &hyperbahn.DiscoveryQuery{ServiceName: serviceName}) if err != nil { return nil, err } var hostPorts []string for _, peer := range result.GetPeers() { hostPorts = append(hostPorts, servicePeerToHostPort(peer)) } return hostPorts, nil }
[ "func", "(", "c", "*", "Client", ")", "Discover", "(", "serviceName", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "ctx", ",", "cancel", ":=", "thrift", ".", "NewContext", "(", "time", ".", "Second", ")", "\n", "defer", "cancel", "(", ")", "\n", "result", ",", "err", ":=", "c", ".", "hyperbahnClient", ".", "Discover", "(", "ctx", ",", "&", "hyperbahn", ".", "DiscoveryQuery", "{", "ServiceName", ":", "serviceName", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "hostPorts", "[", "]", "string", "\n", "for", "_", ",", "peer", ":=", "range", "result", ".", "GetPeers", "(", ")", "{", "hostPorts", "=", "append", "(", "hostPorts", ",", "servicePeerToHostPort", "(", "peer", ")", ")", "\n", "}", "\n", "return", "hostPorts", ",", "nil", "\n", "}" ]
// Discover queries Hyperbahn for a list of peers that are currently // advertised with the specified service name.
[ "Discover", "queries", "Hyperbahn", "for", "a", "list", "of", "peers", "that", "are", "currently", "advertised", "with", "the", "specified", "service", "name", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/hyperbahn/discover.go#L32-L47
test
uber/tchannel-go
crossdock/client/client.go
Start
func (c *Client) Start() error { if err := c.listen(); err != nil { return err } go func() { http.Serve(c.listener, c.mux) }() return nil }
go
func (c *Client) Start() error { if err := c.listen(); err != nil { return err } go func() { http.Serve(c.listener, c.mux) }() return nil }
[ "func", "(", "c", "*", "Client", ")", "Start", "(", ")", "error", "{", "if", "err", ":=", "c", ".", "listen", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "go", "func", "(", ")", "{", "http", ".", "Serve", "(", "c", ".", "listener", ",", "c", ".", "mux", ")", "\n", "}", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Start begins a Crossdock client in the background.
[ "Start", "begins", "a", "Crossdock", "client", "in", "the", "background", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/crossdock/client/client.go#L43-L51
test
uber/tchannel-go
crossdock/client/client.go
listen
func (c *Client) listen() error { c.setDefaultPort(&c.ClientHostPort, ":"+common.DefaultClientPortHTTP) c.setDefaultPort(&c.ServerPort, common.DefaultServerPort) c.mux = http.NewServeMux() // Using default mux creates problem in unit tests c.mux.Handle("/", crossdock.Handler(c.Behaviors, true)) listener, err := net.Listen("tcp", c.ClientHostPort) if err != nil { return err } c.listener = listener c.ClientHostPort = listener.Addr().String() // override in case it was ":0" return nil }
go
func (c *Client) listen() error { c.setDefaultPort(&c.ClientHostPort, ":"+common.DefaultClientPortHTTP) c.setDefaultPort(&c.ServerPort, common.DefaultServerPort) c.mux = http.NewServeMux() // Using default mux creates problem in unit tests c.mux.Handle("/", crossdock.Handler(c.Behaviors, true)) listener, err := net.Listen("tcp", c.ClientHostPort) if err != nil { return err } c.listener = listener c.ClientHostPort = listener.Addr().String() // override in case it was ":0" return nil }
[ "func", "(", "c", "*", "Client", ")", "listen", "(", ")", "error", "{", "c", ".", "setDefaultPort", "(", "&", "c", ".", "ClientHostPort", ",", "\":\"", "+", "common", ".", "DefaultClientPortHTTP", ")", "\n", "c", ".", "setDefaultPort", "(", "&", "c", ".", "ServerPort", ",", "common", ".", "DefaultServerPort", ")", "\n", "c", ".", "mux", "=", "http", ".", "NewServeMux", "(", ")", "\n", "c", ".", "mux", ".", "Handle", "(", "\"/\"", ",", "crossdock", ".", "Handler", "(", "c", ".", "Behaviors", ",", "true", ")", ")", "\n", "listener", ",", "err", ":=", "net", ".", "Listen", "(", "\"tcp\"", ",", "c", ".", "ClientHostPort", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "c", ".", "listener", "=", "listener", "\n", "c", ".", "ClientHostPort", "=", "listener", ".", "Addr", "(", ")", ".", "String", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Listen initializes the server
[ "Listen", "initializes", "the", "server" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/crossdock/client/client.go#L54-L68
test
uber/tchannel-go
http/request.go
WriteRequest
func WriteRequest(call tchannel.ArgWritable, req *http.Request) error { // TODO(prashant): Allow creating write buffers that let you grow the buffer underneath. wb := typed.NewWriteBufferWithSize(10000) wb.WriteLen8String(req.Method) writeVarintString(wb, req.URL.String()) writeHeaders(wb, req.Header) arg2Writer, err := call.Arg2Writer() if err != nil { return err } if _, err := wb.FlushTo(arg2Writer); err != nil { return err } if err := arg2Writer.Close(); err != nil { return err } arg3Writer, err := call.Arg3Writer() if err != nil { return err } if req.Body != nil { if _, err = io.Copy(arg3Writer, req.Body); err != nil { return err } } return arg3Writer.Close() }
go
func WriteRequest(call tchannel.ArgWritable, req *http.Request) error { // TODO(prashant): Allow creating write buffers that let you grow the buffer underneath. wb := typed.NewWriteBufferWithSize(10000) wb.WriteLen8String(req.Method) writeVarintString(wb, req.URL.String()) writeHeaders(wb, req.Header) arg2Writer, err := call.Arg2Writer() if err != nil { return err } if _, err := wb.FlushTo(arg2Writer); err != nil { return err } if err := arg2Writer.Close(); err != nil { return err } arg3Writer, err := call.Arg3Writer() if err != nil { return err } if req.Body != nil { if _, err = io.Copy(arg3Writer, req.Body); err != nil { return err } } return arg3Writer.Close() }
[ "func", "WriteRequest", "(", "call", "tchannel", ".", "ArgWritable", ",", "req", "*", "http", ".", "Request", ")", "error", "{", "wb", ":=", "typed", ".", "NewWriteBufferWithSize", "(", "10000", ")", "\n", "wb", ".", "WriteLen8String", "(", "req", ".", "Method", ")", "\n", "writeVarintString", "(", "wb", ",", "req", ".", "URL", ".", "String", "(", ")", ")", "\n", "writeHeaders", "(", "wb", ",", "req", ".", "Header", ")", "\n", "arg2Writer", ",", "err", ":=", "call", ".", "Arg2Writer", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "_", ",", "err", ":=", "wb", ".", "FlushTo", "(", "arg2Writer", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "arg2Writer", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "arg3Writer", ",", "err", ":=", "call", ".", "Arg3Writer", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "req", ".", "Body", "!=", "nil", "{", "if", "_", ",", "err", "=", "io", ".", "Copy", "(", "arg3Writer", ",", "req", ".", "Body", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "arg3Writer", ".", "Close", "(", ")", "\n", "}" ]
// WriteRequest writes a http.Request to the given writers.
[ "WriteRequest", "writes", "a", "http", ".", "Request", "to", "the", "given", "writers", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/http/request.go#L32-L61
test
uber/tchannel-go
http/request.go
ReadRequest
func ReadRequest(call tchannel.ArgReadable) (*http.Request, error) { var arg2 []byte if err := tchannel.NewArgReader(call.Arg2Reader()).Read(&arg2); err != nil { return nil, err } rb := typed.NewReadBuffer(arg2) method := rb.ReadLen8String() url := readVarintString(rb) r, err := http.NewRequest(method, url, nil) if err != nil { return nil, err } readHeaders(rb, r.Header) if err := rb.Err(); err != nil { return nil, err } r.Body, err = call.Arg3Reader() return r, err }
go
func ReadRequest(call tchannel.ArgReadable) (*http.Request, error) { var arg2 []byte if err := tchannel.NewArgReader(call.Arg2Reader()).Read(&arg2); err != nil { return nil, err } rb := typed.NewReadBuffer(arg2) method := rb.ReadLen8String() url := readVarintString(rb) r, err := http.NewRequest(method, url, nil) if err != nil { return nil, err } readHeaders(rb, r.Header) if err := rb.Err(); err != nil { return nil, err } r.Body, err = call.Arg3Reader() return r, err }
[ "func", "ReadRequest", "(", "call", "tchannel", ".", "ArgReadable", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "var", "arg2", "[", "]", "byte", "\n", "if", "err", ":=", "tchannel", ".", "NewArgReader", "(", "call", ".", "Arg2Reader", "(", ")", ")", ".", "Read", "(", "&", "arg2", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "rb", ":=", "typed", ".", "NewReadBuffer", "(", "arg2", ")", "\n", "method", ":=", "rb", ".", "ReadLen8String", "(", ")", "\n", "url", ":=", "readVarintString", "(", "rb", ")", "\n", "r", ",", "err", ":=", "http", ".", "NewRequest", "(", "method", ",", "url", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "readHeaders", "(", "rb", ",", "r", ".", "Header", ")", "\n", "if", "err", ":=", "rb", ".", "Err", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "r", ".", "Body", ",", "err", "=", "call", ".", "Arg3Reader", "(", ")", "\n", "return", "r", ",", "err", "\n", "}" ]
// ReadRequest reads a http.Request from the given readers.
[ "ReadRequest", "reads", "a", "http", ".", "Request", "from", "the", "given", "readers", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/http/request.go#L64-L85
test
uber/tchannel-go
typed/buffer.go
NewReadBufferWithSize
func NewReadBufferWithSize(size int) *ReadBuffer { return &ReadBuffer{buffer: make([]byte, size), remaining: nil} }
go
func NewReadBufferWithSize(size int) *ReadBuffer { return &ReadBuffer{buffer: make([]byte, size), remaining: nil} }
[ "func", "NewReadBufferWithSize", "(", "size", "int", ")", "*", "ReadBuffer", "{", "return", "&", "ReadBuffer", "{", "buffer", ":", "make", "(", "[", "]", "byte", ",", "size", ")", ",", "remaining", ":", "nil", "}", "\n", "}" ]
// NewReadBufferWithSize returns a ReadBuffer with a given capacity
[ "NewReadBufferWithSize", "returns", "a", "ReadBuffer", "with", "a", "given", "capacity" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L56-L58
test
uber/tchannel-go
typed/buffer.go
ReadByte
func (r *ReadBuffer) ReadByte() (byte, error) { if r.err != nil { return 0, r.err } if len(r.remaining) < 1 { r.err = ErrEOF return 0, r.err } b := r.remaining[0] r.remaining = r.remaining[1:] return b, nil }
go
func (r *ReadBuffer) ReadByte() (byte, error) { if r.err != nil { return 0, r.err } if len(r.remaining) < 1 { r.err = ErrEOF return 0, r.err } b := r.remaining[0] r.remaining = r.remaining[1:] return b, nil }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadByte", "(", ")", "(", "byte", ",", "error", ")", "{", "if", "r", ".", "err", "!=", "nil", "{", "return", "0", ",", "r", ".", "err", "\n", "}", "\n", "if", "len", "(", "r", ".", "remaining", ")", "<", "1", "{", "r", ".", "err", "=", "ErrEOF", "\n", "return", "0", ",", "r", ".", "err", "\n", "}", "\n", "b", ":=", "r", ".", "remaining", "[", "0", "]", "\n", "r", ".", "remaining", "=", "r", ".", "remaining", "[", "1", ":", "]", "\n", "return", "b", ",", "nil", "\n", "}" ]
// ReadByte returns the next byte from the buffer.
[ "ReadByte", "returns", "the", "next", "byte", "from", "the", "buffer", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L67-L80
test
uber/tchannel-go
typed/buffer.go
ReadBytes
func (r *ReadBuffer) ReadBytes(n int) []byte { if r.err != nil { return nil } if len(r.remaining) < n { r.err = ErrEOF return nil } b := r.remaining[0:n] r.remaining = r.remaining[n:] return b }
go
func (r *ReadBuffer) ReadBytes(n int) []byte { if r.err != nil { return nil } if len(r.remaining) < n { r.err = ErrEOF return nil } b := r.remaining[0:n] r.remaining = r.remaining[n:] return b }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadBytes", "(", "n", "int", ")", "[", "]", "byte", "{", "if", "r", ".", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "len", "(", "r", ".", "remaining", ")", "<", "n", "{", "r", ".", "err", "=", "ErrEOF", "\n", "return", "nil", "\n", "}", "\n", "b", ":=", "r", ".", "remaining", "[", "0", ":", "n", "]", "\n", "r", ".", "remaining", "=", "r", ".", "remaining", "[", "n", ":", "]", "\n", "return", "b", "\n", "}" ]
// ReadBytes returns the next n bytes from the buffer
[ "ReadBytes", "returns", "the", "next", "n", "bytes", "from", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L83-L96
test
uber/tchannel-go
typed/buffer.go
ReadString
func (r *ReadBuffer) ReadString(n int) string { if b := r.ReadBytes(n); b != nil { // TODO(mmihic): This creates a copy, which sucks return string(b) } return "" }
go
func (r *ReadBuffer) ReadString(n int) string { if b := r.ReadBytes(n); b != nil { // TODO(mmihic): This creates a copy, which sucks return string(b) } return "" }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadString", "(", "n", "int", ")", "string", "{", "if", "b", ":=", "r", ".", "ReadBytes", "(", "n", ")", ";", "b", "!=", "nil", "{", "return", "string", "(", "b", ")", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// ReadString returns a string of size n from the buffer
[ "ReadString", "returns", "a", "string", "of", "size", "n", "from", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L99-L106
test
uber/tchannel-go
typed/buffer.go
ReadUint16
func (r *ReadBuffer) ReadUint16() uint16 { if b := r.ReadBytes(2); b != nil { return binary.BigEndian.Uint16(b) } return 0 }
go
func (r *ReadBuffer) ReadUint16() uint16 { if b := r.ReadBytes(2); b != nil { return binary.BigEndian.Uint16(b) } return 0 }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadUint16", "(", ")", "uint16", "{", "if", "b", ":=", "r", ".", "ReadBytes", "(", "2", ")", ";", "b", "!=", "nil", "{", "return", "binary", ".", "BigEndian", ".", "Uint16", "(", "b", ")", "\n", "}", "\n", "return", "0", "\n", "}" ]
// ReadUint16 returns the next value in the buffer as a uint16
[ "ReadUint16", "returns", "the", "next", "value", "in", "the", "buffer", "as", "a", "uint16" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L109-L115
test
uber/tchannel-go
typed/buffer.go
ReadUint32
func (r *ReadBuffer) ReadUint32() uint32 { if b := r.ReadBytes(4); b != nil { return binary.BigEndian.Uint32(b) } return 0 }
go
func (r *ReadBuffer) ReadUint32() uint32 { if b := r.ReadBytes(4); b != nil { return binary.BigEndian.Uint32(b) } return 0 }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadUint32", "(", ")", "uint32", "{", "if", "b", ":=", "r", ".", "ReadBytes", "(", "4", ")", ";", "b", "!=", "nil", "{", "return", "binary", ".", "BigEndian", ".", "Uint32", "(", "b", ")", "\n", "}", "\n", "return", "0", "\n", "}" ]
// ReadUint32 returns the next value in the buffer as a uint32
[ "ReadUint32", "returns", "the", "next", "value", "in", "the", "buffer", "as", "a", "uint32" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L118-L124
test
uber/tchannel-go
typed/buffer.go
ReadUint64
func (r *ReadBuffer) ReadUint64() uint64 { if b := r.ReadBytes(8); b != nil { return binary.BigEndian.Uint64(b) } return 0 }
go
func (r *ReadBuffer) ReadUint64() uint64 { if b := r.ReadBytes(8); b != nil { return binary.BigEndian.Uint64(b) } return 0 }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadUint64", "(", ")", "uint64", "{", "if", "b", ":=", "r", ".", "ReadBytes", "(", "8", ")", ";", "b", "!=", "nil", "{", "return", "binary", ".", "BigEndian", ".", "Uint64", "(", "b", ")", "\n", "}", "\n", "return", "0", "\n", "}" ]
// ReadUint64 returns the next value in the buffer as a uint64
[ "ReadUint64", "returns", "the", "next", "value", "in", "the", "buffer", "as", "a", "uint64" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L127-L133
test
uber/tchannel-go
typed/buffer.go
ReadUvarint
func (r *ReadBuffer) ReadUvarint() uint64 { v, _ := binary.ReadUvarint(r) return v }
go
func (r *ReadBuffer) ReadUvarint() uint64 { v, _ := binary.ReadUvarint(r) return v }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadUvarint", "(", ")", "uint64", "{", "v", ",", "_", ":=", "binary", ".", "ReadUvarint", "(", "r", ")", "\n", "return", "v", "\n", "}" ]
// ReadUvarint reads an unsigned varint from the buffer.
[ "ReadUvarint", "reads", "an", "unsigned", "varint", "from", "the", "buffer", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L136-L139
test
uber/tchannel-go
typed/buffer.go
ReadLen8String
func (r *ReadBuffer) ReadLen8String() string { n := r.ReadSingleByte() return r.ReadString(int(n)) }
go
func (r *ReadBuffer) ReadLen8String() string { n := r.ReadSingleByte() return r.ReadString(int(n)) }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadLen8String", "(", ")", "string", "{", "n", ":=", "r", ".", "ReadSingleByte", "(", ")", "\n", "return", "r", ".", "ReadString", "(", "int", "(", "n", ")", ")", "\n", "}" ]
// ReadLen8String reads an 8-bit length preceded string value
[ "ReadLen8String", "reads", "an", "8", "-", "bit", "length", "preceded", "string", "value" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L142-L145
test
uber/tchannel-go
typed/buffer.go
ReadLen16String
func (r *ReadBuffer) ReadLen16String() string { n := r.ReadUint16() return r.ReadString(int(n)) }
go
func (r *ReadBuffer) ReadLen16String() string { n := r.ReadUint16() return r.ReadString(int(n)) }
[ "func", "(", "r", "*", "ReadBuffer", ")", "ReadLen16String", "(", ")", "string", "{", "n", ":=", "r", ".", "ReadUint16", "(", ")", "\n", "return", "r", ".", "ReadString", "(", "int", "(", "n", ")", ")", "\n", "}" ]
// ReadLen16String reads a 16-bit length preceded string value
[ "ReadLen16String", "reads", "a", "16", "-", "bit", "length", "preceded", "string", "value" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L148-L151
test
uber/tchannel-go
typed/buffer.go
FillFrom
func (r *ReadBuffer) FillFrom(ior io.Reader, n int) (int, error) { if len(r.buffer) < n { return 0, ErrEOF } r.err = nil r.remaining = r.buffer[:n] return io.ReadFull(ior, r.remaining) }
go
func (r *ReadBuffer) FillFrom(ior io.Reader, n int) (int, error) { if len(r.buffer) < n { return 0, ErrEOF } r.err = nil r.remaining = r.buffer[:n] return io.ReadFull(ior, r.remaining) }
[ "func", "(", "r", "*", "ReadBuffer", ")", "FillFrom", "(", "ior", "io", ".", "Reader", ",", "n", "int", ")", "(", "int", ",", "error", ")", "{", "if", "len", "(", "r", ".", "buffer", ")", "<", "n", "{", "return", "0", ",", "ErrEOF", "\n", "}", "\n", "r", ".", "err", "=", "nil", "\n", "r", ".", "remaining", "=", "r", ".", "buffer", "[", ":", "n", "]", "\n", "return", "io", ".", "ReadFull", "(", "ior", ",", "r", ".", "remaining", ")", "\n", "}" ]
// FillFrom fills the buffer from a reader
[ "FillFrom", "fills", "the", "buffer", "from", "a", "reader" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L159-L167
test
uber/tchannel-go
typed/buffer.go
Wrap
func (r *ReadBuffer) Wrap(b []byte) { r.buffer = b r.remaining = b r.err = nil }
go
func (r *ReadBuffer) Wrap(b []byte) { r.buffer = b r.remaining = b r.err = nil }
[ "func", "(", "r", "*", "ReadBuffer", ")", "Wrap", "(", "b", "[", "]", "byte", ")", "{", "r", ".", "buffer", "=", "b", "\n", "r", ".", "remaining", "=", "b", "\n", "r", ".", "err", "=", "nil", "\n", "}" ]
// Wrap initializes the buffer to read from the given byte slice
[ "Wrap", "initializes", "the", "buffer", "to", "read", "from", "the", "given", "byte", "slice" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L170-L174
test
uber/tchannel-go
typed/buffer.go
WriteSingleByte
func (w *WriteBuffer) WriteSingleByte(n byte) { if w.err != nil { return } if len(w.remaining) == 0 { w.setErr(ErrBufferFull) return } w.remaining[0] = n w.remaining = w.remaining[1:] }
go
func (w *WriteBuffer) WriteSingleByte(n byte) { if w.err != nil { return } if len(w.remaining) == 0 { w.setErr(ErrBufferFull) return } w.remaining[0] = n w.remaining = w.remaining[1:] }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteSingleByte", "(", "n", "byte", ")", "{", "if", "w", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "len", "(", "w", ".", "remaining", ")", "==", "0", "{", "w", ".", "setErr", "(", "ErrBufferFull", ")", "\n", "return", "\n", "}", "\n", "w", ".", "remaining", "[", "0", "]", "=", "n", "\n", "w", ".", "remaining", "=", "w", ".", "remaining", "[", "1", ":", "]", "\n", "}" ]
// WriteSingleByte writes a single byte to the buffer
[ "WriteSingleByte", "writes", "a", "single", "byte", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L198-L210
test
uber/tchannel-go
typed/buffer.go
WriteBytes
func (w *WriteBuffer) WriteBytes(in []byte) { if b := w.reserve(len(in)); b != nil { copy(b, in) } }
go
func (w *WriteBuffer) WriteBytes(in []byte) { if b := w.reserve(len(in)); b != nil { copy(b, in) } }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteBytes", "(", "in", "[", "]", "byte", ")", "{", "if", "b", ":=", "w", ".", "reserve", "(", "len", "(", "in", ")", ")", ";", "b", "!=", "nil", "{", "copy", "(", "b", ",", "in", ")", "\n", "}", "\n", "}" ]
// WriteBytes writes a slice of bytes to the buffer
[ "WriteBytes", "writes", "a", "slice", "of", "bytes", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L213-L217
test
uber/tchannel-go
typed/buffer.go
WriteUint16
func (w *WriteBuffer) WriteUint16(n uint16) { if b := w.reserve(2); b != nil { binary.BigEndian.PutUint16(b, n) } }
go
func (w *WriteBuffer) WriteUint16(n uint16) { if b := w.reserve(2); b != nil { binary.BigEndian.PutUint16(b, n) } }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteUint16", "(", "n", "uint16", ")", "{", "if", "b", ":=", "w", ".", "reserve", "(", "2", ")", ";", "b", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint16", "(", "b", ",", "n", ")", "\n", "}", "\n", "}" ]
// WriteUint16 writes a big endian encoded uint16 value to the buffer
[ "WriteUint16", "writes", "a", "big", "endian", "encoded", "uint16", "value", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L220-L224
test
uber/tchannel-go
typed/buffer.go
WriteUint32
func (w *WriteBuffer) WriteUint32(n uint32) { if b := w.reserve(4); b != nil { binary.BigEndian.PutUint32(b, n) } }
go
func (w *WriteBuffer) WriteUint32(n uint32) { if b := w.reserve(4); b != nil { binary.BigEndian.PutUint32(b, n) } }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteUint32", "(", "n", "uint32", ")", "{", "if", "b", ":=", "w", ".", "reserve", "(", "4", ")", ";", "b", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint32", "(", "b", ",", "n", ")", "\n", "}", "\n", "}" ]
// WriteUint32 writes a big endian uint32 value to the buffer
[ "WriteUint32", "writes", "a", "big", "endian", "uint32", "value", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L227-L231
test
uber/tchannel-go
typed/buffer.go
WriteUint64
func (w *WriteBuffer) WriteUint64(n uint64) { if b := w.reserve(8); b != nil { binary.BigEndian.PutUint64(b, n) } }
go
func (w *WriteBuffer) WriteUint64(n uint64) { if b := w.reserve(8); b != nil { binary.BigEndian.PutUint64(b, n) } }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteUint64", "(", "n", "uint64", ")", "{", "if", "b", ":=", "w", ".", "reserve", "(", "8", ")", ";", "b", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint64", "(", "b", ",", "n", ")", "\n", "}", "\n", "}" ]
// WriteUint64 writes a big endian uint64 to the buffer
[ "WriteUint64", "writes", "a", "big", "endian", "uint64", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L234-L238
test
uber/tchannel-go
typed/buffer.go
WriteUvarint
func (w *WriteBuffer) WriteUvarint(n uint64) { // A uvarint could be up to 10 bytes long. buf := make([]byte, 10) varBytes := binary.PutUvarint(buf, n) if b := w.reserve(varBytes); b != nil { copy(b, buf[0:varBytes]) } }
go
func (w *WriteBuffer) WriteUvarint(n uint64) { // A uvarint could be up to 10 bytes long. buf := make([]byte, 10) varBytes := binary.PutUvarint(buf, n) if b := w.reserve(varBytes); b != nil { copy(b, buf[0:varBytes]) } }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteUvarint", "(", "n", "uint64", ")", "{", "buf", ":=", "make", "(", "[", "]", "byte", ",", "10", ")", "\n", "varBytes", ":=", "binary", ".", "PutUvarint", "(", "buf", ",", "n", ")", "\n", "if", "b", ":=", "w", ".", "reserve", "(", "varBytes", ")", ";", "b", "!=", "nil", "{", "copy", "(", "b", ",", "buf", "[", "0", ":", "varBytes", "]", ")", "\n", "}", "\n", "}" ]
// WriteUvarint writes an unsigned varint to the buffer
[ "WriteUvarint", "writes", "an", "unsigned", "varint", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L241-L248
test
uber/tchannel-go
typed/buffer.go
WriteString
func (w *WriteBuffer) WriteString(s string) { // NB(mmihic): Don't just call WriteBytes; that will make a double copy // of the string due to the cast if b := w.reserve(len(s)); b != nil { copy(b, s) } }
go
func (w *WriteBuffer) WriteString(s string) { // NB(mmihic): Don't just call WriteBytes; that will make a double copy // of the string due to the cast if b := w.reserve(len(s)); b != nil { copy(b, s) } }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteString", "(", "s", "string", ")", "{", "if", "b", ":=", "w", ".", "reserve", "(", "len", "(", "s", ")", ")", ";", "b", "!=", "nil", "{", "copy", "(", "b", ",", "s", ")", "\n", "}", "\n", "}" ]
// WriteString writes a string to the buffer
[ "WriteString", "writes", "a", "string", "to", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L251-L257
test
uber/tchannel-go
typed/buffer.go
WriteLen8String
func (w *WriteBuffer) WriteLen8String(s string) { if int(byte(len(s))) != len(s) { w.setErr(errStringTooLong) } w.WriteSingleByte(byte(len(s))) w.WriteString(s) }
go
func (w *WriteBuffer) WriteLen8String(s string) { if int(byte(len(s))) != len(s) { w.setErr(errStringTooLong) } w.WriteSingleByte(byte(len(s))) w.WriteString(s) }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteLen8String", "(", "s", "string", ")", "{", "if", "int", "(", "byte", "(", "len", "(", "s", ")", ")", ")", "!=", "len", "(", "s", ")", "{", "w", ".", "setErr", "(", "errStringTooLong", ")", "\n", "}", "\n", "w", ".", "WriteSingleByte", "(", "byte", "(", "len", "(", "s", ")", ")", ")", "\n", "w", ".", "WriteString", "(", "s", ")", "\n", "}" ]
// WriteLen8String writes an 8-bit length preceded string
[ "WriteLen8String", "writes", "an", "8", "-", "bit", "length", "preceded", "string" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L260-L267
test
uber/tchannel-go
typed/buffer.go
WriteLen16String
func (w *WriteBuffer) WriteLen16String(s string) { if int(uint16(len(s))) != len(s) { w.setErr(errStringTooLong) } w.WriteUint16(uint16(len(s))) w.WriteString(s) }
go
func (w *WriteBuffer) WriteLen16String(s string) { if int(uint16(len(s))) != len(s) { w.setErr(errStringTooLong) } w.WriteUint16(uint16(len(s))) w.WriteString(s) }
[ "func", "(", "w", "*", "WriteBuffer", ")", "WriteLen16String", "(", "s", "string", ")", "{", "if", "int", "(", "uint16", "(", "len", "(", "s", ")", ")", ")", "!=", "len", "(", "s", ")", "{", "w", ".", "setErr", "(", "errStringTooLong", ")", "\n", "}", "\n", "w", ".", "WriteUint16", "(", "uint16", "(", "len", "(", "s", ")", ")", ")", "\n", "w", ".", "WriteString", "(", "s", ")", "\n", "}" ]
// WriteLen16String writes a 16-bit length preceded string
[ "WriteLen16String", "writes", "a", "16", "-", "bit", "length", "preceded", "string" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L270-L277
test
uber/tchannel-go
typed/buffer.go
DeferByte
func (w *WriteBuffer) DeferByte() ByteRef { if len(w.remaining) == 0 { w.setErr(ErrBufferFull) return ByteRef(nil) } // Always zero out references, since the caller expects the default to be 0. w.remaining[0] = 0 bufRef := ByteRef(w.remaining[0:]) w.remaining = w.remaining[1:] return bufRef }
go
func (w *WriteBuffer) DeferByte() ByteRef { if len(w.remaining) == 0 { w.setErr(ErrBufferFull) return ByteRef(nil) } // Always zero out references, since the caller expects the default to be 0. w.remaining[0] = 0 bufRef := ByteRef(w.remaining[0:]) w.remaining = w.remaining[1:] return bufRef }
[ "func", "(", "w", "*", "WriteBuffer", ")", "DeferByte", "(", ")", "ByteRef", "{", "if", "len", "(", "w", ".", "remaining", ")", "==", "0", "{", "w", ".", "setErr", "(", "ErrBufferFull", ")", "\n", "return", "ByteRef", "(", "nil", ")", "\n", "}", "\n", "w", ".", "remaining", "[", "0", "]", "=", "0", "\n", "bufRef", ":=", "ByteRef", "(", "w", ".", "remaining", "[", "0", ":", "]", ")", "\n", "w", ".", "remaining", "=", "w", ".", "remaining", "[", "1", ":", "]", "\n", "return", "bufRef", "\n", "}" ]
// DeferByte reserves space in the buffer for a single byte, and returns a // reference that can be used to update that byte later
[ "DeferByte", "reserves", "space", "in", "the", "buffer", "for", "a", "single", "byte", "and", "returns", "a", "reference", "that", "can", "be", "used", "to", "update", "that", "byte", "later" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L281-L292
test
uber/tchannel-go
typed/buffer.go
DeferBytes
func (w *WriteBuffer) DeferBytes(n int) BytesRef { return BytesRef(w.deferred(n)) }
go
func (w *WriteBuffer) DeferBytes(n int) BytesRef { return BytesRef(w.deferred(n)) }
[ "func", "(", "w", "*", "WriteBuffer", ")", "DeferBytes", "(", "n", "int", ")", "BytesRef", "{", "return", "BytesRef", "(", "w", ".", "deferred", "(", "n", ")", ")", "\n", "}" ]
// DeferBytes reserves space in the buffer for a fixed sequence of bytes, and // returns a reference that can be used to update those bytes
[ "DeferBytes", "reserves", "space", "in", "the", "buffer", "for", "a", "fixed", "sequence", "of", "bytes", "and", "returns", "a", "reference", "that", "can", "be", "used", "to", "update", "those", "bytes" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L314-L316
test
uber/tchannel-go
typed/buffer.go
FlushTo
func (w *WriteBuffer) FlushTo(iow io.Writer) (int, error) { dirty := w.buffer[0:w.BytesWritten()] return iow.Write(dirty) }
go
func (w *WriteBuffer) FlushTo(iow io.Writer) (int, error) { dirty := w.buffer[0:w.BytesWritten()] return iow.Write(dirty) }
[ "func", "(", "w", "*", "WriteBuffer", ")", "FlushTo", "(", "iow", "io", ".", "Writer", ")", "(", "int", ",", "error", ")", "{", "dirty", ":=", "w", ".", "buffer", "[", "0", ":", "w", ".", "BytesWritten", "(", ")", "]", "\n", "return", "iow", ".", "Write", "(", "dirty", ")", "\n", "}" ]
// FlushTo flushes the written buffer to the given writer
[ "FlushTo", "flushes", "the", "written", "buffer", "to", "the", "given", "writer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L347-L350
test
uber/tchannel-go
typed/buffer.go
Reset
func (w *WriteBuffer) Reset() { w.remaining = w.buffer w.err = nil }
go
func (w *WriteBuffer) Reset() { w.remaining = w.buffer w.err = nil }
[ "func", "(", "w", "*", "WriteBuffer", ")", "Reset", "(", ")", "{", "w", ".", "remaining", "=", "w", ".", "buffer", "\n", "w", ".", "err", "=", "nil", "\n", "}" ]
// Reset resets the buffer to an empty state, ready for writing
[ "Reset", "resets", "the", "buffer", "to", "an", "empty", "state", "ready", "for", "writing" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L356-L359
test
uber/tchannel-go
typed/buffer.go
Wrap
func (w *WriteBuffer) Wrap(b []byte) { w.buffer = b w.remaining = b }
go
func (w *WriteBuffer) Wrap(b []byte) { w.buffer = b w.remaining = b }
[ "func", "(", "w", "*", "WriteBuffer", ")", "Wrap", "(", "b", "[", "]", "byte", ")", "{", "w", ".", "buffer", "=", "b", "\n", "w", ".", "remaining", "=", "b", "\n", "}" ]
// Wrap initializes the buffer to wrap the given byte slice
[ "Wrap", "initializes", "the", "buffer", "to", "wrap", "the", "given", "byte", "slice" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L374-L377
test
uber/tchannel-go
typed/buffer.go
Update
func (ref Uint16Ref) Update(n uint16) { if ref != nil { binary.BigEndian.PutUint16(ref, n) } }
go
func (ref Uint16Ref) Update(n uint16) { if ref != nil { binary.BigEndian.PutUint16(ref, n) } }
[ "func", "(", "ref", "Uint16Ref", ")", "Update", "(", "n", "uint16", ")", "{", "if", "ref", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint16", "(", "ref", ",", "n", ")", "\n", "}", "\n", "}" ]
// Update updates the uint16 in the buffer
[ "Update", "updates", "the", "uint16", "in", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L393-L397
test
uber/tchannel-go
typed/buffer.go
Update
func (ref Uint32Ref) Update(n uint32) { if ref != nil { binary.BigEndian.PutUint32(ref, n) } }
go
func (ref Uint32Ref) Update(n uint32) { if ref != nil { binary.BigEndian.PutUint32(ref, n) } }
[ "func", "(", "ref", "Uint32Ref", ")", "Update", "(", "n", "uint32", ")", "{", "if", "ref", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint32", "(", "ref", ",", "n", ")", "\n", "}", "\n", "}" ]
// Update updates the uint32 in the buffer
[ "Update", "updates", "the", "uint32", "in", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L403-L407
test
uber/tchannel-go
typed/buffer.go
Update
func (ref Uint64Ref) Update(n uint64) { if ref != nil { binary.BigEndian.PutUint64(ref, n) } }
go
func (ref Uint64Ref) Update(n uint64) { if ref != nil { binary.BigEndian.PutUint64(ref, n) } }
[ "func", "(", "ref", "Uint64Ref", ")", "Update", "(", "n", "uint64", ")", "{", "if", "ref", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint64", "(", "ref", ",", "n", ")", "\n", "}", "\n", "}" ]
// Update updates the uint64 in the buffer
[ "Update", "updates", "the", "uint64", "in", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L413-L417
test
uber/tchannel-go
typed/buffer.go
Update
func (ref BytesRef) Update(b []byte) { if ref != nil { copy(ref, b) } }
go
func (ref BytesRef) Update(b []byte) { if ref != nil { copy(ref, b) } }
[ "func", "(", "ref", "BytesRef", ")", "Update", "(", "b", "[", "]", "byte", ")", "{", "if", "ref", "!=", "nil", "{", "copy", "(", "ref", ",", "b", ")", "\n", "}", "\n", "}" ]
// Update updates the bytes in the buffer
[ "Update", "updates", "the", "bytes", "in", "the", "buffer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L423-L427
test
uber/tchannel-go
typed/buffer.go
UpdateString
func (ref BytesRef) UpdateString(s string) { if ref != nil { copy(ref, s) } }
go
func (ref BytesRef) UpdateString(s string) { if ref != nil { copy(ref, s) } }
[ "func", "(", "ref", "BytesRef", ")", "UpdateString", "(", "s", "string", ")", "{", "if", "ref", "!=", "nil", "{", "copy", "(", "ref", ",", "s", ")", "\n", "}", "\n", "}" ]
// UpdateString updates the bytes in the buffer from a string
[ "UpdateString", "updates", "the", "bytes", "in", "the", "buffer", "from", "a", "string" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/typed/buffer.go#L430-L434
test
uber/tchannel-go
fragmenting_reader.go
ArgReader
func (r *fragmentingReader) ArgReader(last bool) (ArgReader, error) { if err := r.BeginArgument(last); err != nil { return nil, err } return r, nil }
go
func (r *fragmentingReader) ArgReader(last bool) (ArgReader, error) { if err := r.BeginArgument(last); err != nil { return nil, err } return r, nil }
[ "func", "(", "r", "*", "fragmentingReader", ")", "ArgReader", "(", "last", "bool", ")", "(", "ArgReader", ",", "error", ")", "{", "if", "err", ":=", "r", ".", "BeginArgument", "(", "last", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// The ArgReader will handle fragmentation as needed. Once the argument has // been read, the ArgReader must be closed.
[ "The", "ArgReader", "will", "handle", "fragmentation", "as", "needed", ".", "Once", "the", "argument", "has", "been", "read", "the", "ArgReader", "must", "be", "closed", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_reader.go#L105-L110
test
uber/tchannel-go
fragmenting_writer.go
finish
func (f *writableFragment) finish(hasMoreFragments bool) { f.checksumRef.Update(f.checksum.Sum()) if hasMoreFragments { f.flagsRef.Update(hasMoreFragmentsFlag) } else { f.checksum.Release() } }
go
func (f *writableFragment) finish(hasMoreFragments bool) { f.checksumRef.Update(f.checksum.Sum()) if hasMoreFragments { f.flagsRef.Update(hasMoreFragmentsFlag) } else { f.checksum.Release() } }
[ "func", "(", "f", "*", "writableFragment", ")", "finish", "(", "hasMoreFragments", "bool", ")", "{", "f", ".", "checksumRef", ".", "Update", "(", "f", ".", "checksum", ".", "Sum", "(", ")", ")", "\n", "if", "hasMoreFragments", "{", "f", ".", "flagsRef", ".", "Update", "(", "hasMoreFragmentsFlag", ")", "\n", "}", "else", "{", "f", ".", "checksum", ".", "Release", "(", ")", "\n", "}", "\n", "}" ]
// finish finishes the fragment, updating the final checksum and fragment flags
[ "finish", "finishes", "the", "fragment", "updating", "the", "final", "checksum", "and", "fragment", "flags" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L53-L60
test
uber/tchannel-go
fragmenting_writer.go
newWritableChunk
func newWritableChunk(checksum Checksum, contents *typed.WriteBuffer) *writableChunk { return &writableChunk{ size: 0, sizeRef: contents.DeferUint16(), checksum: checksum, contents: contents, } }
go
func newWritableChunk(checksum Checksum, contents *typed.WriteBuffer) *writableChunk { return &writableChunk{ size: 0, sizeRef: contents.DeferUint16(), checksum: checksum, contents: contents, } }
[ "func", "newWritableChunk", "(", "checksum", "Checksum", ",", "contents", "*", "typed", ".", "WriteBuffer", ")", "*", "writableChunk", "{", "return", "&", "writableChunk", "{", "size", ":", "0", ",", "sizeRef", ":", "contents", ".", "DeferUint16", "(", ")", ",", "checksum", ":", "checksum", ",", "contents", ":", "contents", ",", "}", "\n", "}" ]
// newWritableChunk creates a new writable chunk around a checksum and a buffer to hold data
[ "newWritableChunk", "creates", "a", "new", "writable", "chunk", "around", "a", "checksum", "and", "a", "buffer", "to", "hold", "data" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L72-L79
test
uber/tchannel-go
fragmenting_writer.go
writeAsFits
func (c *writableChunk) writeAsFits(b []byte) int { if len(b) > c.contents.BytesRemaining() { b = b[:c.contents.BytesRemaining()] } c.checksum.Add(b) c.contents.WriteBytes(b) written := len(b) c.size += uint16(written) return written }
go
func (c *writableChunk) writeAsFits(b []byte) int { if len(b) > c.contents.BytesRemaining() { b = b[:c.contents.BytesRemaining()] } c.checksum.Add(b) c.contents.WriteBytes(b) written := len(b) c.size += uint16(written) return written }
[ "func", "(", "c", "*", "writableChunk", ")", "writeAsFits", "(", "b", "[", "]", "byte", ")", "int", "{", "if", "len", "(", "b", ")", ">", "c", ".", "contents", ".", "BytesRemaining", "(", ")", "{", "b", "=", "b", "[", ":", "c", ".", "contents", ".", "BytesRemaining", "(", ")", "]", "\n", "}", "\n", "c", ".", "checksum", ".", "Add", "(", "b", ")", "\n", "c", ".", "contents", ".", "WriteBytes", "(", "b", ")", "\n", "written", ":=", "len", "(", "b", ")", "\n", "c", ".", "size", "+=", "uint16", "(", "written", ")", "\n", "return", "written", "\n", "}" ]
// writeAsFits writes as many bytes from the given slice as fits into the chunk
[ "writeAsFits", "writes", "as", "many", "bytes", "from", "the", "given", "slice", "as", "fits", "into", "the", "chunk" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L82-L93
test
uber/tchannel-go
fragmenting_writer.go
newFragmentingWriter
func newFragmentingWriter(logger Logger, sender fragmentSender, checksum Checksum) *fragmentingWriter { return &fragmentingWriter{ logger: logger, sender: sender, checksum: checksum, state: fragmentingWriteStart, } }
go
func newFragmentingWriter(logger Logger, sender fragmentSender, checksum Checksum) *fragmentingWriter { return &fragmentingWriter{ logger: logger, sender: sender, checksum: checksum, state: fragmentingWriteStart, } }
[ "func", "newFragmentingWriter", "(", "logger", "Logger", ",", "sender", "fragmentSender", ",", "checksum", "Checksum", ")", "*", "fragmentingWriter", "{", "return", "&", "fragmentingWriter", "{", "logger", ":", "logger", ",", "sender", ":", "sender", ",", "checksum", ":", "checksum", ",", "state", ":", "fragmentingWriteStart", ",", "}", "\n", "}" ]
// newFragmentingWriter creates a new fragmenting writer
[ "newFragmentingWriter", "creates", "a", "new", "fragmenting", "writer" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L141-L148
test
uber/tchannel-go
fragmenting_writer.go
ArgWriter
func (w *fragmentingWriter) ArgWriter(last bool) (ArgWriter, error) { if err := w.BeginArgument(last); err != nil { return nil, err } return w, nil }
go
func (w *fragmentingWriter) ArgWriter(last bool) (ArgWriter, error) { if err := w.BeginArgument(last); err != nil { return nil, err } return w, nil }
[ "func", "(", "w", "*", "fragmentingWriter", ")", "ArgWriter", "(", "last", "bool", ")", "(", "ArgWriter", ",", "error", ")", "{", "if", "err", ":=", "w", ".", "BeginArgument", "(", "last", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "w", ",", "nil", "\n", "}" ]
// ArgWriter returns an ArgWriter to write an argument. The ArgWriter will handle // fragmentation as needed. Once the argument is written, the ArgWriter must be closed.
[ "ArgWriter", "returns", "an", "ArgWriter", "to", "write", "an", "argument", ".", "The", "ArgWriter", "will", "handle", "fragmentation", "as", "needed", ".", "Once", "the", "argument", "is", "written", "the", "ArgWriter", "must", "be", "closed", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L152-L157
test
uber/tchannel-go
fragmenting_writer.go
BeginArgument
func (w *fragmentingWriter) BeginArgument(last bool) error { if w.err != nil { return w.err } switch { case w.state == fragmentingWriteComplete: w.err = errComplete return w.err case w.state.isWritingArgument(): w.err = errAlreadyWritingArgument return w.err } // If we don't have a fragment, request one if w.curFragment == nil { initial := w.state == fragmentingWriteStart if w.curFragment, w.err = w.sender.newFragment(initial, w.checksum); w.err != nil { return w.err } } // If there's no room in the current fragment, freak out. This will // only happen due to an implementation error in the TChannel stack // itself if w.curFragment.contents.BytesRemaining() <= chunkHeaderSize { panic(fmt.Errorf("attempting to begin an argument in a fragment with only %d bytes available", w.curFragment.contents.BytesRemaining())) } w.curChunk = newWritableChunk(w.checksum, w.curFragment.contents) w.state = fragmentingWriteInArgument if last { w.state = fragmentingWriteInLastArgument } return nil }
go
func (w *fragmentingWriter) BeginArgument(last bool) error { if w.err != nil { return w.err } switch { case w.state == fragmentingWriteComplete: w.err = errComplete return w.err case w.state.isWritingArgument(): w.err = errAlreadyWritingArgument return w.err } // If we don't have a fragment, request one if w.curFragment == nil { initial := w.state == fragmentingWriteStart if w.curFragment, w.err = w.sender.newFragment(initial, w.checksum); w.err != nil { return w.err } } // If there's no room in the current fragment, freak out. This will // only happen due to an implementation error in the TChannel stack // itself if w.curFragment.contents.BytesRemaining() <= chunkHeaderSize { panic(fmt.Errorf("attempting to begin an argument in a fragment with only %d bytes available", w.curFragment.contents.BytesRemaining())) } w.curChunk = newWritableChunk(w.checksum, w.curFragment.contents) w.state = fragmentingWriteInArgument if last { w.state = fragmentingWriteInLastArgument } return nil }
[ "func", "(", "w", "*", "fragmentingWriter", ")", "BeginArgument", "(", "last", "bool", ")", "error", "{", "if", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "switch", "{", "case", "w", ".", "state", "==", "fragmentingWriteComplete", ":", "w", ".", "err", "=", "errComplete", "\n", "return", "w", ".", "err", "\n", "case", "w", ".", "state", ".", "isWritingArgument", "(", ")", ":", "w", ".", "err", "=", "errAlreadyWritingArgument", "\n", "return", "w", ".", "err", "\n", "}", "\n", "if", "w", ".", "curFragment", "==", "nil", "{", "initial", ":=", "w", ".", "state", "==", "fragmentingWriteStart", "\n", "if", "w", ".", "curFragment", ",", "w", ".", "err", "=", "w", ".", "sender", ".", "newFragment", "(", "initial", ",", "w", ".", "checksum", ")", ";", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "}", "\n", "if", "w", ".", "curFragment", ".", "contents", ".", "BytesRemaining", "(", ")", "<=", "chunkHeaderSize", "{", "panic", "(", "fmt", ".", "Errorf", "(", "\"attempting to begin an argument in a fragment with only %d bytes available\"", ",", "w", ".", "curFragment", ".", "contents", ".", "BytesRemaining", "(", ")", ")", ")", "\n", "}", "\n", "w", ".", "curChunk", "=", "newWritableChunk", "(", "w", ".", "checksum", ",", "w", ".", "curFragment", ".", "contents", ")", "\n", "w", ".", "state", "=", "fragmentingWriteInArgument", "\n", "if", "last", "{", "w", ".", "state", "=", "fragmentingWriteInLastArgument", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// BeginArgument tells the writer that the caller is starting a new argument. // Must not be called while an existing argument is in place
[ "BeginArgument", "tells", "the", "writer", "that", "the", "caller", "is", "starting", "a", "new", "argument", ".", "Must", "not", "be", "called", "while", "an", "existing", "argument", "is", "in", "place" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L161-L197
test
uber/tchannel-go
fragmenting_writer.go
Write
func (w *fragmentingWriter) Write(b []byte) (int, error) { if w.err != nil { return 0, w.err } if !w.state.isWritingArgument() { w.err = errNotWritingArgument return 0, w.err } totalWritten := 0 for { bytesWritten := w.curChunk.writeAsFits(b) totalWritten += bytesWritten if bytesWritten == len(b) { // The whole thing fit, we're done return totalWritten, nil } // There was more data than fit into the fragment, so flush the current fragment, // start a new fragment and chunk, and continue writing if w.err = w.Flush(); w.err != nil { return totalWritten, w.err } b = b[bytesWritten:] } }
go
func (w *fragmentingWriter) Write(b []byte) (int, error) { if w.err != nil { return 0, w.err } if !w.state.isWritingArgument() { w.err = errNotWritingArgument return 0, w.err } totalWritten := 0 for { bytesWritten := w.curChunk.writeAsFits(b) totalWritten += bytesWritten if bytesWritten == len(b) { // The whole thing fit, we're done return totalWritten, nil } // There was more data than fit into the fragment, so flush the current fragment, // start a new fragment and chunk, and continue writing if w.err = w.Flush(); w.err != nil { return totalWritten, w.err } b = b[bytesWritten:] } }
[ "func", "(", "w", "*", "fragmentingWriter", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "if", "w", ".", "err", "!=", "nil", "{", "return", "0", ",", "w", ".", "err", "\n", "}", "\n", "if", "!", "w", ".", "state", ".", "isWritingArgument", "(", ")", "{", "w", ".", "err", "=", "errNotWritingArgument", "\n", "return", "0", ",", "w", ".", "err", "\n", "}", "\n", "totalWritten", ":=", "0", "\n", "for", "{", "bytesWritten", ":=", "w", ".", "curChunk", ".", "writeAsFits", "(", "b", ")", "\n", "totalWritten", "+=", "bytesWritten", "\n", "if", "bytesWritten", "==", "len", "(", "b", ")", "{", "return", "totalWritten", ",", "nil", "\n", "}", "\n", "if", "w", ".", "err", "=", "w", ".", "Flush", "(", ")", ";", "w", ".", "err", "!=", "nil", "{", "return", "totalWritten", ",", "w", ".", "err", "\n", "}", "\n", "b", "=", "b", "[", "bytesWritten", ":", "]", "\n", "}", "\n", "}" ]
// Write writes argument data, breaking it into fragments as needed
[ "Write", "writes", "argument", "data", "breaking", "it", "into", "fragments", "as", "needed" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L200-L227
test
uber/tchannel-go
fragmenting_writer.go
Flush
func (w *fragmentingWriter) Flush() error { w.curChunk.finish() w.curFragment.finish(true) if w.err = w.sender.flushFragment(w.curFragment); w.err != nil { return w.err } if w.curFragment, w.err = w.sender.newFragment(false, w.checksum); w.err != nil { return w.err } w.curChunk = newWritableChunk(w.checksum, w.curFragment.contents) return nil }
go
func (w *fragmentingWriter) Flush() error { w.curChunk.finish() w.curFragment.finish(true) if w.err = w.sender.flushFragment(w.curFragment); w.err != nil { return w.err } if w.curFragment, w.err = w.sender.newFragment(false, w.checksum); w.err != nil { return w.err } w.curChunk = newWritableChunk(w.checksum, w.curFragment.contents) return nil }
[ "func", "(", "w", "*", "fragmentingWriter", ")", "Flush", "(", ")", "error", "{", "w", ".", "curChunk", ".", "finish", "(", ")", "\n", "w", ".", "curFragment", ".", "finish", "(", "true", ")", "\n", "if", "w", ".", "err", "=", "w", ".", "sender", ".", "flushFragment", "(", "w", ".", "curFragment", ")", ";", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "if", "w", ".", "curFragment", ",", "w", ".", "err", "=", "w", ".", "sender", ".", "newFragment", "(", "false", ",", "w", ".", "checksum", ")", ";", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "w", ".", "curChunk", "=", "newWritableChunk", "(", "w", ".", "checksum", ",", "w", ".", "curFragment", ".", "contents", ")", "\n", "return", "nil", "\n", "}" ]
// Flush flushes the current fragment, and starts a new fragment and chunk.
[ "Flush", "flushes", "the", "current", "fragment", "and", "starts", "a", "new", "fragment", "and", "chunk", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L230-L243
test
uber/tchannel-go
fragmenting_writer.go
Close
func (w *fragmentingWriter) Close() error { last := w.state == fragmentingWriteInLastArgument if w.err != nil { return w.err } if !w.state.isWritingArgument() { w.err = errNotWritingArgument return w.err } w.curChunk.finish() // There are three possibilities here: // 1. There are no more arguments // flush with more_fragments=false, mark the stream as complete // 2. There are more arguments, but we can't fit more data into this fragment // flush with more_fragments=true, start new fragment, write empty chunk to indicate // the current argument is complete // 3. There are more arguments, and we can fit more data into this fragment // update the chunk but leave the current fragment open if last { // No more arguments - flush this final fragment and mark ourselves complete w.state = fragmentingWriteComplete w.curFragment.finish(false) w.err = w.sender.flushFragment(w.curFragment) w.sender.doneSending() return w.err } w.state = fragmentingWriteWaitingForArgument if w.curFragment.contents.BytesRemaining() > chunkHeaderSize { // There's enough room in this fragment for the next argument's // initial chunk, so we're done here return nil } // This fragment is full - flush and prepare for another argument w.curFragment.finish(true) if w.err = w.sender.flushFragment(w.curFragment); w.err != nil { return w.err } if w.curFragment, w.err = w.sender.newFragment(false, w.checksum); w.err != nil { return w.err } // Write an empty chunk to indicate this argument has ended w.curFragment.contents.WriteUint16(0) return nil }
go
func (w *fragmentingWriter) Close() error { last := w.state == fragmentingWriteInLastArgument if w.err != nil { return w.err } if !w.state.isWritingArgument() { w.err = errNotWritingArgument return w.err } w.curChunk.finish() // There are three possibilities here: // 1. There are no more arguments // flush with more_fragments=false, mark the stream as complete // 2. There are more arguments, but we can't fit more data into this fragment // flush with more_fragments=true, start new fragment, write empty chunk to indicate // the current argument is complete // 3. There are more arguments, and we can fit more data into this fragment // update the chunk but leave the current fragment open if last { // No more arguments - flush this final fragment and mark ourselves complete w.state = fragmentingWriteComplete w.curFragment.finish(false) w.err = w.sender.flushFragment(w.curFragment) w.sender.doneSending() return w.err } w.state = fragmentingWriteWaitingForArgument if w.curFragment.contents.BytesRemaining() > chunkHeaderSize { // There's enough room in this fragment for the next argument's // initial chunk, so we're done here return nil } // This fragment is full - flush and prepare for another argument w.curFragment.finish(true) if w.err = w.sender.flushFragment(w.curFragment); w.err != nil { return w.err } if w.curFragment, w.err = w.sender.newFragment(false, w.checksum); w.err != nil { return w.err } // Write an empty chunk to indicate this argument has ended w.curFragment.contents.WriteUint16(0) return nil }
[ "func", "(", "w", "*", "fragmentingWriter", ")", "Close", "(", ")", "error", "{", "last", ":=", "w", ".", "state", "==", "fragmentingWriteInLastArgument", "\n", "if", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "if", "!", "w", ".", "state", ".", "isWritingArgument", "(", ")", "{", "w", ".", "err", "=", "errNotWritingArgument", "\n", "return", "w", ".", "err", "\n", "}", "\n", "w", ".", "curChunk", ".", "finish", "(", ")", "\n", "if", "last", "{", "w", ".", "state", "=", "fragmentingWriteComplete", "\n", "w", ".", "curFragment", ".", "finish", "(", "false", ")", "\n", "w", ".", "err", "=", "w", ".", "sender", ".", "flushFragment", "(", "w", ".", "curFragment", ")", "\n", "w", ".", "sender", ".", "doneSending", "(", ")", "\n", "return", "w", ".", "err", "\n", "}", "\n", "w", ".", "state", "=", "fragmentingWriteWaitingForArgument", "\n", "if", "w", ".", "curFragment", ".", "contents", ".", "BytesRemaining", "(", ")", ">", "chunkHeaderSize", "{", "return", "nil", "\n", "}", "\n", "w", ".", "curFragment", ".", "finish", "(", "true", ")", "\n", "if", "w", ".", "err", "=", "w", ".", "sender", ".", "flushFragment", "(", "w", ".", "curFragment", ")", ";", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "if", "w", ".", "curFragment", ",", "w", ".", "err", "=", "w", ".", "sender", ".", "newFragment", "(", "false", ",", "w", ".", "checksum", ")", ";", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "w", ".", "curFragment", ".", "contents", ".", "WriteUint16", "(", "0", ")", "\n", "return", "nil", "\n", "}" ]
// Close ends the current argument.
[ "Close", "ends", "the", "current", "argument", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/fragmenting_writer.go#L246-L296
test
uber/tchannel-go
outbound.go
handleCallRes
func (c *Connection) handleCallRes(frame *Frame) bool { if err := c.outbound.forwardPeerFrame(frame); err != nil { return true } return false }
go
func (c *Connection) handleCallRes(frame *Frame) bool { if err := c.outbound.forwardPeerFrame(frame); err != nil { return true } return false }
[ "func", "(", "c", "*", "Connection", ")", "handleCallRes", "(", "frame", "*", "Frame", ")", "bool", "{", "if", "err", ":=", "c", ".", "outbound", ".", "forwardPeerFrame", "(", "frame", ")", ";", "err", "!=", "nil", "{", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// handleCallRes handles an incoming call req message, forwarding the // frame to the response channel waiting for it
[ "handleCallRes", "handles", "an", "incoming", "call", "req", "message", "forwarding", "the", "frame", "to", "the", "response", "channel", "waiting", "for", "it" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/outbound.go#L142-L147
test
uber/tchannel-go
outbound.go
Arg2Reader
func (response *OutboundCallResponse) Arg2Reader() (ArgReader, error) { var method []byte if err := NewArgReader(response.arg1Reader()).Read(&method); err != nil { return nil, err } return response.arg2Reader() }
go
func (response *OutboundCallResponse) Arg2Reader() (ArgReader, error) { var method []byte if err := NewArgReader(response.arg1Reader()).Read(&method); err != nil { return nil, err } return response.arg2Reader() }
[ "func", "(", "response", "*", "OutboundCallResponse", ")", "Arg2Reader", "(", ")", "(", "ArgReader", ",", "error", ")", "{", "var", "method", "[", "]", "byte", "\n", "if", "err", ":=", "NewArgReader", "(", "response", ".", "arg1Reader", "(", ")", ")", ".", "Read", "(", "&", "method", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "response", ".", "arg2Reader", "(", ")", "\n", "}" ]
// Arg2Reader returns an ArgReader to read the second argument. // The ReadCloser must be closed once the argument has been read.
[ "Arg2Reader", "returns", "an", "ArgReader", "to", "read", "the", "second", "argument", ".", "The", "ReadCloser", "must", "be", "closed", "once", "the", "argument", "has", "been", "read", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/outbound.go#L251-L258
test
uber/tchannel-go
outbound.go
handleError
func (c *Connection) handleError(frame *Frame) bool { errMsg := errorMessage{ id: frame.Header.ID, } rbuf := typed.NewReadBuffer(frame.SizedPayload()) if err := errMsg.read(rbuf); err != nil { c.log.WithFields( LogField{"remotePeer", c.remotePeerInfo}, ErrField(err), ).Warn("Unable to read error frame.") c.connectionError("parsing error frame", err) return true } if errMsg.errCode == ErrCodeProtocol { c.log.WithFields( LogField{"remotePeer", c.remotePeerInfo}, LogField{"error", errMsg.message}, ).Warn("Peer reported protocol error.") c.connectionError("received protocol error", errMsg.AsSystemError()) return true } if err := c.outbound.forwardPeerFrame(frame); err != nil { c.log.WithFields( LogField{"frameHeader", frame.Header.String()}, LogField{"id", errMsg.id}, LogField{"errorMessage", errMsg.message}, LogField{"errorCode", errMsg.errCode}, ErrField(err), ).Info("Failed to forward error frame.") return true } // If the frame was forwarded, then the other side is responsible for releasing the frame. return false }
go
func (c *Connection) handleError(frame *Frame) bool { errMsg := errorMessage{ id: frame.Header.ID, } rbuf := typed.NewReadBuffer(frame.SizedPayload()) if err := errMsg.read(rbuf); err != nil { c.log.WithFields( LogField{"remotePeer", c.remotePeerInfo}, ErrField(err), ).Warn("Unable to read error frame.") c.connectionError("parsing error frame", err) return true } if errMsg.errCode == ErrCodeProtocol { c.log.WithFields( LogField{"remotePeer", c.remotePeerInfo}, LogField{"error", errMsg.message}, ).Warn("Peer reported protocol error.") c.connectionError("received protocol error", errMsg.AsSystemError()) return true } if err := c.outbound.forwardPeerFrame(frame); err != nil { c.log.WithFields( LogField{"frameHeader", frame.Header.String()}, LogField{"id", errMsg.id}, LogField{"errorMessage", errMsg.message}, LogField{"errorCode", errMsg.errCode}, ErrField(err), ).Info("Failed to forward error frame.") return true } // If the frame was forwarded, then the other side is responsible for releasing the frame. return false }
[ "func", "(", "c", "*", "Connection", ")", "handleError", "(", "frame", "*", "Frame", ")", "bool", "{", "errMsg", ":=", "errorMessage", "{", "id", ":", "frame", ".", "Header", ".", "ID", ",", "}", "\n", "rbuf", ":=", "typed", ".", "NewReadBuffer", "(", "frame", ".", "SizedPayload", "(", ")", ")", "\n", "if", "err", ":=", "errMsg", ".", "read", "(", "rbuf", ")", ";", "err", "!=", "nil", "{", "c", ".", "log", ".", "WithFields", "(", "LogField", "{", "\"remotePeer\"", ",", "c", ".", "remotePeerInfo", "}", ",", "ErrField", "(", "err", ")", ",", ")", ".", "Warn", "(", "\"Unable to read error frame.\"", ")", "\n", "c", ".", "connectionError", "(", "\"parsing error frame\"", ",", "err", ")", "\n", "return", "true", "\n", "}", "\n", "if", "errMsg", ".", "errCode", "==", "ErrCodeProtocol", "{", "c", ".", "log", ".", "WithFields", "(", "LogField", "{", "\"remotePeer\"", ",", "c", ".", "remotePeerInfo", "}", ",", "LogField", "{", "\"error\"", ",", "errMsg", ".", "message", "}", ",", ")", ".", "Warn", "(", "\"Peer reported protocol error.\"", ")", "\n", "c", ".", "connectionError", "(", "\"received protocol error\"", ",", "errMsg", ".", "AsSystemError", "(", ")", ")", "\n", "return", "true", "\n", "}", "\n", "if", "err", ":=", "c", ".", "outbound", ".", "forwardPeerFrame", "(", "frame", ")", ";", "err", "!=", "nil", "{", "c", ".", "log", ".", "WithFields", "(", "LogField", "{", "\"frameHeader\"", ",", "frame", ".", "Header", ".", "String", "(", ")", "}", ",", "LogField", "{", "\"id\"", ",", "errMsg", ".", "id", "}", ",", "LogField", "{", "\"errorMessage\"", ",", "errMsg", ".", "message", "}", ",", "LogField", "{", "\"errorCode\"", ",", "errMsg", ".", "errCode", "}", ",", "ErrField", "(", "err", ")", ",", ")", ".", "Info", "(", "\"Failed to forward error frame.\"", ")", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// handleError handles an error coming back from the peer. If the error is a // protocol level error, the entire connection will be closed. If the error is // a request specific error, it will be written to the request's response // channel and converted into a SystemError returned from the next reader or // access call. // The return value is whether the frame should be released immediately.
[ "handleError", "handles", "an", "error", "coming", "back", "from", "the", "peer", ".", "If", "the", "error", "is", "a", "protocol", "level", "error", "the", "entire", "connection", "will", "be", "closed", ".", "If", "the", "error", "is", "a", "request", "specific", "error", "it", "will", "be", "written", "to", "the", "request", "s", "response", "channel", "and", "converted", "into", "a", "SystemError", "returned", "from", "the", "next", "reader", "or", "access", "call", ".", "The", "return", "value", "is", "whether", "the", "frame", "should", "be", "released", "immediately", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/outbound.go#L272-L308
test
uber/tchannel-go
outbound.go
doneReading
func (response *OutboundCallResponse) doneReading(unexpected error) { now := response.timeNow() isSuccess := unexpected == nil && !response.ApplicationError() lastAttempt := isSuccess || !response.requestState.HasRetries(unexpected) // TODO how should this work with retries? if span := response.span; span != nil { if unexpected != nil { span.LogEventWithPayload("error", unexpected) } if !isSuccess && lastAttempt { ext.Error.Set(span, true) } span.FinishWithOptions(opentracing.FinishOptions{FinishTime: now}) } latency := now.Sub(response.startedAt) response.statsReporter.RecordTimer("outbound.calls.per-attempt.latency", response.commonStatsTags, latency) if lastAttempt { requestLatency := response.requestState.SinceStart(now, latency) response.statsReporter.RecordTimer("outbound.calls.latency", response.commonStatsTags, requestLatency) } if retryCount := response.requestState.RetryCount(); retryCount > 0 { retryTags := cloneTags(response.commonStatsTags) retryTags["retry-count"] = fmt.Sprint(retryCount) response.statsReporter.IncCounter("outbound.calls.retries", retryTags, 1) } if unexpected != nil { // TODO(prashant): Report the error code type as per metrics doc and enable. // response.statsReporter.IncCounter("outbound.calls.system-errors", response.commonStatsTags, 1) } else if response.ApplicationError() { // TODO(prashant): Figure out how to add "type" to tags, which TChannel does not know about. response.statsReporter.IncCounter("outbound.calls.per-attempt.app-errors", response.commonStatsTags, 1) if lastAttempt { response.statsReporter.IncCounter("outbound.calls.app-errors", response.commonStatsTags, 1) } } else { response.statsReporter.IncCounter("outbound.calls.success", response.commonStatsTags, 1) } response.mex.shutdown() }
go
func (response *OutboundCallResponse) doneReading(unexpected error) { now := response.timeNow() isSuccess := unexpected == nil && !response.ApplicationError() lastAttempt := isSuccess || !response.requestState.HasRetries(unexpected) // TODO how should this work with retries? if span := response.span; span != nil { if unexpected != nil { span.LogEventWithPayload("error", unexpected) } if !isSuccess && lastAttempt { ext.Error.Set(span, true) } span.FinishWithOptions(opentracing.FinishOptions{FinishTime: now}) } latency := now.Sub(response.startedAt) response.statsReporter.RecordTimer("outbound.calls.per-attempt.latency", response.commonStatsTags, latency) if lastAttempt { requestLatency := response.requestState.SinceStart(now, latency) response.statsReporter.RecordTimer("outbound.calls.latency", response.commonStatsTags, requestLatency) } if retryCount := response.requestState.RetryCount(); retryCount > 0 { retryTags := cloneTags(response.commonStatsTags) retryTags["retry-count"] = fmt.Sprint(retryCount) response.statsReporter.IncCounter("outbound.calls.retries", retryTags, 1) } if unexpected != nil { // TODO(prashant): Report the error code type as per metrics doc and enable. // response.statsReporter.IncCounter("outbound.calls.system-errors", response.commonStatsTags, 1) } else if response.ApplicationError() { // TODO(prashant): Figure out how to add "type" to tags, which TChannel does not know about. response.statsReporter.IncCounter("outbound.calls.per-attempt.app-errors", response.commonStatsTags, 1) if lastAttempt { response.statsReporter.IncCounter("outbound.calls.app-errors", response.commonStatsTags, 1) } } else { response.statsReporter.IncCounter("outbound.calls.success", response.commonStatsTags, 1) } response.mex.shutdown() }
[ "func", "(", "response", "*", "OutboundCallResponse", ")", "doneReading", "(", "unexpected", "error", ")", "{", "now", ":=", "response", ".", "timeNow", "(", ")", "\n", "isSuccess", ":=", "unexpected", "==", "nil", "&&", "!", "response", ".", "ApplicationError", "(", ")", "\n", "lastAttempt", ":=", "isSuccess", "||", "!", "response", ".", "requestState", ".", "HasRetries", "(", "unexpected", ")", "\n", "if", "span", ":=", "response", ".", "span", ";", "span", "!=", "nil", "{", "if", "unexpected", "!=", "nil", "{", "span", ".", "LogEventWithPayload", "(", "\"error\"", ",", "unexpected", ")", "\n", "}", "\n", "if", "!", "isSuccess", "&&", "lastAttempt", "{", "ext", ".", "Error", ".", "Set", "(", "span", ",", "true", ")", "\n", "}", "\n", "span", ".", "FinishWithOptions", "(", "opentracing", ".", "FinishOptions", "{", "FinishTime", ":", "now", "}", ")", "\n", "}", "\n", "latency", ":=", "now", ".", "Sub", "(", "response", ".", "startedAt", ")", "\n", "response", ".", "statsReporter", ".", "RecordTimer", "(", "\"outbound.calls.per-attempt.latency\"", ",", "response", ".", "commonStatsTags", ",", "latency", ")", "\n", "if", "lastAttempt", "{", "requestLatency", ":=", "response", ".", "requestState", ".", "SinceStart", "(", "now", ",", "latency", ")", "\n", "response", ".", "statsReporter", ".", "RecordTimer", "(", "\"outbound.calls.latency\"", ",", "response", ".", "commonStatsTags", ",", "requestLatency", ")", "\n", "}", "\n", "if", "retryCount", ":=", "response", ".", "requestState", ".", "RetryCount", "(", ")", ";", "retryCount", ">", "0", "{", "retryTags", ":=", "cloneTags", "(", "response", ".", "commonStatsTags", ")", "\n", "retryTags", "[", "\"retry-count\"", "]", "=", "fmt", ".", "Sprint", "(", "retryCount", ")", "\n", "response", ".", "statsReporter", ".", "IncCounter", "(", "\"outbound.calls.retries\"", ",", "retryTags", ",", "1", ")", "\n", "}", "\n", "if", "unexpected", "!=", "nil", "{", "}", "else", "if", "response", ".", "ApplicationError", "(", ")", "{", "response", ".", "statsReporter", ".", "IncCounter", "(", "\"outbound.calls.per-attempt.app-errors\"", ",", "response", ".", "commonStatsTags", ",", "1", ")", "\n", "if", "lastAttempt", "{", "response", ".", "statsReporter", ".", "IncCounter", "(", "\"outbound.calls.app-errors\"", ",", "response", ".", "commonStatsTags", ",", "1", ")", "\n", "}", "\n", "}", "else", "{", "response", ".", "statsReporter", ".", "IncCounter", "(", "\"outbound.calls.success\"", ",", "response", ".", "commonStatsTags", ",", "1", ")", "\n", "}", "\n", "response", ".", "mex", ".", "shutdown", "(", ")", "\n", "}" ]
// doneReading shuts down the message exchange for this call. // For outgoing calls, the last message is reading the call response.
[ "doneReading", "shuts", "down", "the", "message", "exchange", "for", "this", "call", ".", "For", "outgoing", "calls", "the", "last", "message", "is", "reading", "the", "call", "response", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/outbound.go#L320-L363
test
uber/tchannel-go
reqres.go
newFragment
func (w *reqResWriter) newFragment(initial bool, checksum Checksum) (*writableFragment, error) { if err := w.mex.checkError(); err != nil { return nil, w.failed(err) } message := w.messageForFragment(initial) // Create the frame frame := w.conn.opts.FramePool.Get() frame.Header.ID = w.mex.msgID frame.Header.messageType = message.messageType() // Write the message into the fragment, reserving flags and checksum bytes wbuf := typed.NewWriteBuffer(frame.Payload[:]) fragment := new(writableFragment) fragment.frame = frame fragment.flagsRef = wbuf.DeferByte() if err := message.write(wbuf); err != nil { return nil, err } wbuf.WriteSingleByte(byte(checksum.TypeCode())) fragment.checksumRef = wbuf.DeferBytes(checksum.Size()) fragment.checksum = checksum fragment.contents = wbuf return fragment, wbuf.Err() }
go
func (w *reqResWriter) newFragment(initial bool, checksum Checksum) (*writableFragment, error) { if err := w.mex.checkError(); err != nil { return nil, w.failed(err) } message := w.messageForFragment(initial) // Create the frame frame := w.conn.opts.FramePool.Get() frame.Header.ID = w.mex.msgID frame.Header.messageType = message.messageType() // Write the message into the fragment, reserving flags and checksum bytes wbuf := typed.NewWriteBuffer(frame.Payload[:]) fragment := new(writableFragment) fragment.frame = frame fragment.flagsRef = wbuf.DeferByte() if err := message.write(wbuf); err != nil { return nil, err } wbuf.WriteSingleByte(byte(checksum.TypeCode())) fragment.checksumRef = wbuf.DeferBytes(checksum.Size()) fragment.checksum = checksum fragment.contents = wbuf return fragment, wbuf.Err() }
[ "func", "(", "w", "*", "reqResWriter", ")", "newFragment", "(", "initial", "bool", ",", "checksum", "Checksum", ")", "(", "*", "writableFragment", ",", "error", ")", "{", "if", "err", ":=", "w", ".", "mex", ".", "checkError", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "w", ".", "failed", "(", "err", ")", "\n", "}", "\n", "message", ":=", "w", ".", "messageForFragment", "(", "initial", ")", "\n", "frame", ":=", "w", ".", "conn", ".", "opts", ".", "FramePool", ".", "Get", "(", ")", "\n", "frame", ".", "Header", ".", "ID", "=", "w", ".", "mex", ".", "msgID", "\n", "frame", ".", "Header", ".", "messageType", "=", "message", ".", "messageType", "(", ")", "\n", "wbuf", ":=", "typed", ".", "NewWriteBuffer", "(", "frame", ".", "Payload", "[", ":", "]", ")", "\n", "fragment", ":=", "new", "(", "writableFragment", ")", "\n", "fragment", ".", "frame", "=", "frame", "\n", "fragment", ".", "flagsRef", "=", "wbuf", ".", "DeferByte", "(", ")", "\n", "if", "err", ":=", "message", ".", "write", "(", "wbuf", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "wbuf", ".", "WriteSingleByte", "(", "byte", "(", "checksum", ".", "TypeCode", "(", ")", ")", ")", "\n", "fragment", ".", "checksumRef", "=", "wbuf", ".", "DeferBytes", "(", "checksum", ".", "Size", "(", ")", ")", "\n", "fragment", ".", "checksum", "=", "checksum", "\n", "fragment", ".", "contents", "=", "wbuf", "\n", "return", "fragment", ",", "wbuf", ".", "Err", "(", ")", "\n", "}" ]
// newFragment creates a new fragment for marshaling into
[ "newFragment", "creates", "a", "new", "fragment", "for", "marshaling", "into" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L111-L136
test
uber/tchannel-go
reqres.go
flushFragment
func (w *reqResWriter) flushFragment(fragment *writableFragment) error { if w.err != nil { return w.err } frame := fragment.frame.(*Frame) frame.Header.SetPayloadSize(uint16(fragment.contents.BytesWritten())) if err := w.mex.checkError(); err != nil { return w.failed(err) } select { case <-w.mex.ctx.Done(): return w.failed(GetContextError(w.mex.ctx.Err())) case <-w.mex.errCh.c: return w.failed(w.mex.errCh.err) case w.conn.sendCh <- frame: return nil } }
go
func (w *reqResWriter) flushFragment(fragment *writableFragment) error { if w.err != nil { return w.err } frame := fragment.frame.(*Frame) frame.Header.SetPayloadSize(uint16(fragment.contents.BytesWritten())) if err := w.mex.checkError(); err != nil { return w.failed(err) } select { case <-w.mex.ctx.Done(): return w.failed(GetContextError(w.mex.ctx.Err())) case <-w.mex.errCh.c: return w.failed(w.mex.errCh.err) case w.conn.sendCh <- frame: return nil } }
[ "func", "(", "w", "*", "reqResWriter", ")", "flushFragment", "(", "fragment", "*", "writableFragment", ")", "error", "{", "if", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "frame", ":=", "fragment", ".", "frame", ".", "(", "*", "Frame", ")", "\n", "frame", ".", "Header", ".", "SetPayloadSize", "(", "uint16", "(", "fragment", ".", "contents", ".", "BytesWritten", "(", ")", ")", ")", "\n", "if", "err", ":=", "w", ".", "mex", ".", "checkError", "(", ")", ";", "err", "!=", "nil", "{", "return", "w", ".", "failed", "(", "err", ")", "\n", "}", "\n", "select", "{", "case", "<-", "w", ".", "mex", ".", "ctx", ".", "Done", "(", ")", ":", "return", "w", ".", "failed", "(", "GetContextError", "(", "w", ".", "mex", ".", "ctx", ".", "Err", "(", ")", ")", ")", "\n", "case", "<-", "w", ".", "mex", ".", "errCh", ".", "c", ":", "return", "w", ".", "failed", "(", "w", ".", "mex", ".", "errCh", ".", "err", ")", "\n", "case", "w", ".", "conn", ".", "sendCh", "<-", "frame", ":", "return", "nil", "\n", "}", "\n", "}" ]
// flushFragment sends a fragment to the peer over the connection
[ "flushFragment", "sends", "a", "fragment", "to", "the", "peer", "over", "the", "connection" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L139-L158
test
uber/tchannel-go
reqres.go
failed
func (w *reqResWriter) failed(err error) error { w.log.Debugf("writer failed: %v existing err: %v", err, w.err) if w.err != nil { return w.err } w.mex.shutdown() w.err = err return w.err }
go
func (w *reqResWriter) failed(err error) error { w.log.Debugf("writer failed: %v existing err: %v", err, w.err) if w.err != nil { return w.err } w.mex.shutdown() w.err = err return w.err }
[ "func", "(", "w", "*", "reqResWriter", ")", "failed", "(", "err", "error", ")", "error", "{", "w", ".", "log", ".", "Debugf", "(", "\"writer failed: %v existing err: %v\"", ",", "err", ",", "w", ".", "err", ")", "\n", "if", "w", ".", "err", "!=", "nil", "{", "return", "w", ".", "err", "\n", "}", "\n", "w", ".", "mex", ".", "shutdown", "(", ")", "\n", "w", ".", "err", "=", "err", "\n", "return", "w", ".", "err", "\n", "}" ]
// failed marks the writer as having failed
[ "failed", "marks", "the", "writer", "as", "having", "failed" ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L161-L170
test
uber/tchannel-go
reqres.go
arg1Reader
func (r *reqResReader) arg1Reader() (ArgReader, error) { return r.argReader(false /* last */, reqResReaderPreArg1, reqResReaderPreArg2) }
go
func (r *reqResReader) arg1Reader() (ArgReader, error) { return r.argReader(false /* last */, reqResReaderPreArg1, reqResReaderPreArg2) }
[ "func", "(", "r", "*", "reqResReader", ")", "arg1Reader", "(", ")", "(", "ArgReader", ",", "error", ")", "{", "return", "r", ".", "argReader", "(", "false", ",", "reqResReaderPreArg1", ",", "reqResReaderPreArg2", ")", "\n", "}" ]
// arg1Reader returns an ArgReader to read arg1.
[ "arg1Reader", "returns", "an", "ArgReader", "to", "read", "arg1", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L195-L197
test
uber/tchannel-go
reqres.go
arg2Reader
func (r *reqResReader) arg2Reader() (ArgReader, error) { return r.argReader(false /* last */, reqResReaderPreArg2, reqResReaderPreArg3) }
go
func (r *reqResReader) arg2Reader() (ArgReader, error) { return r.argReader(false /* last */, reqResReaderPreArg2, reqResReaderPreArg3) }
[ "func", "(", "r", "*", "reqResReader", ")", "arg2Reader", "(", ")", "(", "ArgReader", ",", "error", ")", "{", "return", "r", ".", "argReader", "(", "false", ",", "reqResReaderPreArg2", ",", "reqResReaderPreArg3", ")", "\n", "}" ]
// arg2Reader returns an ArgReader to read arg2.
[ "arg2Reader", "returns", "an", "ArgReader", "to", "read", "arg2", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L200-L202
test
uber/tchannel-go
reqres.go
arg3Reader
func (r *reqResReader) arg3Reader() (ArgReader, error) { return r.argReader(true /* last */, reqResReaderPreArg3, reqResReaderComplete) }
go
func (r *reqResReader) arg3Reader() (ArgReader, error) { return r.argReader(true /* last */, reqResReaderPreArg3, reqResReaderComplete) }
[ "func", "(", "r", "*", "reqResReader", ")", "arg3Reader", "(", ")", "(", "ArgReader", ",", "error", ")", "{", "return", "r", ".", "argReader", "(", "true", ",", "reqResReaderPreArg3", ",", "reqResReaderComplete", ")", "\n", "}" ]
// arg3Reader returns an ArgReader to read arg3.
[ "arg3Reader", "returns", "an", "ArgReader", "to", "read", "arg3", "." ]
3c9ced6d946fe2fec6c915703a533e966c09e07a
https://github.com/uber/tchannel-go/blob/3c9ced6d946fe2fec6c915703a533e966c09e07a/reqres.go#L205-L207
test