-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add option for max connection #112
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,10 @@ import ( | |
"github.com/yudai/umutex" | ||
) | ||
|
||
var ( | ||
connection int = 0 | ||
) | ||
|
||
type InitMessage struct { | ||
Arguments string `json:"Arguments,omitempty"` | ||
AuthToken string `json:"AuthToken,omitempty"` | ||
|
@@ -62,6 +66,7 @@ type Options struct { | |
TitleFormat string `hcl:"title_format"` | ||
EnableReconnect bool `hcl:"enable_reconnect"` | ||
ReconnectTime int `hcl:"reconnect_time"` | ||
MaxConnection int `hcl:"max_connection"` | ||
Once bool `hcl:"once"` | ||
PermitArguments bool `hcl:"permit_arguments"` | ||
CloseSignal int `hcl:"close_signal"` | ||
|
@@ -88,6 +93,7 @@ var DefaultOptions = Options{ | |
TitleFormat: "GoTTY - {{ .Command }} ({{ .Hostname }})", | ||
EnableReconnect: false, | ||
ReconnectTime: 10, | ||
MaxConnection: 0, | ||
Once: false, | ||
CloseSignal: 1, // syscall.SIGHUP | ||
Preferences: HtermPrefernces{}, | ||
|
@@ -274,6 +280,12 @@ func (app *App) makeServer(addr string, handler *http.Handler) (*http.Server, er | |
} | ||
|
||
func (app *App) handleWS(w http.ResponseWriter, r *http.Request) { | ||
if app.options.MaxConnection != 0 { | ||
if connection >= app.options.MaxConnection { | ||
log.Printf("reached max connection: %d", app.options.MaxConnection) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log messages should start with a capital letter |
||
return | ||
} | ||
} | ||
log.Printf("New client connected: %s", r.RemoteAddr) | ||
|
||
if r.Method != "GET" { | ||
|
@@ -344,6 +356,9 @@ func (app *App) handleWS(w http.ResponseWriter, r *http.Request) { | |
} | ||
log.Printf("Command is running for client %s with PID %d (args=%q)", r.RemoteAddr, cmd.Process.Pid, strings.Join(argv, " ")) | ||
|
||
connection++ | ||
log.Printf("Connection: %d/%d\n", connection, app.options.MaxConnection) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should show when MaxConnection is not 0. And it's better to merge to the log line above ("Command is running....") |
||
|
||
context := &clientContext{ | ||
app: app, | ||
request: r, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable should be a member of the App struct.