id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
25,200
apex/apex
metrics/metric.go
aggregate
func aggregate(datapoints []*cloudwatch.Datapoint) int { sum := 0.0 for _, datapoint := range datapoints { sum += *datapoint.Sum } return int(sum) }
go
func aggregate(datapoints []*cloudwatch.Datapoint) int { sum := 0.0 for _, datapoint := range datapoints { sum += *datapoint.Sum } return int(sum) }
[ "func", "aggregate", "(", "datapoints", "[", "]", "*", "cloudwatch", ".", "Datapoint", ")", "int", "{", "sum", ":=", "0.0", "\n\n", "for", "_", ",", "datapoint", ":=", "range", "datapoints", "{", "sum", "+=", "*", "datapoint", ".", "Sum", "\n", "}", ...
// aggregate accumulates the datapoints.
[ "aggregate", "accumulates", "the", "datapoints", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metric.go#L132-L140
25,201
apex/apex
plugins/hooks/hooks.go
Error
func (e *HookError) Error() string { return fmt.Sprintf("%s hook: %s", e.Hook, e.Output) }
go
func (e *HookError) Error() string { return fmt.Sprintf("%s hook: %s", e.Hook, e.Output) }
[ "func", "(", "e", "*", "HookError", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "Hook", ",", "e", ".", "Output", ")", "\n", "}" ]
// Error string.
[ "Error", "string", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L28-L30
25,202
apex/apex
plugins/hooks/hooks.go
Build
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { return p.run("build", fn.Hooks.Build, fn) }
go
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { return p.run("build", fn.Hooks.Build, fn) }
[ "func", "(", "p", "*", "Plugin", ")", "Build", "(", "fn", "*", "function", ".", "Function", ",", "zip", "*", "archive", ".", "Zip", ")", "error", "{", "return", "p", ".", "run", "(", "\"", "\"", ",", "fn", ".", "Hooks", ".", "Build", ",", "fn",...
// Build runs the "build" hook commands.
[ "Build", "runs", "the", "build", "hook", "commands", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L36-L38
25,203
apex/apex
plugins/hooks/hooks.go
Deploy
func (p *Plugin) Deploy(fn *function.Function) error { return p.run("deploy", fn.Hooks.Deploy, fn) }
go
func (p *Plugin) Deploy(fn *function.Function) error { return p.run("deploy", fn.Hooks.Deploy, fn) }
[ "func", "(", "p", "*", "Plugin", ")", "Deploy", "(", "fn", "*", "function", ".", "Function", ")", "error", "{", "return", "p", ".", "run", "(", "\"", "\"", ",", "fn", ".", "Hooks", ".", "Deploy", ",", "fn", ")", "\n", "}" ]
// Deploy runs the "deploy" hook commands.
[ "Deploy", "runs", "the", "deploy", "hook", "commands", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L46-L48
25,204
apex/apex
plugins/hooks/hooks.go
run
func (p *Plugin) run(hook, command string, fn *function.Function) error { if command == "" { return nil } fn.Log.WithFields(log.Fields{ "hook": hook, "command": command, }).Debug("hook") var cmd *exec.Cmd if runtime.GOOS == "windows" { cmd = exec.Command("cmd", "/c", command) } else { cmd = exec.C...
go
func (p *Plugin) run(hook, command string, fn *function.Function) error { if command == "" { return nil } fn.Log.WithFields(log.Fields{ "hook": hook, "command": command, }).Debug("hook") var cmd *exec.Cmd if runtime.GOOS == "windows" { cmd = exec.Command("cmd", "/c", command) } else { cmd = exec.C...
[ "func", "(", "p", "*", "Plugin", ")", "run", "(", "hook", ",", "command", "string", ",", "fn", "*", "function", ".", "Function", ")", "error", "{", "if", "command", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "fn", ".", "Log", ".",...
// run a hook command.
[ "run", "a", "hook", "command", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/hooks/hooks.go#L51-L80
25,205
apex/apex
internal/util/util.go
ClearHeader
func ClearHeader(h http.Header) { for k := range h { if keepFields[k] { continue } h.Del(k) } }
go
func ClearHeader(h http.Header) { for k := range h { if keepFields[k] { continue } h.Del(k) } }
[ "func", "ClearHeader", "(", "h", "http", ".", "Header", ")", "{", "for", "k", ":=", "range", "h", "{", "if", "keepFields", "[", "k", "]", "{", "continue", "\n", "}", "\n\n", "h", ".", "Del", "(", "k", ")", "\n", "}", "\n", "}" ]
// ClearHeader removes all header fields.
[ "ClearHeader", "removes", "all", "header", "fields", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L38-L46
25,206
apex/apex
internal/util/util.go
ReadFileJSON
func ReadFileJSON(path string, v interface{}) error { b, err := ioutil.ReadFile(path) if err != nil { return errors.Wrap(err, "reading") } if err := json.Unmarshal(b, &v); err != nil { return errors.Wrap(err, "unmarshaling") } return nil }
go
func ReadFileJSON(path string, v interface{}) error { b, err := ioutil.ReadFile(path) if err != nil { return errors.Wrap(err, "reading") } if err := json.Unmarshal(b, &v); err != nil { return errors.Wrap(err, "unmarshaling") } return nil }
[ "func", "ReadFileJSON", "(", "path", "string", ",", "v", "interface", "{", "}", ")", "error", "{", "b", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err",...
// ReadFileJSON reads json from the given path.
[ "ReadFileJSON", "reads", "json", "from", "the", "given", "path", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L64-L75
25,207
apex/apex
internal/util/util.go
Camelcase
func Camelcase(s string, v ...interface{}) string { return name.CamelCase(fmt.Sprintf(s, v...), true) }
go
func Camelcase(s string, v ...interface{}) string { return name.CamelCase(fmt.Sprintf(s, v...), true) }
[ "func", "Camelcase", "(", "s", "string", ",", "v", "...", "interface", "{", "}", ")", "string", "{", "return", "name", ".", "CamelCase", "(", "fmt", ".", "Sprintf", "(", "s", ",", "v", "...", ")", ",", "true", ")", "\n", "}" ]
// Camelcase string with optional args.
[ "Camelcase", "string", "with", "optional", "args", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L78-L80
25,208
apex/apex
internal/util/util.go
NewInlineProgressInt
func NewInlineProgressInt(total int) *progress.Bar { b := progress.NewInt(total) b.Template(`{{.Bar}} {{.Percent | printf "%0.0f"}}% {{.Text}}`) b.Width = 20 b.StartDelimiter = colors.Gray("|") b.EndDelimiter = colors.Gray("|") b.Filled = colors.Purple("█") b.Empty = colors.Gray(" ") return b }
go
func NewInlineProgressInt(total int) *progress.Bar { b := progress.NewInt(total) b.Template(`{{.Bar}} {{.Percent | printf "%0.0f"}}% {{.Text}}`) b.Width = 20 b.StartDelimiter = colors.Gray("|") b.EndDelimiter = colors.Gray("|") b.Filled = colors.Purple("█") b.Empty = colors.Gray(" ") return b }
[ "func", "NewInlineProgressInt", "(", "total", "int", ")", "*", "progress", ".", "Bar", "{", "b", ":=", "progress", ".", "NewInt", "(", "total", ")", "\n", "b", ".", "Template", "(", "`{{.Bar}} {{.Percent | printf \"%0.0f\"}}% {{.Text}}`", ")", "\n", "b", ".", ...
// NewInlineProgressInt with the given total.
[ "NewInlineProgressInt", "with", "the", "given", "total", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L95-L104
25,209
apex/apex
internal/util/util.go
Fatal
func Fatal(err error) { fmt.Fprintf(os.Stderr, "\n %s %s\n\n", colors.Red("Error:"), err) os.Exit(1) }
go
func Fatal(err error) { fmt.Fprintf(os.Stderr, "\n %s %s\n\n", colors.Red("Error:"), err) os.Exit(1) }
[ "func", "Fatal", "(", "err", "error", ")", "{", "fmt", ".", "Fprintf", "(", "os", ".", "Stderr", ",", "\"", "\\n", "\\n", "\\n", "\"", ",", "colors", ".", "Red", "(", "\"", "\"", ")", ",", "err", ")", "\n", "os", ".", "Exit", "(", "1", ")", ...
// Fatal error.
[ "Fatal", "error", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L115-L118
25,210
apex/apex
internal/util/util.go
IsJSON
func IsJSON(s string) bool { return len(s) > 1 && s[0] == '{' && s[len(s)-1] == '}' }
go
func IsJSON(s string) bool { return len(s) > 1 && s[0] == '{' && s[len(s)-1] == '}' }
[ "func", "IsJSON", "(", "s", "string", ")", "bool", "{", "return", "len", "(", "s", ")", ">", "1", "&&", "s", "[", "0", "]", "==", "'{'", "&&", "s", "[", "len", "(", "s", ")", "-", "1", "]", "==", "'}'", "\n", "}" ]
// IsJSON returns true if the string looks like json.
[ "IsJSON", "returns", "true", "if", "the", "string", "looks", "like", "json", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L121-L123
25,211
apex/apex
internal/util/util.go
IsNotFound
func IsNotFound(err error) bool { switch { case err == nil: return false case strings.Contains(err.Error(), "does not exist"): return true case strings.Contains(err.Error(), "not found"): return true default: return false } }
go
func IsNotFound(err error) bool { switch { case err == nil: return false case strings.Contains(err.Error(), "does not exist"): return true case strings.Contains(err.Error(), "not found"): return true default: return false } }
[ "func", "IsNotFound", "(", "err", "error", ")", "bool", "{", "switch", "{", "case", "err", "==", "nil", ":", "return", "false", "\n", "case", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", ":", "return", "true...
// IsNotFound returns true if err is not nil and represents a missing resource.
[ "IsNotFound", "returns", "true", "if", "err", "is", "not", "nil", "and", "represents", "a", "missing", "resource", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L131-L142
25,212
apex/apex
internal/util/util.go
Env
func Env(m map[string]string) (env []string) { for k, v := range m { env = append(env, fmt.Sprintf("%s=%s", k, v)) } return }
go
func Env(m map[string]string) (env []string) { for k, v := range m { env = append(env, fmt.Sprintf("%s=%s", k, v)) } return }
[ "func", "Env", "(", "m", "map", "[", "string", "]", "string", ")", "(", "env", "[", "]", "string", ")", "{", "for", "k", ",", "v", ":=", "range", "m", "{", "env", "=", "append", "(", "env", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", ...
// Env returns a slice from environment variable map.
[ "Env", "returns", "a", "slice", "from", "environment", "variable", "map", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L157-L162
25,213
apex/apex
internal/util/util.go
PrefixLines
func PrefixLines(s string, prefix string) string { lines := strings.Split(s, "\n") for i, l := range lines { lines[i] = prefix + l } return strings.Join(lines, "\n") }
go
func PrefixLines(s string, prefix string) string { lines := strings.Split(s, "\n") for i, l := range lines { lines[i] = prefix + l } return strings.Join(lines, "\n") }
[ "func", "PrefixLines", "(", "s", "string", ",", "prefix", "string", ")", "string", "{", "lines", ":=", "strings", ".", "Split", "(", "s", ",", "\"", "\\n", "\"", ")", "\n", "for", "i", ",", "l", ":=", "range", "lines", "{", "lines", "[", "i", "]"...
// PrefixLines prefixes the lines in s with prefix.
[ "PrefixLines", "prefixes", "the", "lines", "in", "s", "with", "prefix", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L165-L171
25,214
apex/apex
internal/util/util.go
WaitForListen
func WaitForListen(u *url.URL, timeout time.Duration) error { timedout := time.After(timeout) b := backoff.Backoff{ Min: 100 * time.Millisecond, Max: time.Second, Factor: 1.5, } for { select { case <-timedout: return errors.Errorf("timed out after %s", timeout) case <-time.After(b.Duration())...
go
func WaitForListen(u *url.URL, timeout time.Duration) error { timedout := time.After(timeout) b := backoff.Backoff{ Min: 100 * time.Millisecond, Max: time.Second, Factor: 1.5, } for { select { case <-timedout: return errors.Errorf("timed out after %s", timeout) case <-time.After(b.Duration())...
[ "func", "WaitForListen", "(", "u", "*", "url", ".", "URL", ",", "timeout", "time", ".", "Duration", ")", "error", "{", "timedout", ":=", "time", ".", "After", "(", "timeout", ")", "\n\n", "b", ":=", "backoff", ".", "Backoff", "{", "Min", ":", "100", ...
// WaitForListen blocks until `u` is listening with timeout.
[ "WaitForListen", "blocks", "until", "u", "is", "listening", "with", "timeout", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L179-L198
25,215
apex/apex
internal/util/util.go
IsListening
func IsListening(u *url.URL) bool { conn, err := net.Dial("tcp", u.Host) if err != nil { return false } conn.Close() return true }
go
func IsListening(u *url.URL) bool { conn, err := net.Dial("tcp", u.Host) if err != nil { return false } conn.Close() return true }
[ "func", "IsListening", "(", "u", "*", "url", ".", "URL", ")", "bool", "{", "conn", ",", "err", ":=", "net", ".", "Dial", "(", "\"", "\"", ",", "u", ".", "Host", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n\n", "...
// IsListening returns true if there's a server listening on `u`.
[ "IsListening", "returns", "true", "if", "there", "s", "a", "server", "listening", "on", "u", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L201-L209
25,216
apex/apex
internal/util/util.go
ExitStatus
func ExitStatus(cmd *exec.Cmd, err error) string { ps := cmd.ProcessState if e, ok := err.(*exec.ExitError); ok { ps = e.ProcessState } if ps != nil { s, ok := ps.Sys().(syscall.WaitStatus) if ok { return fmt.Sprintf("%d", s.ExitStatus()) } } return "?" }
go
func ExitStatus(cmd *exec.Cmd, err error) string { ps := cmd.ProcessState if e, ok := err.(*exec.ExitError); ok { ps = e.ProcessState } if ps != nil { s, ok := ps.Sys().(syscall.WaitStatus) if ok { return fmt.Sprintf("%d", s.ExitStatus()) } } return "?" }
[ "func", "ExitStatus", "(", "cmd", "*", "exec", ".", "Cmd", ",", "err", "error", ")", "string", "{", "ps", ":=", "cmd", ".", "ProcessState", "\n\n", "if", "e", ",", "ok", ":=", "err", ".", "(", "*", "exec", ".", "ExitError", ")", ";", "ok", "{", ...
// ExitStatus returns the exit status of cmd.
[ "ExitStatus", "returns", "the", "exit", "status", "of", "cmd", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L212-L227
25,217
apex/apex
internal/util/util.go
Log
func Log(msg string, v ...interface{}) { fmt.Printf(" %s\n", colors.Purple(fmt.Sprintf(msg, v...))) }
go
func Log(msg string, v ...interface{}) { fmt.Printf(" %s\n", colors.Purple(fmt.Sprintf(msg, v...))) }
[ "func", "Log", "(", "msg", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "colors", ".", "Purple", "(", "fmt", ".", "Sprintf", "(", "msg", ",", "v", "...", ")", ")", ")", "\n", "...
// Log outputs a log message.
[ "Log", "outputs", "a", "log", "message", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L252-L254
25,218
apex/apex
internal/util/util.go
LogClear
func LogClear(msg string, v ...interface{}) { term.MoveUp(1) term.ClearLine() fmt.Printf("\r %s\n", colors.Purple(fmt.Sprintf(msg, v...))) }
go
func LogClear(msg string, v ...interface{}) { term.MoveUp(1) term.ClearLine() fmt.Printf("\r %s\n", colors.Purple(fmt.Sprintf(msg, v...))) }
[ "func", "LogClear", "(", "msg", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "term", ".", "MoveUp", "(", "1", ")", "\n", "term", ".", "ClearLine", "(", ")", "\n", "fmt", ".", "Printf", "(", "\"", "\\r", "\\n", "\"", ",", "colors", ...
// LogClear clears the line and outputs a log message.
[ "LogClear", "clears", "the", "line", "and", "outputs", "a", "log", "message", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L257-L261
25,219
apex/apex
internal/util/util.go
LogTitle
func LogTitle(msg string, v ...interface{}) { fmt.Printf("\n \x1b[1m%s\x1b[m\n\n", fmt.Sprintf(msg, v...)) }
go
func LogTitle(msg string, v ...interface{}) { fmt.Printf("\n \x1b[1m%s\x1b[m\n\n", fmt.Sprintf(msg, v...)) }
[ "func", "LogTitle", "(", "msg", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\\x1b", "\\x1b", "\\n", "\\n", "\"", ",", "fmt", ".", "Sprintf", "(", "msg", ",", "v", "...", ")", ")", "\n", "...
// LogTitle outputs a log title.
[ "LogTitle", "outputs", "a", "log", "title", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L264-L266
25,220
apex/apex
internal/util/util.go
LogName
func LogName(name, msg string, v ...interface{}) { fmt.Printf(" %s %s\n", colors.Purple(name+":"), fmt.Sprintf(msg, v...)) }
go
func LogName(name, msg string, v ...interface{}) { fmt.Printf(" %s %s\n", colors.Purple(name+":"), fmt.Sprintf(msg, v...)) }
[ "func", "LogName", "(", "name", ",", "msg", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "colors", ".", "Purple", "(", "name", "+", "\"", "\"", ")", ",", "fmt", ".", "Sprintf", "...
// LogName outputs a log message with name.
[ "LogName", "outputs", "a", "log", "message", "with", "name", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L269-L271
25,221
apex/apex
internal/util/util.go
LogListItem
func LogListItem(msg string, v ...interface{}) { fmt.Printf(" • %s\n", fmt.Sprintf(msg, v...)) }
go
func LogListItem(msg string, v ...interface{}) { fmt.Printf(" • %s\n", fmt.Sprintf(msg, v...)) }
[ "func", "LogListItem", "(", "msg", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "fmt", ".", "Printf", "(", "\"", "\",", " ", "f", "t.S", "p", "rintf(m", "s", "g, ", "v", ".", ".))", "", "", "\n", "}" ]
// LogListItem outputs a list item.
[ "LogListItem", "outputs", "a", "list", "item", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L274-L276
25,222
apex/apex
internal/util/util.go
ToFloat
func ToFloat(v interface{}) float64 { switch n := v.(type) { case int: return float64(n) case int8: return float64(n) case int16: return float64(n) case int32: return float64(n) case int64: return float64(n) case uint: return float64(n) case uint8: return float64(n) case uint16: return float64(...
go
func ToFloat(v interface{}) float64 { switch n := v.(type) { case int: return float64(n) case int8: return float64(n) case int16: return float64(n) case int32: return float64(n) case int64: return float64(n) case uint: return float64(n) case uint8: return float64(n) case uint16: return float64(...
[ "func", "ToFloat", "(", "v", "interface", "{", "}", ")", "float64", "{", "switch", "n", ":=", "v", ".", "(", "type", ")", "{", "case", "int", ":", "return", "float64", "(", "n", ")", "\n", "case", "int8", ":", "return", "float64", "(", "n", ")", ...
// ToFloat returns a float or NaN.
[ "ToFloat", "returns", "a", "float", "or", "NaN", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L279-L308
25,223
apex/apex
internal/util/util.go
MillisecondsSince
func MillisecondsSince(t time.Time) int { return int(time.Since(t) / time.Millisecond) }
go
func MillisecondsSince(t time.Time) int { return int(time.Since(t) / time.Millisecond) }
[ "func", "MillisecondsSince", "(", "t", "time", ".", "Time", ")", "int", "{", "return", "int", "(", "time", ".", "Since", "(", "t", ")", "/", "time", ".", "Millisecond", ")", "\n", "}" ]
// MillisecondsSince returns the duration as milliseconds relative to time t.
[ "MillisecondsSince", "returns", "the", "duration", "as", "milliseconds", "relative", "to", "time", "t", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L316-L318
25,224
apex/apex
internal/util/util.go
ParseDuration
func ParseDuration(s string) (d time.Duration, err error) { r := strings.NewReader(s) switch { case strings.HasSuffix(s, "d"): var v float64 _, err = fmt.Fscanf(r, "%fd", &v) d = time.Duration(v * float64(24*time.Hour)) case strings.HasSuffix(s, "w"): var v float64 _, err = fmt.Fscanf(r, "%fw", &v) d =...
go
func ParseDuration(s string) (d time.Duration, err error) { r := strings.NewReader(s) switch { case strings.HasSuffix(s, "d"): var v float64 _, err = fmt.Fscanf(r, "%fd", &v) d = time.Duration(v * float64(24*time.Hour)) case strings.HasSuffix(s, "w"): var v float64 _, err = fmt.Fscanf(r, "%fw", &v) d =...
[ "func", "ParseDuration", "(", "s", "string", ")", "(", "d", "time", ".", "Duration", ",", "err", "error", ")", "{", "r", ":=", "strings", ".", "NewReader", "(", "s", ")", "\n\n", "switch", "{", "case", "strings", ".", "HasSuffix", "(", "s", ",", "\...
// ParseDuration string with day and month approximation support.
[ "ParseDuration", "string", "with", "day", "and", "month", "approximation", "support", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L321-L346
25,225
apex/apex
internal/util/util.go
ParseSections
func ParseSections(r io.Reader) (sections []string, err error) { s := bufio.NewScanner(r) for s.Scan() { t := s.Text() if strings.HasPrefix(t, "[") { sections = append(sections, strings.Trim(t, "[]")) } } err = s.Err() return }
go
func ParseSections(r io.Reader) (sections []string, err error) { s := bufio.NewScanner(r) for s.Scan() { t := s.Text() if strings.HasPrefix(t, "[") { sections = append(sections, strings.Trim(t, "[]")) } } err = s.Err() return }
[ "func", "ParseSections", "(", "r", "io", ".", "Reader", ")", "(", "sections", "[", "]", "string", ",", "err", "error", ")", "{", "s", ":=", "bufio", ".", "NewScanner", "(", "r", ")", "\n\n", "for", "s", ".", "Scan", "(", ")", "{", "t", ":=", "s...
// ParseSections returns INI style sections from r.
[ "ParseSections", "returns", "INI", "style", "sections", "from", "r", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/internal/util/util.go#L368-L381
25,226
apex/apex
cost/cost.go
Cost
func Cost(requests, ms, memory int) float64 { return RequestCost(requests) + DurationCost(ms, memory) }
go
func Cost(requests, ms, memory int) float64 { return RequestCost(requests) + DurationCost(ms, memory) }
[ "func", "Cost", "(", "requests", ",", "ms", ",", "memory", "int", ")", "float64", "{", "return", "RequestCost", "(", "requests", ")", "+", "DurationCost", "(", "ms", ",", "memory", ")", "\n", "}" ]
// Cost returns the total cost.
[ "Cost", "returns", "the", "total", "cost", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cost/cost.go#L50-L52
25,227
apex/apex
infra/tfvars.go
functionVars
func (p *Proxy) functionVars() (args []string) { args = append(args, "-var") args = append(args, fmt.Sprintf("aws_region=%s", p.Region)) args = append(args, "-var") args = append(args, fmt.Sprintf("apex_environment=%s", p.Environment)) if p.Role != "" { args = append(args, "-var") args = append(args, fmt.Sp...
go
func (p *Proxy) functionVars() (args []string) { args = append(args, "-var") args = append(args, fmt.Sprintf("aws_region=%s", p.Region)) args = append(args, "-var") args = append(args, fmt.Sprintf("apex_environment=%s", p.Environment)) if p.Role != "" { args = append(args, "-var") args = append(args, fmt.Sp...
[ "func", "(", "p", "*", "Proxy", ")", "functionVars", "(", ")", "(", "args", "[", "]", "string", ")", "{", "args", "=", "append", "(", "args", ",", "\"", "\"", ")", "\n", "args", "=", "append", "(", "args", ",", "fmt", ".", "Sprintf", "(", "\"",...
// functionVars returns the function variables as terraform -var arguments.
[ "functionVars", "returns", "the", "function", "variables", "as", "terraform", "-", "var", "arguments", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/infra/tfvars.go#L19-L53
25,228
apex/apex
infra/tfvars.go
getFunctionArnVars
func getFunctionArnVars(relations []ConfigRelation) (args []string) { log.Debugf("Generating the tfvar apex_function_FUNCTION") for _, rel := range relations { args = append(args, "-var") args = append(args, fmt.Sprintf("apex_function_%s=%s", rel.Function.Name, *rel.Configuration.FunctionArn)) } return args }
go
func getFunctionArnVars(relations []ConfigRelation) (args []string) { log.Debugf("Generating the tfvar apex_function_FUNCTION") for _, rel := range relations { args = append(args, "-var") args = append(args, fmt.Sprintf("apex_function_%s=%s", rel.Function.Name, *rel.Configuration.FunctionArn)) } return args }
[ "func", "getFunctionArnVars", "(", "relations", "[", "]", "ConfigRelation", ")", "(", "args", "[", "]", "string", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ")", "\n", "for", "_", ",", "rel", ":=", "range", "relations", "{", "args", "=", "appen...
// Generate a series of variables apex_function_FUNCTION that contains the arn of the functions // This function is being phased out in favour of apex_function_arns
[ "Generate", "a", "series", "of", "variables", "apex_function_FUNCTION", "that", "contains", "the", "arn", "of", "the", "functions", "This", "function", "is", "being", "phased", "out", "in", "favour", "of", "apex_function_arns" ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/infra/tfvars.go#L57-L64
25,229
apex/apex
infra/tfvars.go
getFunctionArns
func getFunctionArns(relations []ConfigRelation) (args []string) { log.Debugf("Generating the tfvar apex_function_arns") var arns []string for _, rel := range relations { arns = append(arns, fmt.Sprintf("%s = %q", rel.Function.Name, *rel.Configuration.FunctionArn)) } args = append(args, "-var") args = append(ar...
go
func getFunctionArns(relations []ConfigRelation) (args []string) { log.Debugf("Generating the tfvar apex_function_arns") var arns []string for _, rel := range relations { arns = append(arns, fmt.Sprintf("%s = %q", rel.Function.Name, *rel.Configuration.FunctionArn)) } args = append(args, "-var") args = append(ar...
[ "func", "getFunctionArns", "(", "relations", "[", "]", "ConfigRelation", ")", "(", "args", "[", "]", "string", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ")", "\n", "var", "arns", "[", "]", "string", "\n", "for", "_", ",", "rel", ":=", "range...
// Generates a map that has the function's name as a key and the arn of the function as a value
[ "Generates", "a", "map", "that", "has", "the", "function", "s", "name", "as", "a", "key", "and", "the", "arn", "of", "the", "function", "as", "a", "value" ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/infra/tfvars.go#L78-L87
25,230
apex/apex
infra/tfvars.go
getFunctionNames
func getFunctionNames(relations []ConfigRelation) (args []string) { log.Debugf("Generating the tfvar apex_function_names") var names []string for _, rel := range relations { names = append(names, fmt.Sprintf("%s = %q", rel.Function.Name, rel.Function.FunctionName)) } args = append(args, "-var") args = append(ar...
go
func getFunctionNames(relations []ConfigRelation) (args []string) { log.Debugf("Generating the tfvar apex_function_names") var names []string for _, rel := range relations { names = append(names, fmt.Sprintf("%s = %q", rel.Function.Name, rel.Function.FunctionName)) } args = append(args, "-var") args = append(ar...
[ "func", "getFunctionNames", "(", "relations", "[", "]", "ConfigRelation", ")", "(", "args", "[", "]", "string", ")", "{", "log", ".", "Debugf", "(", "\"", "\"", ")", "\n", "var", "names", "[", "]", "string", "\n", "for", "_", ",", "rel", ":=", "ran...
// Generates a map that has the function's name as a key and the full name of the function as a value
[ "Generates", "a", "map", "that", "has", "the", "function", "s", "name", "as", "a", "key", "and", "the", "full", "name", "of", "the", "function", "as", "a", "value" ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/infra/tfvars.go#L90-L99
25,231
apex/apex
exec/exec.go
Run
func (p *Proxy) Run(command string, args ...string) error { log.WithFields(log.Fields{ "command": command, "args": args, }).Debug("exec") cmd := exec.Command(command, args...) cmd.Env = append(os.Environ(), p.functionEnvVars()...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Di...
go
func (p *Proxy) Run(command string, args ...string) error { log.WithFields(log.Fields{ "command": command, "args": args, }).Debug("exec") cmd := exec.Command(command, args...) cmd.Env = append(os.Environ(), p.functionEnvVars()...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Di...
[ "func", "(", "p", "*", "Proxy", ")", "Run", "(", "command", "string", ",", "args", "...", "string", ")", "error", "{", "log", ".", "WithFields", "(", "log", ".", "Fields", "{", "\"", "\"", ":", "command", ",", "\"", "\"", ":", "args", ",", "}", ...
// Run command in specified directory.
[ "Run", "command", "in", "specified", "directory", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/exec/exec.go#L23-L37
25,232
apex/apex
metrics/metrics.go
Collect
func (m *Metrics) Collect() (a map[string]AggregatedMetrics) { a = make(map[string]AggregatedMetrics) for _, fnName := range m.FunctionNames { metric := Metric{ Config: m.Config, FunctionName: fnName, } a[fnName] = metric.Collect() } return }
go
func (m *Metrics) Collect() (a map[string]AggregatedMetrics) { a = make(map[string]AggregatedMetrics) for _, fnName := range m.FunctionNames { metric := Metric{ Config: m.Config, FunctionName: fnName, } a[fnName] = metric.Collect() } return }
[ "func", "(", "m", "*", "Metrics", ")", "Collect", "(", ")", "(", "a", "map", "[", "string", "]", "AggregatedMetrics", ")", "{", "a", "=", "make", "(", "map", "[", "string", "]", "AggregatedMetrics", ")", "\n\n", "for", "_", ",", "fnName", ":=", "ra...
// Collect and aggregate metrics for multiple functions.
[ "Collect", "and", "aggregate", "metrics", "for", "multiple", "functions", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/metrics/metrics.go#L33-L46
25,233
apex/apex
cmd/apex/autocomplete/autocomplete.go
find
func find(name string) *cobra.Command { for _, cmd := range root.Command.Commands() { if cmd.Name() == name { return cmd } } return nil }
go
func find(name string) *cobra.Command { for _, cmd := range root.Command.Commands() { if cmd.Name() == name { return cmd } } return nil }
[ "func", "find", "(", "name", "string", ")", "*", "cobra", ".", "Command", "{", "for", "_", ",", "cmd", ":=", "range", "root", ".", "Command", ".", "Commands", "(", ")", "{", "if", "cmd", ".", "Name", "(", ")", "==", "name", "{", "return", "cmd", ...
// find command by `name`.
[ "find", "command", "by", "name", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/autocomplete/autocomplete.go#L73-L80
25,234
apex/apex
cmd/apex/autocomplete/autocomplete.go
rootCommands
func rootCommands() { for _, cmd := range root.Command.Commands() { if !cmd.Hidden { fmt.Printf("%s ", cmd.Name()) } } }
go
func rootCommands() { for _, cmd := range root.Command.Commands() { if !cmd.Hidden { fmt.Printf("%s ", cmd.Name()) } } }
[ "func", "rootCommands", "(", ")", "{", "for", "_", ",", "cmd", ":=", "range", "root", ".", "Command", ".", "Commands", "(", ")", "{", "if", "!", "cmd", ".", "Hidden", "{", "fmt", ".", "Printf", "(", "\"", "\"", ",", "cmd", ".", "Name", "(", ")"...
// output root commands.
[ "output", "root", "commands", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/autocomplete/autocomplete.go#L83-L89
25,235
apex/apex
cmd/apex/autocomplete/autocomplete.go
flags
func flags(cmd *cobra.Command) { cmd.Flags().VisitAll(func(f *flag.Flag) { if !f.Hidden { fmt.Printf("--%s ", f.Name) } }) }
go
func flags(cmd *cobra.Command) { cmd.Flags().VisitAll(func(f *flag.Flag) { if !f.Hidden { fmt.Printf("--%s ", f.Name) } }) }
[ "func", "flags", "(", "cmd", "*", "cobra", ".", "Command", ")", "{", "cmd", ".", "Flags", "(", ")", ".", "VisitAll", "(", "func", "(", "f", "*", "flag", ".", "Flag", ")", "{", "if", "!", "f", ".", "Hidden", "{", "fmt", ".", "Printf", "(", "\"...
// output flags.
[ "output", "flags", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/autocomplete/autocomplete.go#L92-L98
25,236
apex/apex
plugins/inference/inference.go
Open
func (p *Plugin) Open(fn *function.Function) error { if fn.Runtime != "" { return nil } fn.Log.Debug("inferring runtime") for name, runtime := range p.Files { if _, err := os.Stat(filepath.Join(fn.Path, name)); err == nil { fn.Log.WithField("runtime", runtime).Debug("inferred runtime") fn.Runtime = runt...
go
func (p *Plugin) Open(fn *function.Function) error { if fn.Runtime != "" { return nil } fn.Log.Debug("inferring runtime") for name, runtime := range p.Files { if _, err := os.Stat(filepath.Join(fn.Path, name)); err == nil { fn.Log.WithField("runtime", runtime).Debug("inferred runtime") fn.Runtime = runt...
[ "func", "(", "p", "*", "Plugin", ")", "Open", "(", "fn", "*", "function", ".", "Function", ")", "error", "{", "if", "fn", ".", "Runtime", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "fn", ".", "Log", ".", "Debug", "(", "\"", "\""...
// Open checks for files in the function directory to infer its runtime.
[ "Open", "checks", "for", "files", "in", "the", "function", "directory", "to", "infer", "its", "runtime", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/inference/inference.go#L35-L51
25,237
apex/apex
service/provider.go
NewProvider
func NewProvider(session *session.Session, dryRun bool) Provideriface { return &Provider{ Session: session, DryRun: dryRun, } }
go
func NewProvider(session *session.Session, dryRun bool) Provideriface { return &Provider{ Session: session, DryRun: dryRun, } }
[ "func", "NewProvider", "(", "session", "*", "session", ".", "Session", ",", "dryRun", "bool", ")", "Provideriface", "{", "return", "&", "Provider", "{", "Session", ":", "session", ",", "DryRun", ":", "dryRun", ",", "}", "\n", "}" ]
// NewProvider with session and dry run
[ "NewProvider", "with", "session", "and", "dry", "run" ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/service/provider.go#L24-L29
25,238
apex/apex
service/provider.go
NewService
func (p *Provider) NewService(cfg *aws.Config) lambdaiface.LambdaAPI { if p.DryRun { return dryrun.New(p.Session) } else if cfg != nil { return lambda.New(p.Session, cfg) } else { return lambda.New(p.Session) } }
go
func (p *Provider) NewService(cfg *aws.Config) lambdaiface.LambdaAPI { if p.DryRun { return dryrun.New(p.Session) } else if cfg != nil { return lambda.New(p.Session, cfg) } else { return lambda.New(p.Session) } }
[ "func", "(", "p", "*", "Provider", ")", "NewService", "(", "cfg", "*", "aws", ".", "Config", ")", "lambdaiface", ".", "LambdaAPI", "{", "if", "p", ".", "DryRun", "{", "return", "dryrun", ".", "New", "(", "p", ".", "Session", ")", "\n", "}", "else",...
// NewService returns Lambda service with AWS config
[ "NewService", "returns", "Lambda", "service", "with", "AWS", "config" ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/service/provider.go#L32-L40
25,239
apex/apex
plugins/shim/shim.go
Build
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if fn.Shim { fn.Log.Debug("add shim") if err := zip.AddBytes("index.js", shim.MustAsset("index.js")); err != nil { return err } if err := zip.AddBytes("byline.js", shim.MustAsset("byline.js")); err != nil { return err } } retu...
go
func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if fn.Shim { fn.Log.Debug("add shim") if err := zip.AddBytes("index.js", shim.MustAsset("index.js")); err != nil { return err } if err := zip.AddBytes("byline.js", shim.MustAsset("byline.js")); err != nil { return err } } retu...
[ "func", "(", "p", "*", "Plugin", ")", "Build", "(", "fn", "*", "function", ".", "Function", ",", "zip", "*", "archive", ".", "Zip", ")", "error", "{", "if", "fn", ".", "Shim", "{", "fn", ".", "Log", ".", "Debug", "(", "\"", "\"", ")", "\n\n", ...
// Build adds the nodejs shim files.
[ "Build", "adds", "the", "nodejs", "shim", "files", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/plugins/shim/shim.go#L19-L33
25,240
apex/apex
cmd/apex/list/list.go
outputTFvars
func outputTFvars() { for _, fn := range root.Project.Functions { config, err := fn.GetConfig() if err != nil { log.Debugf("can't fetch function config: %s", err.Error()) continue } fmt.Printf("apex_function_%s=%q\n", fn.Name, *config.Configuration.FunctionArn) } }
go
func outputTFvars() { for _, fn := range root.Project.Functions { config, err := fn.GetConfig() if err != nil { log.Debugf("can't fetch function config: %s", err.Error()) continue } fmt.Printf("apex_function_%s=%q\n", fn.Name, *config.Configuration.FunctionArn) } }
[ "func", "outputTFvars", "(", ")", "{", "for", "_", ",", "fn", ":=", "range", "root", ".", "Project", ".", "Functions", "{", "config", ",", "err", ":=", "fn", ".", "GetConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Debugf", "...
// outputTFvars format.
[ "outputTFvars", "format", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/list/list.go#L61-L71
25,241
apex/apex
cmd/apex/list/list.go
outputList
func outputList() { fmt.Println() for _, fn := range root.Project.Functions { awsFn, err := fn.GetConfigCurrent() if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ResourceNotFoundException" { fmt.Printf(" \033[%dm%s\033[0m (not deployed) \n", colors.Blue, fn.Name) } else { fmt.Printf(" \033...
go
func outputList() { fmt.Println() for _, fn := range root.Project.Functions { awsFn, err := fn.GetConfigCurrent() if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ResourceNotFoundException" { fmt.Printf(" \033[%dm%s\033[0m (not deployed) \n", colors.Blue, fn.Name) } else { fmt.Printf(" \033...
[ "func", "outputList", "(", ")", "{", "fmt", ".", "Println", "(", ")", "\n", "for", "_", ",", "fn", ":=", "range", "root", ".", "Project", ".", "Functions", "{", "awsFn", ",", "err", ":=", "fn", ".", "GetConfigCurrent", "(", ")", "\n\n", "if", "awse...
// outputList format.
[ "outputList", "format", "." ]
c31f0a78ce189a8328563fa6a6eb97d04ace4284
https://github.com/apex/apex/blob/c31f0a78ce189a8328563fa6a6eb97d04ace4284/cmd/apex/list/list.go#L74-L120
25,242
xtaci/kcp-go
fec.go
freeRange
func (dec *fecDecoder) freeRange(first, n int, q []fecPacket) []fecPacket { for i := first; i < first+n; i++ { // recycle buffer xmitBuf.Put([]byte(q[i])) } if first == 0 && n < len(q)/2 { return q[n:] } copy(q[first:], q[first+n:]) return q[:len(q)-n] }
go
func (dec *fecDecoder) freeRange(first, n int, q []fecPacket) []fecPacket { for i := first; i < first+n; i++ { // recycle buffer xmitBuf.Put([]byte(q[i])) } if first == 0 && n < len(q)/2 { return q[n:] } copy(q[first:], q[first+n:]) return q[:len(q)-n] }
[ "func", "(", "dec", "*", "fecDecoder", ")", "freeRange", "(", "first", ",", "n", "int", ",", "q", "[", "]", "fecPacket", ")", "[", "]", "fecPacket", "{", "for", "i", ":=", "first", ";", "i", "<", "first", "+", "n", ";", "i", "++", "{", "// recy...
// free a range of fecPacket
[ "free", "a", "range", "of", "fecPacket" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/fec.go#L178-L188
25,243
xtaci/kcp-go
readloop_linux.go
readLoop
func (s *UDPSession) readLoop() { addr, _ := net.ResolveUDPAddr("udp", s.conn.LocalAddr().String()) if addr.IP.To4() != nil { s.readLoopIPv4() } else { s.readLoopIPv6() } }
go
func (s *UDPSession) readLoop() { addr, _ := net.ResolveUDPAddr("udp", s.conn.LocalAddr().String()) if addr.IP.To4() != nil { s.readLoopIPv4() } else { s.readLoopIPv6() } }
[ "func", "(", "s", "*", "UDPSession", ")", "readLoop", "(", ")", "{", "addr", ",", "_", ":=", "net", ".", "ResolveUDPAddr", "(", "\"", "\"", ",", "s", ".", "conn", ".", "LocalAddr", "(", ")", ".", "String", "(", ")", ")", "\n", "if", "addr", "."...
// the read loop for a client session
[ "the", "read", "loop", "for", "a", "client", "session" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/readloop_linux.go#L19-L26
25,244
xtaci/kcp-go
readloop_linux.go
monitor
func (l *Listener) monitor() { addr, _ := net.ResolveUDPAddr("udp", l.conn.LocalAddr().String()) if addr.IP.To4() != nil { l.monitorIPv4() } else { l.monitorIPv6() } }
go
func (l *Listener) monitor() { addr, _ := net.ResolveUDPAddr("udp", l.conn.LocalAddr().String()) if addr.IP.To4() != nil { l.monitorIPv4() } else { l.monitorIPv6() } }
[ "func", "(", "l", "*", "Listener", ")", "monitor", "(", ")", "{", "addr", ",", "_", ":=", "net", ".", "ResolveUDPAddr", "(", "\"", "\"", ",", "l", ".", "conn", ".", "LocalAddr", "(", ")", ".", "String", "(", ")", ")", "\n", "if", "addr", ".", ...
// monitor incoming data for all connections of server
[ "monitor", "incoming", "data", "for", "all", "connections", "of", "server" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/readloop_linux.go#L100-L107
25,245
xtaci/kcp-go
kcp.go
encode
func (seg *segment) encode(ptr []byte) []byte { ptr = ikcp_encode32u(ptr, seg.conv) ptr = ikcp_encode8u(ptr, seg.cmd) ptr = ikcp_encode8u(ptr, seg.frg) ptr = ikcp_encode16u(ptr, seg.wnd) ptr = ikcp_encode32u(ptr, seg.ts) ptr = ikcp_encode32u(ptr, seg.sn) ptr = ikcp_encode32u(ptr, seg.una) ptr = ikcp_encode32u(p...
go
func (seg *segment) encode(ptr []byte) []byte { ptr = ikcp_encode32u(ptr, seg.conv) ptr = ikcp_encode8u(ptr, seg.cmd) ptr = ikcp_encode8u(ptr, seg.frg) ptr = ikcp_encode16u(ptr, seg.wnd) ptr = ikcp_encode32u(ptr, seg.ts) ptr = ikcp_encode32u(ptr, seg.sn) ptr = ikcp_encode32u(ptr, seg.una) ptr = ikcp_encode32u(p...
[ "func", "(", "seg", "*", "segment", ")", "encode", "(", "ptr", "[", "]", "byte", ")", "[", "]", "byte", "{", "ptr", "=", "ikcp_encode32u", "(", "ptr", ",", "seg", ".", "conv", ")", "\n", "ptr", "=", "ikcp_encode8u", "(", "ptr", ",", "seg", ".", ...
// encode a segment into buffer
[ "encode", "a", "segment", "into", "buffer" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L112-L123
25,246
xtaci/kcp-go
kcp.go
NewKCP
func NewKCP(conv uint32, output output_callback) *KCP { kcp := new(KCP) kcp.conv = conv kcp.snd_wnd = IKCP_WND_SND kcp.rcv_wnd = IKCP_WND_RCV kcp.rmt_wnd = IKCP_WND_RCV kcp.mtu = IKCP_MTU_DEF kcp.mss = kcp.mtu - IKCP_OVERHEAD kcp.buffer = make([]byte, kcp.mtu) kcp.rx_rto = IKCP_RTO_DEF kcp.rx_minrto = IKCP_RT...
go
func NewKCP(conv uint32, output output_callback) *KCP { kcp := new(KCP) kcp.conv = conv kcp.snd_wnd = IKCP_WND_SND kcp.rcv_wnd = IKCP_WND_RCV kcp.rmt_wnd = IKCP_WND_RCV kcp.mtu = IKCP_MTU_DEF kcp.mss = kcp.mtu - IKCP_OVERHEAD kcp.buffer = make([]byte, kcp.mtu) kcp.rx_rto = IKCP_RTO_DEF kcp.rx_minrto = IKCP_RT...
[ "func", "NewKCP", "(", "conv", "uint32", ",", "output", "output_callback", ")", "*", "KCP", "{", "kcp", ":=", "new", "(", "KCP", ")", "\n", "kcp", ".", "conv", "=", "conv", "\n", "kcp", ".", "snd_wnd", "=", "IKCP_WND_SND", "\n", "kcp", ".", "rcv_wnd"...
// NewKCP create a new kcp control object, 'conv' must equal in two endpoint // from the same connection.
[ "NewKCP", "create", "a", "new", "kcp", "control", "object", "conv", "must", "equal", "in", "two", "endpoint", "from", "the", "same", "connection", "." ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L160-L177
25,247
xtaci/kcp-go
kcp.go
newSegment
func (kcp *KCP) newSegment(size int) (seg segment) { seg.data = xmitBuf.Get().([]byte)[:size] return }
go
func (kcp *KCP) newSegment(size int) (seg segment) { seg.data = xmitBuf.Get().([]byte)[:size] return }
[ "func", "(", "kcp", "*", "KCP", ")", "newSegment", "(", "size", "int", ")", "(", "seg", "segment", ")", "{", "seg", ".", "data", "=", "xmitBuf", ".", "Get", "(", ")", ".", "(", "[", "]", "byte", ")", "[", ":", "size", "]", "\n", "return", "\n...
// newSegment creates a KCP segment
[ "newSegment", "creates", "a", "KCP", "segment" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L180-L183
25,248
xtaci/kcp-go
kcp.go
delSegment
func (kcp *KCP) delSegment(seg *segment) { if seg.data != nil { xmitBuf.Put(seg.data) seg.data = nil } }
go
func (kcp *KCP) delSegment(seg *segment) { if seg.data != nil { xmitBuf.Put(seg.data) seg.data = nil } }
[ "func", "(", "kcp", "*", "KCP", ")", "delSegment", "(", "seg", "*", "segment", ")", "{", "if", "seg", ".", "data", "!=", "nil", "{", "xmitBuf", ".", "Put", "(", "seg", ".", "data", ")", "\n", "seg", ".", "data", "=", "nil", "\n", "}", "\n", "...
// delSegment recycles a KCP segment
[ "delSegment", "recycles", "a", "KCP", "segment" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L186-L191
25,249
xtaci/kcp-go
kcp.go
ReserveBytes
func (kcp *KCP) ReserveBytes(n int) bool { if n >= int(kcp.mtu-IKCP_OVERHEAD) || n < 0 { return false } kcp.reserved = n kcp.mss = kcp.mtu - IKCP_OVERHEAD - uint32(n) return true }
go
func (kcp *KCP) ReserveBytes(n int) bool { if n >= int(kcp.mtu-IKCP_OVERHEAD) || n < 0 { return false } kcp.reserved = n kcp.mss = kcp.mtu - IKCP_OVERHEAD - uint32(n) return true }
[ "func", "(", "kcp", "*", "KCP", ")", "ReserveBytes", "(", "n", "int", ")", "bool", "{", "if", "n", ">=", "int", "(", "kcp", ".", "mtu", "-", "IKCP_OVERHEAD", ")", "||", "n", "<", "0", "{", "return", "false", "\n", "}", "\n", "kcp", ".", "reserv...
// ReserveBytes keeps n bytes untouched from the beginning of the buffer // the output_callback function should be aware of this // return false if n >= mss
[ "ReserveBytes", "keeps", "n", "bytes", "untouched", "from", "the", "beginning", "of", "the", "buffer", "the", "output_callback", "function", "should", "be", "aware", "of", "this", "return", "false", "if", "n", ">", "=", "mss" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L196-L203
25,250
xtaci/kcp-go
kcp.go
PeekSize
func (kcp *KCP) PeekSize() (length int) { if len(kcp.rcv_queue) == 0 { return -1 } seg := &kcp.rcv_queue[0] if seg.frg == 0 { return len(seg.data) } if len(kcp.rcv_queue) < int(seg.frg+1) { return -1 } for k := range kcp.rcv_queue { seg := &kcp.rcv_queue[k] length += len(seg.data) if seg.frg == 0...
go
func (kcp *KCP) PeekSize() (length int) { if len(kcp.rcv_queue) == 0 { return -1 } seg := &kcp.rcv_queue[0] if seg.frg == 0 { return len(seg.data) } if len(kcp.rcv_queue) < int(seg.frg+1) { return -1 } for k := range kcp.rcv_queue { seg := &kcp.rcv_queue[k] length += len(seg.data) if seg.frg == 0...
[ "func", "(", "kcp", "*", "KCP", ")", "PeekSize", "(", ")", "(", "length", "int", ")", "{", "if", "len", "(", "kcp", ".", "rcv_queue", ")", "==", "0", "{", "return", "-", "1", "\n", "}", "\n\n", "seg", ":=", "&", "kcp", ".", "rcv_queue", "[", ...
// PeekSize checks the size of next message in the recv queue
[ "PeekSize", "checks", "the", "size", "of", "next", "message", "in", "the", "recv", "queue" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L206-L228
25,251
xtaci/kcp-go
kcp.go
parse_data
func (kcp *KCP) parse_data(newseg segment) bool { sn := newseg.sn if _itimediff(sn, kcp.rcv_nxt+kcp.rcv_wnd) >= 0 || _itimediff(sn, kcp.rcv_nxt) < 0 { return true } n := len(kcp.rcv_buf) - 1 insert_idx := 0 repeat := false for i := n; i >= 0; i-- { seg := &kcp.rcv_buf[i] if seg.sn == sn { repeat = tr...
go
func (kcp *KCP) parse_data(newseg segment) bool { sn := newseg.sn if _itimediff(sn, kcp.rcv_nxt+kcp.rcv_wnd) >= 0 || _itimediff(sn, kcp.rcv_nxt) < 0 { return true } n := len(kcp.rcv_buf) - 1 insert_idx := 0 repeat := false for i := n; i >= 0; i-- { seg := &kcp.rcv_buf[i] if seg.sn == sn { repeat = tr...
[ "func", "(", "kcp", "*", "KCP", ")", "parse_data", "(", "newseg", "segment", ")", "bool", "{", "sn", ":=", "newseg", ".", "sn", "\n", "if", "_itimediff", "(", "sn", ",", "kcp", ".", "rcv_nxt", "+", "kcp", ".", "rcv_wnd", ")", ">=", "0", "||", "_i...
// returns true if data has repeated
[ "returns", "true", "if", "data", "has", "repeated" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L453-L507
25,252
xtaci/kcp-go
kcp.go
SetMtu
func (kcp *KCP) SetMtu(mtu int) int { if mtu < 50 || mtu < IKCP_OVERHEAD { return -1 } if kcp.reserved >= int(kcp.mtu-IKCP_OVERHEAD) || kcp.reserved < 0 { return -1 } buffer := make([]byte, mtu) if buffer == nil { return -2 } kcp.mtu = uint32(mtu) kcp.mss = kcp.mtu - IKCP_OVERHEAD - uint32(kcp.reserved)...
go
func (kcp *KCP) SetMtu(mtu int) int { if mtu < 50 || mtu < IKCP_OVERHEAD { return -1 } if kcp.reserved >= int(kcp.mtu-IKCP_OVERHEAD) || kcp.reserved < 0 { return -1 } buffer := make([]byte, mtu) if buffer == nil { return -2 } kcp.mtu = uint32(mtu) kcp.mss = kcp.mtu - IKCP_OVERHEAD - uint32(kcp.reserved)...
[ "func", "(", "kcp", "*", "KCP", ")", "SetMtu", "(", "mtu", "int", ")", "int", "{", "if", "mtu", "<", "50", "||", "mtu", "<", "IKCP_OVERHEAD", "{", "return", "-", "1", "\n", "}", "\n", "if", "kcp", ".", "reserved", ">=", "int", "(", "kcp", ".", ...
// SetMtu changes MTU size, default is 1400
[ "SetMtu", "changes", "MTU", "size", "default", "is", "1400" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L957-L973
25,253
xtaci/kcp-go
kcp.go
WaitSnd
func (kcp *KCP) WaitSnd() int { return len(kcp.snd_buf) + len(kcp.snd_queue) }
go
func (kcp *KCP) WaitSnd() int { return len(kcp.snd_buf) + len(kcp.snd_queue) }
[ "func", "(", "kcp", "*", "KCP", ")", "WaitSnd", "(", ")", "int", "{", "return", "len", "(", "kcp", ".", "snd_buf", ")", "+", "len", "(", "kcp", ".", "snd_queue", ")", "\n", "}" ]
// WaitSnd gets how many packet is waiting to be sent
[ "WaitSnd", "gets", "how", "many", "packet", "is", "waiting", "to", "be", "sent" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/kcp.go#L1019-L1021
25,254
xtaci/kcp-go
sess.go
newUDPSession
func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn net.PacketConn, remote net.Addr, block BlockCrypt) *UDPSession { sess := new(UDPSession) sess.die = make(chan struct{}) sess.nonce = new(nonceAES128) sess.nonce.Init() sess.chReadEvent = make(chan struct{}, 1) sess.chWriteEvent = make...
go
func newUDPSession(conv uint32, dataShards, parityShards int, l *Listener, conn net.PacketConn, remote net.Addr, block BlockCrypt) *UDPSession { sess := new(UDPSession) sess.die = make(chan struct{}) sess.nonce = new(nonceAES128) sess.nonce.Init() sess.chReadEvent = make(chan struct{}, 1) sess.chWriteEvent = make...
[ "func", "newUDPSession", "(", "conv", "uint32", ",", "dataShards", ",", "parityShards", "int", ",", "l", "*", "Listener", ",", "conn", "net", ".", "PacketConn", ",", "remote", "net", ".", "Addr", ",", "block", "BlockCrypt", ")", "*", "UDPSession", "{", "...
// newUDPSession create a new udp session for client or server
[ "newUDPSession", "create", "a", "new", "udp", "session", "for", "client", "or", "server" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L113-L168
25,255
xtaci/kcp-go
sess.go
WriteBuffers
func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error) { for { s.mu.Lock() if s.isClosed { s.mu.Unlock() return 0, errors.New(errBrokenPipe) } if s.kcp.WaitSnd() < int(s.kcp.snd_wnd) { for _, b := range v { n += len(b) for { if len(b) <= int(s.kcp.mss) { s.kcp.Send(b) ...
go
func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error) { for { s.mu.Lock() if s.isClosed { s.mu.Unlock() return 0, errors.New(errBrokenPipe) } if s.kcp.WaitSnd() < int(s.kcp.snd_wnd) { for _, b := range v { n += len(b) for { if len(b) <= int(s.kcp.mss) { s.kcp.Send(b) ...
[ "func", "(", "s", "*", "UDPSession", ")", "WriteBuffers", "(", "v", "[", "]", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "for", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "if", "s", ".", "isClosed", "{", "...
// WriteBuffers write a vector of byte slices to the underlying connection
[ "WriteBuffers", "write", "a", "vector", "of", "byte", "slices", "to", "the", "underlying", "connection" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L247-L305
25,256
xtaci/kcp-go
sess.go
SetWriteDelay
func (s *UDPSession) SetWriteDelay(delay bool) { s.mu.Lock() defer s.mu.Unlock() s.writeDelay = delay }
go
func (s *UDPSession) SetWriteDelay(delay bool) { s.mu.Lock() defer s.mu.Unlock() s.writeDelay = delay }
[ "func", "(", "s", "*", "UDPSession", ")", "SetWriteDelay", "(", "delay", "bool", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "s", ".", "writeDelay", "=", "delay", "\n", "}" ]
// SetWriteDelay delays write for bulk transfer until the next update interval
[ "SetWriteDelay", "delays", "write", "for", "bulk", "transfer", "until", "the", "next", "update", "interval" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L365-L369
25,257
xtaci/kcp-go
sess.go
SetWindowSize
func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int) { s.mu.Lock() defer s.mu.Unlock() s.kcp.WndSize(sndwnd, rcvwnd) }
go
func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int) { s.mu.Lock() defer s.mu.Unlock() s.kcp.WndSize(sndwnd, rcvwnd) }
[ "func", "(", "s", "*", "UDPSession", ")", "SetWindowSize", "(", "sndwnd", ",", "rcvwnd", "int", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "s", ".", "kcp", ".", "WndSize", "(",...
// SetWindowSize set maximum window size
[ "SetWindowSize", "set", "maximum", "window", "size" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L372-L376
25,258
xtaci/kcp-go
sess.go
SetACKNoDelay
func (s *UDPSession) SetACKNoDelay(nodelay bool) { s.mu.Lock() defer s.mu.Unlock() s.ackNoDelay = nodelay }
go
func (s *UDPSession) SetACKNoDelay(nodelay bool) { s.mu.Lock() defer s.mu.Unlock() s.ackNoDelay = nodelay }
[ "func", "(", "s", "*", "UDPSession", ")", "SetACKNoDelay", "(", "nodelay", "bool", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "s", ".", "ackNoDelay", "=", "nodelay", "\n", "}" ]
// SetACKNoDelay changes ack flush option, set true to flush ack immediately,
[ "SetACKNoDelay", "changes", "ack", "flush", "option", "set", "true", "to", "flush", "ack", "immediately" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L402-L406
25,259
xtaci/kcp-go
sess.go
SetDUP
func (s *UDPSession) SetDUP(dup int) { s.mu.Lock() defer s.mu.Unlock() s.dup = dup }
go
func (s *UDPSession) SetDUP(dup int) { s.mu.Lock() defer s.mu.Unlock() s.dup = dup }
[ "func", "(", "s", "*", "UDPSession", ")", "SetDUP", "(", "dup", "int", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "s", ".", "dup", "=", "dup", "\n", "}" ]
// SetDUP duplicates udp packets for kcp output, for testing purpose only
[ "SetDUP", "duplicates", "udp", "packets", "for", "kcp", "output", "for", "testing", "purpose", "only" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L409-L413
25,260
xtaci/kcp-go
sess.go
SetReadBuffer
func (s *UDPSession) SetReadBuffer(bytes int) error { s.mu.Lock() defer s.mu.Unlock() if s.l == nil { if nc, ok := s.conn.(setReadBuffer); ok { return nc.SetReadBuffer(bytes) } } return errors.New(errInvalidOperation) }
go
func (s *UDPSession) SetReadBuffer(bytes int) error { s.mu.Lock() defer s.mu.Unlock() if s.l == nil { if nc, ok := s.conn.(setReadBuffer); ok { return nc.SetReadBuffer(bytes) } } return errors.New(errInvalidOperation) }
[ "func", "(", "s", "*", "UDPSession", ")", "SetReadBuffer", "(", "bytes", "int", ")", "error", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "l", "==", "nil", "{", "if...
// SetReadBuffer sets the socket read buffer, no effect if it's accepted from Listener
[ "SetReadBuffer", "sets", "the", "socket", "read", "buffer", "no", "effect", "if", "it", "s", "accepted", "from", "Listener" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L441-L450
25,261
xtaci/kcp-go
sess.go
update
func (s *UDPSession) update() (interval time.Duration) { s.mu.Lock() waitsnd := s.kcp.WaitSnd() interval = time.Duration(s.kcp.flush(false)) * time.Millisecond if s.kcp.WaitSnd() < waitsnd { s.notifyWriteEvent() } s.mu.Unlock() return }
go
func (s *UDPSession) update() (interval time.Duration) { s.mu.Lock() waitsnd := s.kcp.WaitSnd() interval = time.Duration(s.kcp.flush(false)) * time.Millisecond if s.kcp.WaitSnd() < waitsnd { s.notifyWriteEvent() } s.mu.Unlock() return }
[ "func", "(", "s", "*", "UDPSession", ")", "update", "(", ")", "(", "interval", "time", ".", "Duration", ")", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "waitsnd", ":=", "s", ".", "kcp", ".", "WaitSnd", "(", ")", "\n", "interval", "=", "t...
// kcp update, returns interval for next calling
[ "kcp", "update", "returns", "interval", "for", "next", "calling" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L518-L527
25,262
xtaci/kcp-go
sess.go
SetReadBuffer
func (l *Listener) SetReadBuffer(bytes int) error { if nc, ok := l.conn.(setReadBuffer); ok { return nc.SetReadBuffer(bytes) } return errors.New(errInvalidOperation) }
go
func (l *Listener) SetReadBuffer(bytes int) error { if nc, ok := l.conn.(setReadBuffer); ok { return nc.SetReadBuffer(bytes) } return errors.New(errInvalidOperation) }
[ "func", "(", "l", "*", "Listener", ")", "SetReadBuffer", "(", "bytes", "int", ")", "error", "{", "if", "nc", ",", "ok", ":=", "l", ".", "conn", ".", "(", "setReadBuffer", ")", ";", "ok", "{", "return", "nc", ".", "SetReadBuffer", "(", "bytes", ")",...
// SetReadBuffer sets the socket read buffer for the Listener
[ "SetReadBuffer", "sets", "the", "socket", "read", "buffer", "for", "the", "Listener" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L733-L738
25,263
xtaci/kcp-go
sess.go
SetWriteBuffer
func (l *Listener) SetWriteBuffer(bytes int) error { if nc, ok := l.conn.(setWriteBuffer); ok { return nc.SetWriteBuffer(bytes) } return errors.New(errInvalidOperation) }
go
func (l *Listener) SetWriteBuffer(bytes int) error { if nc, ok := l.conn.(setWriteBuffer); ok { return nc.SetWriteBuffer(bytes) } return errors.New(errInvalidOperation) }
[ "func", "(", "l", "*", "Listener", ")", "SetWriteBuffer", "(", "bytes", "int", ")", "error", "{", "if", "nc", ",", "ok", ":=", "l", ".", "conn", ".", "(", "setWriteBuffer", ")", ";", "ok", "{", "return", "nc", ".", "SetWriteBuffer", "(", "bytes", "...
// SetWriteBuffer sets the socket write buffer for the Listener
[ "SetWriteBuffer", "sets", "the", "socket", "write", "buffer", "for", "the", "Listener" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L741-L746
25,264
xtaci/kcp-go
sess.go
SetDSCP
func (l *Listener) SetDSCP(dscp int) error { if nc, ok := l.conn.(net.Conn); ok { addr, _ := net.ResolveUDPAddr("udp", nc.LocalAddr().String()) if addr.IP.To4() != nil { return ipv4.NewConn(nc).SetTOS(dscp << 2) } else { return ipv6.NewConn(nc).SetTrafficClass(dscp) } } return errors.New(errInvalidOper...
go
func (l *Listener) SetDSCP(dscp int) error { if nc, ok := l.conn.(net.Conn); ok { addr, _ := net.ResolveUDPAddr("udp", nc.LocalAddr().String()) if addr.IP.To4() != nil { return ipv4.NewConn(nc).SetTOS(dscp << 2) } else { return ipv6.NewConn(nc).SetTrafficClass(dscp) } } return errors.New(errInvalidOper...
[ "func", "(", "l", "*", "Listener", ")", "SetDSCP", "(", "dscp", "int", ")", "error", "{", "if", "nc", ",", "ok", ":=", "l", ".", "conn", ".", "(", "net", ".", "Conn", ")", ";", "ok", "{", "addr", ",", "_", ":=", "net", ".", "ResolveUDPAddr", ...
// SetDSCP sets the 6bit DSCP field of IP header
[ "SetDSCP", "sets", "the", "6bit", "DSCP", "field", "of", "IP", "header" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L749-L759
25,265
xtaci/kcp-go
sess.go
AcceptKCP
func (l *Listener) AcceptKCP() (*UDPSession, error) { var timeout <-chan time.Time if tdeadline, ok := l.rd.Load().(time.Time); ok && !tdeadline.IsZero() { timeout = time.After(tdeadline.Sub(time.Now())) } select { case <-timeout: return nil, &errTimeout{} case c := <-l.chAccepts: return c, nil case <-l.d...
go
func (l *Listener) AcceptKCP() (*UDPSession, error) { var timeout <-chan time.Time if tdeadline, ok := l.rd.Load().(time.Time); ok && !tdeadline.IsZero() { timeout = time.After(tdeadline.Sub(time.Now())) } select { case <-timeout: return nil, &errTimeout{} case c := <-l.chAccepts: return c, nil case <-l.d...
[ "func", "(", "l", "*", "Listener", ")", "AcceptKCP", "(", ")", "(", "*", "UDPSession", ",", "error", ")", "{", "var", "timeout", "<-", "chan", "time", ".", "Time", "\n", "if", "tdeadline", ",", "ok", ":=", "l", ".", "rd", ".", "Load", "(", ")", ...
// AcceptKCP accepts a KCP connection
[ "AcceptKCP", "accepts", "a", "KCP", "connection" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L767-L781
25,266
xtaci/kcp-go
sess.go
Close
func (l *Listener) Close() error { close(l.die) return l.conn.Close() }
go
func (l *Listener) Close() error { close(l.die) return l.conn.Close() }
[ "func", "(", "l", "*", "Listener", ")", "Close", "(", ")", "error", "{", "close", "(", "l", ".", "die", ")", "\n", "return", "l", ".", "conn", ".", "Close", "(", ")", "\n", "}" ]
// Close stops listening on the UDP address. Already Accepted connections are not closed.
[ "Close", "stops", "listening", "on", "the", "UDP", "address", ".", "Already", "Accepted", "connections", "are", "not", "closed", "." ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L803-L806
25,267
xtaci/kcp-go
sess.go
closeSession
func (l *Listener) closeSession(remote net.Addr) (ret bool) { l.sessionLock.Lock() defer l.sessionLock.Unlock() if _, ok := l.sessions[remote.String()]; ok { delete(l.sessions, remote.String()) return true } return false }
go
func (l *Listener) closeSession(remote net.Addr) (ret bool) { l.sessionLock.Lock() defer l.sessionLock.Unlock() if _, ok := l.sessions[remote.String()]; ok { delete(l.sessions, remote.String()) return true } return false }
[ "func", "(", "l", "*", "Listener", ")", "closeSession", "(", "remote", "net", ".", "Addr", ")", "(", "ret", "bool", ")", "{", "l", ".", "sessionLock", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "sessionLock", ".", "Unlock", "(", ")", "\n", "...
// closeSession notify the listener that a session has closed
[ "closeSession", "notify", "the", "listener", "that", "a", "session", "has", "closed" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L809-L817
25,268
xtaci/kcp-go
sess.go
ListenWithOptions
func ListenWithOptions(laddr string, block BlockCrypt, dataShards, parityShards int) (*Listener, error) { udpaddr, err := net.ResolveUDPAddr("udp", laddr) if err != nil { return nil, errors.Wrap(err, "net.ResolveUDPAddr") } conn, err := net.ListenUDP("udp", udpaddr) if err != nil { return nil, errors.Wrap(err,...
go
func ListenWithOptions(laddr string, block BlockCrypt, dataShards, parityShards int) (*Listener, error) { udpaddr, err := net.ResolveUDPAddr("udp", laddr) if err != nil { return nil, errors.Wrap(err, "net.ResolveUDPAddr") } conn, err := net.ListenUDP("udp", udpaddr) if err != nil { return nil, errors.Wrap(err,...
[ "func", "ListenWithOptions", "(", "laddr", "string", ",", "block", "BlockCrypt", ",", "dataShards", ",", "parityShards", "int", ")", "(", "*", "Listener", ",", "error", ")", "{", "udpaddr", ",", "err", ":=", "net", ".", "ResolveUDPAddr", "(", "\"", "\"", ...
// ListenWithOptions listens for incoming KCP packets addressed to the local address laddr on the network "udp" with packet encryption, // dataShards, parityShards defines Reed-Solomon Erasure Coding parameters
[ "ListenWithOptions", "listens", "for", "incoming", "KCP", "packets", "addressed", "to", "the", "local", "address", "laddr", "on", "the", "network", "udp", "with", "packet", "encryption", "dataShards", "parityShards", "defines", "Reed", "-", "Solomon", "Erasure", "...
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L827-L838
25,269
xtaci/kcp-go
sess.go
ServeConn
func ServeConn(block BlockCrypt, dataShards, parityShards int, conn net.PacketConn) (*Listener, error) { l := new(Listener) l.conn = conn l.sessions = make(map[string]*UDPSession) l.chAccepts = make(chan *UDPSession, acceptBacklog) l.chSessionClosed = make(chan net.Addr) l.die = make(chan struct{}) l.dataShards ...
go
func ServeConn(block BlockCrypt, dataShards, parityShards int, conn net.PacketConn) (*Listener, error) { l := new(Listener) l.conn = conn l.sessions = make(map[string]*UDPSession) l.chAccepts = make(chan *UDPSession, acceptBacklog) l.chSessionClosed = make(chan net.Addr) l.die = make(chan struct{}) l.dataShards ...
[ "func", "ServeConn", "(", "block", "BlockCrypt", ",", "dataShards", ",", "parityShards", "int", ",", "conn", "net", ".", "PacketConn", ")", "(", "*", "Listener", ",", "error", ")", "{", "l", ":=", "new", "(", "Listener", ")", "\n", "l", ".", "conn", ...
// ServeConn serves KCP protocol for a single packet connection.
[ "ServeConn", "serves", "KCP", "protocol", "for", "a", "single", "packet", "connection", "." ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L841-L863
25,270
xtaci/kcp-go
sess.go
DialWithOptions
func DialWithOptions(raddr string, block BlockCrypt, dataShards, parityShards int) (*UDPSession, error) { // network type detection udpaddr, err := net.ResolveUDPAddr("udp", raddr) if err != nil { return nil, errors.Wrap(err, "net.ResolveUDPAddr") } network := "udp4" if udpaddr.IP.To4() == nil { network = "ud...
go
func DialWithOptions(raddr string, block BlockCrypt, dataShards, parityShards int) (*UDPSession, error) { // network type detection udpaddr, err := net.ResolveUDPAddr("udp", raddr) if err != nil { return nil, errors.Wrap(err, "net.ResolveUDPAddr") } network := "udp4" if udpaddr.IP.To4() == nil { network = "ud...
[ "func", "DialWithOptions", "(", "raddr", "string", ",", "block", "BlockCrypt", ",", "dataShards", ",", "parityShards", "int", ")", "(", "*", "UDPSession", ",", "error", ")", "{", "// network type detection", "udpaddr", ",", "err", ":=", "net", ".", "ResolveUDP...
// DialWithOptions connects to the remote address "raddr" on the network "udp" with packet encryption
[ "DialWithOptions", "connects", "to", "the", "remote", "address", "raddr", "on", "the", "network", "udp", "with", "packet", "encryption" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L869-L886
25,271
xtaci/kcp-go
sess.go
NewConn
func NewConn(raddr string, block BlockCrypt, dataShards, parityShards int, conn net.PacketConn) (*UDPSession, error) { udpaddr, err := net.ResolveUDPAddr("udp", raddr) if err != nil { return nil, errors.Wrap(err, "net.ResolveUDPAddr") } var convid uint32 binary.Read(rand.Reader, binary.LittleEndian, &convid) r...
go
func NewConn(raddr string, block BlockCrypt, dataShards, parityShards int, conn net.PacketConn) (*UDPSession, error) { udpaddr, err := net.ResolveUDPAddr("udp", raddr) if err != nil { return nil, errors.Wrap(err, "net.ResolveUDPAddr") } var convid uint32 binary.Read(rand.Reader, binary.LittleEndian, &convid) r...
[ "func", "NewConn", "(", "raddr", "string", ",", "block", "BlockCrypt", ",", "dataShards", ",", "parityShards", "int", ",", "conn", "net", ".", "PacketConn", ")", "(", "*", "UDPSession", ",", "error", ")", "{", "udpaddr", ",", "err", ":=", "net", ".", "...
// NewConn establishes a session and talks KCP protocol over a packet connection.
[ "NewConn", "establishes", "a", "session", "and", "talks", "KCP", "protocol", "over", "a", "packet", "connection", "." ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/sess.go#L889-L898
25,272
xtaci/kcp-go
snmp.go
ToSlice
func (s *Snmp) ToSlice() []string { snmp := s.Copy() return []string{ fmt.Sprint(snmp.BytesSent), fmt.Sprint(snmp.BytesReceived), fmt.Sprint(snmp.MaxConn), fmt.Sprint(snmp.ActiveOpens), fmt.Sprint(snmp.PassiveOpens), fmt.Sprint(snmp.CurrEstab), fmt.Sprint(snmp.InErrs), fmt.Sprint(snmp.InCsumErrors), ...
go
func (s *Snmp) ToSlice() []string { snmp := s.Copy() return []string{ fmt.Sprint(snmp.BytesSent), fmt.Sprint(snmp.BytesReceived), fmt.Sprint(snmp.MaxConn), fmt.Sprint(snmp.ActiveOpens), fmt.Sprint(snmp.PassiveOpens), fmt.Sprint(snmp.CurrEstab), fmt.Sprint(snmp.InErrs), fmt.Sprint(snmp.InCsumErrors), ...
[ "func", "(", "s", "*", "Snmp", ")", "ToSlice", "(", ")", "[", "]", "string", "{", "snmp", ":=", "s", ".", "Copy", "(", ")", "\n", "return", "[", "]", "string", "{", "fmt", ".", "Sprint", "(", "snmp", ".", "BytesSent", ")", ",", "fmt", ".", "S...
// ToSlice returns current snmp info as slice
[ "ToSlice", "returns", "current", "snmp", "info", "as", "slice" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/snmp.go#L71-L99
25,273
xtaci/kcp-go
snmp.go
Copy
func (s *Snmp) Copy() *Snmp { d := newSnmp() d.BytesSent = atomic.LoadUint64(&s.BytesSent) d.BytesReceived = atomic.LoadUint64(&s.BytesReceived) d.MaxConn = atomic.LoadUint64(&s.MaxConn) d.ActiveOpens = atomic.LoadUint64(&s.ActiveOpens) d.PassiveOpens = atomic.LoadUint64(&s.PassiveOpens) d.CurrEstab = atomic.Loa...
go
func (s *Snmp) Copy() *Snmp { d := newSnmp() d.BytesSent = atomic.LoadUint64(&s.BytesSent) d.BytesReceived = atomic.LoadUint64(&s.BytesReceived) d.MaxConn = atomic.LoadUint64(&s.MaxConn) d.ActiveOpens = atomic.LoadUint64(&s.ActiveOpens) d.PassiveOpens = atomic.LoadUint64(&s.PassiveOpens) d.CurrEstab = atomic.Loa...
[ "func", "(", "s", "*", "Snmp", ")", "Copy", "(", ")", "*", "Snmp", "{", "d", ":=", "newSnmp", "(", ")", "\n", "d", ".", "BytesSent", "=", "atomic", ".", "LoadUint64", "(", "&", "s", ".", "BytesSent", ")", "\n", "d", ".", "BytesReceived", "=", "...
// Copy make a copy of current snmp snapshot
[ "Copy", "make", "a", "copy", "of", "current", "snmp", "snapshot" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/snmp.go#L102-L129
25,274
xtaci/kcp-go
snmp.go
Reset
func (s *Snmp) Reset() { atomic.StoreUint64(&s.BytesSent, 0) atomic.StoreUint64(&s.BytesReceived, 0) atomic.StoreUint64(&s.MaxConn, 0) atomic.StoreUint64(&s.ActiveOpens, 0) atomic.StoreUint64(&s.PassiveOpens, 0) atomic.StoreUint64(&s.CurrEstab, 0) atomic.StoreUint64(&s.InErrs, 0) atomic.StoreUint64(&s.InCsumErr...
go
func (s *Snmp) Reset() { atomic.StoreUint64(&s.BytesSent, 0) atomic.StoreUint64(&s.BytesReceived, 0) atomic.StoreUint64(&s.MaxConn, 0) atomic.StoreUint64(&s.ActiveOpens, 0) atomic.StoreUint64(&s.PassiveOpens, 0) atomic.StoreUint64(&s.CurrEstab, 0) atomic.StoreUint64(&s.InErrs, 0) atomic.StoreUint64(&s.InCsumErr...
[ "func", "(", "s", "*", "Snmp", ")", "Reset", "(", ")", "{", "atomic", ".", "StoreUint64", "(", "&", "s", ".", "BytesSent", ",", "0", ")", "\n", "atomic", ".", "StoreUint64", "(", "&", "s", ".", "BytesReceived", ",", "0", ")", "\n", "atomic", ".",...
// Reset values to zero
[ "Reset", "values", "to", "zero" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/snmp.go#L132-L157
25,275
xtaci/kcp-go
crypt.go
NewSimpleXORBlockCrypt
func NewSimpleXORBlockCrypt(key []byte) (BlockCrypt, error) { c := new(simpleXORBlockCrypt) c.xortbl = pbkdf2.Key(key, []byte(saltxor), 32, mtuLimit, sha1.New) return c, nil }
go
func NewSimpleXORBlockCrypt(key []byte) (BlockCrypt, error) { c := new(simpleXORBlockCrypt) c.xortbl = pbkdf2.Key(key, []byte(saltxor), 32, mtuLimit, sha1.New) return c, nil }
[ "func", "NewSimpleXORBlockCrypt", "(", "key", "[", "]", "byte", ")", "(", "BlockCrypt", ",", "error", ")", "{", "c", ":=", "new", "(", "simpleXORBlockCrypt", ")", "\n", "c", ".", "xortbl", "=", "pbkdf2", ".", "Key", "(", "key", ",", "[", "]", "byte",...
// NewSimpleXORBlockCrypt simple xor with key expanding
[ "NewSimpleXORBlockCrypt", "simple", "xor", "with", "key", "expanding" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/crypt.go#L224-L228
25,276
xtaci/kcp-go
crypt.go
encrypt
func encrypt(block cipher.Block, dst, src, buf []byte) { switch block.BlockSize() { case 8: encrypt8(block, dst, src, buf) case 16: encrypt16(block, dst, src, buf) default: encryptVariant(block, dst, src, buf) } }
go
func encrypt(block cipher.Block, dst, src, buf []byte) { switch block.BlockSize() { case 8: encrypt8(block, dst, src, buf) case 16: encrypt16(block, dst, src, buf) default: encryptVariant(block, dst, src, buf) } }
[ "func", "encrypt", "(", "block", "cipher", ".", "Block", ",", "dst", ",", "src", ",", "buf", "[", "]", "byte", ")", "{", "switch", "block", ".", "BlockSize", "(", ")", "{", "case", "8", ":", "encrypt8", "(", "block", ",", "dst", ",", "src", ",", ...
// packet encryption with local CFB mode
[ "packet", "encryption", "with", "local", "CFB", "mode" ]
88b8a1475ba14b58f41457c9c89b5ccd919f1c24
https://github.com/xtaci/kcp-go/blob/88b8a1475ba14b58f41457c9c89b5ccd919f1c24/crypt.go#L244-L253
25,277
hashicorp/yamux
addr.go
LocalAddr
func (s *Session) LocalAddr() net.Addr { addr, ok := s.conn.(hasAddr) if !ok { return &yamuxAddr{"local"} } return addr.LocalAddr() }
go
func (s *Session) LocalAddr() net.Addr { addr, ok := s.conn.(hasAddr) if !ok { return &yamuxAddr{"local"} } return addr.LocalAddr() }
[ "func", "(", "s", "*", "Session", ")", "LocalAddr", "(", ")", "net", ".", "Addr", "{", "addr", ",", "ok", ":=", "s", ".", "conn", ".", "(", "hasAddr", ")", "\n", "if", "!", "ok", "{", "return", "&", "yamuxAddr", "{", "\"", "\"", "}", "\n", "}...
// LocalAddr is used to get the local address of the // underlying connection.
[ "LocalAddr", "is", "used", "to", "get", "the", "local", "address", "of", "the", "underlying", "connection", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/addr.go#L34-L40
25,278
hashicorp/yamux
stream.go
newStream
func newStream(session *Session, id uint32, state streamState) *Stream { s := &Stream{ id: id, session: session, state: state, controlHdr: header(make([]byte, headerSize)), controlErr: make(chan error, 1), sendHdr: header(make([]byte, headerSize)), sendErr: make(chan e...
go
func newStream(session *Session, id uint32, state streamState) *Stream { s := &Stream{ id: id, session: session, state: state, controlHdr: header(make([]byte, headerSize)), controlErr: make(chan error, 1), sendHdr: header(make([]byte, headerSize)), sendErr: make(chan e...
[ "func", "newStream", "(", "session", "*", "Session", ",", "id", "uint32", ",", "state", "streamState", ")", "*", "Stream", "{", "s", ":=", "&", "Stream", "{", "id", ":", "id", ",", "session", ":", "session", ",", "state", ":", "state", ",", "controlH...
// newStream is used to construct a new stream within // a given session for an ID
[ "newStream", "is", "used", "to", "construct", "a", "new", "stream", "within", "a", "given", "session", "for", "an", "ID" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L56-L73
25,279
hashicorp/yamux
stream.go
Read
func (s *Stream) Read(b []byte) (n int, err error) { defer asyncNotify(s.recvNotifyCh) START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamRemoteClose: fallthrough case streamClosed: s.recvLock.Lock() if s.recvBuf == nil || s.recvBuf.Len() == 0 { s.recvLock.Unlock()...
go
func (s *Stream) Read(b []byte) (n int, err error) { defer asyncNotify(s.recvNotifyCh) START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamRemoteClose: fallthrough case streamClosed: s.recvLock.Lock() if s.recvBuf == nil || s.recvBuf.Len() == 0 { s.recvLock.Unlock()...
[ "func", "(", "s", "*", "Stream", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "defer", "asyncNotify", "(", "s", ".", "recvNotifyCh", ")", "\n", "START", ":", "s", ".", "stateLock", ".", "Lock", "...
// Read is used to read from the stream
[ "Read", "is", "used", "to", "read", "from", "the", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L86-L142
25,280
hashicorp/yamux
stream.go
Write
func (s *Stream) Write(b []byte) (n int, err error) { s.sendLock.Lock() defer s.sendLock.Unlock() total := 0 for total < len(b) { n, err := s.write(b[total:]) total += n if err != nil { return total, err } } return total, nil }
go
func (s *Stream) Write(b []byte) (n int, err error) { s.sendLock.Lock() defer s.sendLock.Unlock() total := 0 for total < len(b) { n, err := s.write(b[total:]) total += n if err != nil { return total, err } } return total, nil }
[ "func", "(", "s", "*", "Stream", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "s", ".", "sendLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "sendLock", ".", "Unlock", "(", ")", "\n", ...
// Write is used to write to the stream
[ "Write", "is", "used", "to", "write", "to", "the", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L145-L157
25,281
hashicorp/yamux
stream.go
write
func (s *Stream) write(b []byte) (n int, err error) { var flags uint16 var max uint32 var body io.Reader START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamClosed: s.stateLock.Unlock() return 0, ErrStreamClosed case streamReset: s.stateLock.Unlock() return 0, ErrC...
go
func (s *Stream) write(b []byte) (n int, err error) { var flags uint16 var max uint32 var body io.Reader START: s.stateLock.Lock() switch s.state { case streamLocalClose: fallthrough case streamClosed: s.stateLock.Unlock() return 0, ErrStreamClosed case streamReset: s.stateLock.Unlock() return 0, ErrC...
[ "func", "(", "s", "*", "Stream", ")", "write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "var", "flags", "uint16", "\n", "var", "max", "uint32", "\n", "var", "body", "io", ".", "Reader", "\n", "START", ":"...
// write is used to write to the stream, may return on // a short write.
[ "write", "is", "used", "to", "write", "to", "the", "stream", "may", "return", "on", "a", "short", "write", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L161-L218
25,282
hashicorp/yamux
stream.go
sendFlags
func (s *Stream) sendFlags() uint16 { s.stateLock.Lock() defer s.stateLock.Unlock() var flags uint16 switch s.state { case streamInit: flags |= flagSYN s.state = streamSYNSent case streamSYNReceived: flags |= flagACK s.state = streamEstablished } return flags }
go
func (s *Stream) sendFlags() uint16 { s.stateLock.Lock() defer s.stateLock.Unlock() var flags uint16 switch s.state { case streamInit: flags |= flagSYN s.state = streamSYNSent case streamSYNReceived: flags |= flagACK s.state = streamEstablished } return flags }
[ "func", "(", "s", "*", "Stream", ")", "sendFlags", "(", ")", "uint16", "{", "s", ".", "stateLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "stateLock", ".", "Unlock", "(", ")", "\n", "var", "flags", "uint16", "\n", "switch", "s", ".", "st...
// sendFlags determines any flags that are appropriate // based on the current stream state
[ "sendFlags", "determines", "any", "flags", "that", "are", "appropriate", "based", "on", "the", "current", "stream", "state" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L222-L235
25,283
hashicorp/yamux
stream.go
sendWindowUpdate
func (s *Stream) sendWindowUpdate() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() // Determine the delta update max := s.session.config.MaxStreamWindowSize var bufLen uint32 s.recvLock.Lock() if s.recvBuf != nil { bufLen = uint32(s.recvBuf.Len()) } delta := (max - bufLen) - s.recvWindow ...
go
func (s *Stream) sendWindowUpdate() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() // Determine the delta update max := s.session.config.MaxStreamWindowSize var bufLen uint32 s.recvLock.Lock() if s.recvBuf != nil { bufLen = uint32(s.recvBuf.Len()) } delta := (max - bufLen) - s.recvWindow ...
[ "func", "(", "s", "*", "Stream", ")", "sendWindowUpdate", "(", ")", "error", "{", "s", ".", "controlHdrLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "controlHdrLock", ".", "Unlock", "(", ")", "\n\n", "// Determine the delta update", "max", ":=", ...
// sendWindowUpdate potentially sends a window update enabling // further writes to take place. Must be invoked with the lock.
[ "sendWindowUpdate", "potentially", "sends", "a", "window", "update", "enabling", "further", "writes", "to", "take", "place", ".", "Must", "be", "invoked", "with", "the", "lock", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L239-L271
25,284
hashicorp/yamux
stream.go
sendClose
func (s *Stream) sendClose() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() flags := s.sendFlags() flags |= flagFIN s.controlHdr.encode(typeWindowUpdate, flags, s.id, 0) if err := s.session.waitForSendErr(s.controlHdr, nil, s.controlErr); err != nil { return err } return nil }
go
func (s *Stream) sendClose() error { s.controlHdrLock.Lock() defer s.controlHdrLock.Unlock() flags := s.sendFlags() flags |= flagFIN s.controlHdr.encode(typeWindowUpdate, flags, s.id, 0) if err := s.session.waitForSendErr(s.controlHdr, nil, s.controlErr); err != nil { return err } return nil }
[ "func", "(", "s", "*", "Stream", ")", "sendClose", "(", ")", "error", "{", "s", ".", "controlHdrLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "controlHdrLock", ".", "Unlock", "(", ")", "\n\n", "flags", ":=", "s", ".", "sendFlags", "(", ")"...
// sendClose is used to send a FIN
[ "sendClose", "is", "used", "to", "send", "a", "FIN" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L274-L285
25,285
hashicorp/yamux
stream.go
Close
func (s *Stream) Close() error { closeStream := false s.stateLock.Lock() switch s.state { // Opened means we need to signal a close case streamSYNSent: fallthrough case streamSYNReceived: fallthrough case streamEstablished: s.state = streamLocalClose goto SEND_CLOSE case streamLocalClose: case streamR...
go
func (s *Stream) Close() error { closeStream := false s.stateLock.Lock() switch s.state { // Opened means we need to signal a close case streamSYNSent: fallthrough case streamSYNReceived: fallthrough case streamEstablished: s.state = streamLocalClose goto SEND_CLOSE case streamLocalClose: case streamR...
[ "func", "(", "s", "*", "Stream", ")", "Close", "(", ")", "error", "{", "closeStream", ":=", "false", "\n", "s", ".", "stateLock", ".", "Lock", "(", ")", "\n", "switch", "s", ".", "state", "{", "// Opened means we need to signal a close", "case", "streamSYN...
// Close is used to close the stream
[ "Close", "is", "used", "to", "close", "the", "stream" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L288-L322
25,286
hashicorp/yamux
stream.go
forceClose
func (s *Stream) forceClose() { s.stateLock.Lock() s.state = streamClosed s.stateLock.Unlock() s.notifyWaiting() }
go
func (s *Stream) forceClose() { s.stateLock.Lock() s.state = streamClosed s.stateLock.Unlock() s.notifyWaiting() }
[ "func", "(", "s", "*", "Stream", ")", "forceClose", "(", ")", "{", "s", ".", "stateLock", ".", "Lock", "(", ")", "\n", "s", ".", "state", "=", "streamClosed", "\n", "s", ".", "stateLock", ".", "Unlock", "(", ")", "\n", "s", ".", "notifyWaiting", ...
// forceClose is used for when the session is exiting
[ "forceClose", "is", "used", "for", "when", "the", "session", "is", "exiting" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L325-L330
25,287
hashicorp/yamux
stream.go
processFlags
func (s *Stream) processFlags(flags uint16) error { // Close the stream without holding the state lock closeStream := false defer func() { if closeStream { s.session.closeStream(s.id) } }() s.stateLock.Lock() defer s.stateLock.Unlock() if flags&flagACK == flagACK { if s.state == streamSYNSent { s.st...
go
func (s *Stream) processFlags(flags uint16) error { // Close the stream without holding the state lock closeStream := false defer func() { if closeStream { s.session.closeStream(s.id) } }() s.stateLock.Lock() defer s.stateLock.Unlock() if flags&flagACK == flagACK { if s.state == streamSYNSent { s.st...
[ "func", "(", "s", "*", "Stream", ")", "processFlags", "(", "flags", "uint16", ")", "error", "{", "// Close the stream without holding the state lock", "closeStream", ":=", "false", "\n", "defer", "func", "(", ")", "{", "if", "closeStream", "{", "s", ".", "sess...
// processFlags is used to update the state of the stream // based on set flags, if any. Lock must be held
[ "processFlags", "is", "used", "to", "update", "the", "state", "of", "the", "stream", "based", "on", "set", "flags", "if", "any", ".", "Lock", "must", "be", "held" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L334-L375
25,288
hashicorp/yamux
stream.go
incrSendWindow
func (s *Stream) incrSendWindow(hdr header, flags uint16) error { if err := s.processFlags(flags); err != nil { return err } // Increase window, unblock a sender atomic.AddUint32(&s.sendWindow, hdr.Length()) asyncNotify(s.sendNotifyCh) return nil }
go
func (s *Stream) incrSendWindow(hdr header, flags uint16) error { if err := s.processFlags(flags); err != nil { return err } // Increase window, unblock a sender atomic.AddUint32(&s.sendWindow, hdr.Length()) asyncNotify(s.sendNotifyCh) return nil }
[ "func", "(", "s", "*", "Stream", ")", "incrSendWindow", "(", "hdr", "header", ",", "flags", "uint16", ")", "error", "{", "if", "err", ":=", "s", ".", "processFlags", "(", "flags", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n...
// incrSendWindow updates the size of our send window
[ "incrSendWindow", "updates", "the", "size", "of", "our", "send", "window" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L384-L393
25,289
hashicorp/yamux
stream.go
readData
func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error { if err := s.processFlags(flags); err != nil { return err } // Check that our recv window is not exceeded length := hdr.Length() if length == 0 { return nil } // Wrap in a limited reader conn = &io.LimitedReader{R: conn, N: int64(l...
go
func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error { if err := s.processFlags(flags); err != nil { return err } // Check that our recv window is not exceeded length := hdr.Length() if length == 0 { return nil } // Wrap in a limited reader conn = &io.LimitedReader{R: conn, N: int64(l...
[ "func", "(", "s", "*", "Stream", ")", "readData", "(", "hdr", "header", ",", "flags", "uint16", ",", "conn", "io", ".", "Reader", ")", "error", "{", "if", "err", ":=", "s", ".", "processFlags", "(", "flags", ")", ";", "err", "!=", "nil", "{", "re...
// readData is used to handle a data frame
[ "readData", "is", "used", "to", "handle", "a", "data", "frame" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L396-L436
25,290
hashicorp/yamux
stream.go
SetDeadline
func (s *Stream) SetDeadline(t time.Time) error { if err := s.SetReadDeadline(t); err != nil { return err } if err := s.SetWriteDeadline(t); err != nil { return err } return nil }
go
func (s *Stream) SetDeadline(t time.Time) error { if err := s.SetReadDeadline(t); err != nil { return err } if err := s.SetWriteDeadline(t); err != nil { return err } return nil }
[ "func", "(", "s", "*", "Stream", ")", "SetDeadline", "(", "t", "time", ".", "Time", ")", "error", "{", "if", "err", ":=", "s", ".", "SetReadDeadline", "(", "t", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "...
// SetDeadline sets the read and write deadlines
[ "SetDeadline", "sets", "the", "read", "and", "write", "deadlines" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L439-L447
25,291
hashicorp/yamux
stream.go
SetWriteDeadline
func (s *Stream) SetWriteDeadline(t time.Time) error { s.writeDeadline.Store(t) return nil }
go
func (s *Stream) SetWriteDeadline(t time.Time) error { s.writeDeadline.Store(t) return nil }
[ "func", "(", "s", "*", "Stream", ")", "SetWriteDeadline", "(", "t", "time", ".", "Time", ")", "error", "{", "s", ".", "writeDeadline", ".", "Store", "(", "t", ")", "\n", "return", "nil", "\n", "}" ]
// SetWriteDeadline sets the deadline for future Write calls
[ "SetWriteDeadline", "sets", "the", "deadline", "for", "future", "Write", "calls" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L456-L459
25,292
hashicorp/yamux
stream.go
Shrink
func (s *Stream) Shrink() { s.recvLock.Lock() if s.recvBuf != nil && s.recvBuf.Len() == 0 { s.recvBuf = nil } s.recvLock.Unlock() }
go
func (s *Stream) Shrink() { s.recvLock.Lock() if s.recvBuf != nil && s.recvBuf.Len() == 0 { s.recvBuf = nil } s.recvLock.Unlock() }
[ "func", "(", "s", "*", "Stream", ")", "Shrink", "(", ")", "{", "s", ".", "recvLock", ".", "Lock", "(", ")", "\n", "if", "s", ".", "recvBuf", "!=", "nil", "&&", "s", ".", "recvBuf", ".", "Len", "(", ")", "==", "0", "{", "s", ".", "recvBuf", ...
// Shrink is used to compact the amount of buffers utilized // This is useful when using Yamux in a connection pool to reduce // the idle memory utilization.
[ "Shrink", "is", "used", "to", "compact", "the", "amount", "of", "buffers", "utilized", "This", "is", "useful", "when", "using", "Yamux", "in", "a", "connection", "pool", "to", "reduce", "the", "idle", "memory", "utilization", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/stream.go#L464-L470
25,293
hashicorp/yamux
mux.go
Server
func Server(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, false), nil }
go
func Server(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, false), nil }
[ "func", "Server", "(", "conn", "io", ".", "ReadWriteCloser", ",", "config", "*", "Config", ")", "(", "*", "Session", ",", "error", ")", "{", "if", "config", "==", "nil", "{", "config", "=", "DefaultConfig", "(", ")", "\n", "}", "\n", "if", "err", "...
// Server is used to initialize a new server-side connection. // There must be at most one server-side connection. If a nil config is // provided, the DefaultConfiguration will be used.
[ "Server", "is", "used", "to", "initialize", "a", "new", "server", "-", "side", "connection", ".", "There", "must", "be", "at", "most", "one", "server", "-", "side", "connection", ".", "If", "a", "nil", "config", "is", "provided", "the", "DefaultConfigurati...
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/mux.go#L77-L85
25,294
hashicorp/yamux
mux.go
Client
func Client(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, true), nil }
go
func Client(conn io.ReadWriteCloser, config *Config) (*Session, error) { if config == nil { config = DefaultConfig() } if err := VerifyConfig(config); err != nil { return nil, err } return newSession(config, conn, true), nil }
[ "func", "Client", "(", "conn", "io", ".", "ReadWriteCloser", ",", "config", "*", "Config", ")", "(", "*", "Session", ",", "error", ")", "{", "if", "config", "==", "nil", "{", "config", "=", "DefaultConfig", "(", ")", "\n", "}", "\n\n", "if", "err", ...
// Client is used to initialize a new client-side connection. // There must be at most one client-side connection.
[ "Client", "is", "used", "to", "initialize", "a", "new", "client", "-", "side", "connection", ".", "There", "must", "be", "at", "most", "one", "client", "-", "side", "connection", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/mux.go#L89-L98
25,295
hashicorp/yamux
session.go
newSession
func newSession(config *Config, conn io.ReadWriteCloser, client bool) *Session { logger := config.Logger if logger == nil { logger = log.New(config.LogOutput, "", log.LstdFlags) } s := &Session{ config: config, logger: logger, conn: conn, bufRead: bufio.NewReader(conn), pings: mak...
go
func newSession(config *Config, conn io.ReadWriteCloser, client bool) *Session { logger := config.Logger if logger == nil { logger = log.New(config.LogOutput, "", log.LstdFlags) } s := &Session{ config: config, logger: logger, conn: conn, bufRead: bufio.NewReader(conn), pings: mak...
[ "func", "newSession", "(", "config", "*", "Config", ",", "conn", "io", ".", "ReadWriteCloser", ",", "client", "bool", ")", "*", "Session", "{", "logger", ":=", "config", ".", "Logger", "\n", "if", "logger", "==", "nil", "{", "logger", "=", "log", ".", ...
// newSession is used to construct a new session
[ "newSession", "is", "used", "to", "construct", "a", "new", "session" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L88-L119
25,296
hashicorp/yamux
session.go
NumStreams
func (s *Session) NumStreams() int { s.streamLock.Lock() num := len(s.streams) s.streamLock.Unlock() return num }
go
func (s *Session) NumStreams() int { s.streamLock.Lock() num := len(s.streams) s.streamLock.Unlock() return num }
[ "func", "(", "s", "*", "Session", ")", "NumStreams", "(", ")", "int", "{", "s", ".", "streamLock", ".", "Lock", "(", ")", "\n", "num", ":=", "len", "(", "s", ".", "streams", ")", "\n", "s", ".", "streamLock", ".", "Unlock", "(", ")", "\n", "ret...
// NumStreams returns the number of currently open streams
[ "NumStreams", "returns", "the", "number", "of", "currently", "open", "streams" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L138-L143
25,297
hashicorp/yamux
session.go
Open
func (s *Session) Open() (net.Conn, error) { conn, err := s.OpenStream() if err != nil { return nil, err } return conn, nil }
go
func (s *Session) Open() (net.Conn, error) { conn, err := s.OpenStream() if err != nil { return nil, err } return conn, nil }
[ "func", "(", "s", "*", "Session", ")", "Open", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "s", ".", "OpenStream", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}",...
// Open is used to create a new stream as a net.Conn
[ "Open", "is", "used", "to", "create", "a", "new", "stream", "as", "a", "net", ".", "Conn" ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L146-L152
25,298
hashicorp/yamux
session.go
Accept
func (s *Session) Accept() (net.Conn, error) { conn, err := s.AcceptStream() if err != nil { return nil, err } return conn, err }
go
func (s *Session) Accept() (net.Conn, error) { conn, err := s.AcceptStream() if err != nil { return nil, err } return conn, err }
[ "func", "(", "s", "*", "Session", ")", "Accept", "(", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "conn", ",", "err", ":=", "s", ".", "AcceptStream", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", ...
// Accept is used to block until the next available stream // is ready to be accepted.
[ "Accept", "is", "used", "to", "block", "until", "the", "next", "available", "stream", "is", "ready", "to", "be", "accepted", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L201-L207
25,299
hashicorp/yamux
session.go
Close
func (s *Session) Close() error { s.shutdownLock.Lock() defer s.shutdownLock.Unlock() if s.shutdown { return nil } s.shutdown = true if s.shutdownErr == nil { s.shutdownErr = ErrSessionShutdown } close(s.shutdownCh) s.conn.Close() <-s.recvDoneCh s.streamLock.Lock() defer s.streamLock.Unlock() for _, ...
go
func (s *Session) Close() error { s.shutdownLock.Lock() defer s.shutdownLock.Unlock() if s.shutdown { return nil } s.shutdown = true if s.shutdownErr == nil { s.shutdownErr = ErrSessionShutdown } close(s.shutdownCh) s.conn.Close() <-s.recvDoneCh s.streamLock.Lock() defer s.streamLock.Unlock() for _, ...
[ "func", "(", "s", "*", "Session", ")", "Close", "(", ")", "error", "{", "s", ".", "shutdownLock", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "shutdownLock", ".", "Unlock", "(", ")", "\n\n", "if", "s", ".", "shutdown", "{", "return", "nil", "...
// Close is used to close the session and all streams. // Attempts to send a GoAway before closing the connection.
[ "Close", "is", "used", "to", "close", "the", "session", "and", "all", "streams", ".", "Attempts", "to", "send", "a", "GoAway", "before", "closing", "the", "connection", "." ]
2f1d1f20f75d5404f53b9edf6b53ed5505508675
https://github.com/hashicorp/yamux/blob/2f1d1f20f75d5404f53b9edf6b53ed5505508675/session.go#L225-L246