Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
haoqu.ma
/
gotty
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit be07d420
authored
Aug 13, 2016
by
Yifa Zhang
Committed by
Iwasaki Yudai
Aug 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add option for max connection (#112)
add option for max connection
1 parent
54597c0b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
2 deletions
.gotty
app/app.go
app/client_context.go
main.go
.gotty
View file @
be07d42
...
@@ -54,6 +54,9 @@
...
@@ -54,6 +54,9 @@
// To enable reconnection, set `true` to `enable_reconnect`
// To enable reconnection, set `true` to `enable_reconnect`
// reconnect_time = false
// reconnect_time = false
// [int] Maximum connection to gotty, 0(default) means no limit.
// max_connection = 0
// [bool] Accept only one client and exit gotty once the client exits
// [bool] Accept only one client and exit gotty once the client exits
// once = false
// once = false
...
...
app/app.go
View file @
be07d42
...
@@ -43,6 +43,8 @@ type App struct {
...
@@ -43,6 +43,8 @@ type App struct {
titleTemplate
*
template
.
Template
titleTemplate
*
template
.
Template
onceMutex
*
umutex
.
UnblockingMutex
onceMutex
*
umutex
.
UnblockingMutex
connections
int
}
}
type
Options
struct
{
type
Options
struct
{
...
@@ -62,6 +64,7 @@ type Options struct {
...
@@ -62,6 +64,7 @@ type Options struct {
TitleFormat
string
`hcl:"title_format"`
TitleFormat
string
`hcl:"title_format"`
EnableReconnect
bool
`hcl:"enable_reconnect"`
EnableReconnect
bool
`hcl:"enable_reconnect"`
ReconnectTime
int
`hcl:"reconnect_time"`
ReconnectTime
int
`hcl:"reconnect_time"`
MaxConnection
int
`hcl:"max_connection"`
Once
bool
`hcl:"once"`
Once
bool
`hcl:"once"`
PermitArguments
bool
`hcl:"permit_arguments"`
PermitArguments
bool
`hcl:"permit_arguments"`
CloseSignal
int
`hcl:"close_signal"`
CloseSignal
int
`hcl:"close_signal"`
...
@@ -88,6 +91,7 @@ var DefaultOptions = Options{
...
@@ -88,6 +91,7 @@ var DefaultOptions = Options{
TitleFormat
:
"GoTTY - {{ .Command }} ({{ .Hostname }})"
,
TitleFormat
:
"GoTTY - {{ .Command }} ({{ .Hostname }})"
,
EnableReconnect
:
false
,
EnableReconnect
:
false
,
ReconnectTime
:
10
,
ReconnectTime
:
10
,
MaxConnection
:
0
,
Once
:
false
,
Once
:
false
,
CloseSignal
:
1
,
// syscall.SIGHUP
CloseSignal
:
1
,
// syscall.SIGHUP
Preferences
:
HtermPrefernces
{},
Preferences
:
HtermPrefernces
{},
...
@@ -274,6 +278,12 @@ func (app *App) makeServer(addr string, handler *http.Handler) (*http.Server, er
...
@@ -274,6 +278,12 @@ func (app *App) makeServer(addr string, handler *http.Handler) (*http.Server, er
}
}
func
(
app
*
App
)
handleWS
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
app
*
App
)
handleWS
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
app
.
options
.
MaxConnection
!=
0
{
if
app
.
connections
>=
app
.
options
.
MaxConnection
{
log
.
Printf
(
"Reached max connection: %d"
,
app
.
options
.
MaxConnection
)
return
}
}
log
.
Printf
(
"New client connected: %s"
,
r
.
RemoteAddr
)
log
.
Printf
(
"New client connected: %s"
,
r
.
RemoteAddr
)
if
r
.
Method
!=
"GET"
{
if
r
.
Method
!=
"GET"
{
...
@@ -342,7 +352,15 @@ func (app *App) handleWS(w http.ResponseWriter, r *http.Request) {
...
@@ -342,7 +352,15 @@ func (app *App) handleWS(w http.ResponseWriter, r *http.Request) {
log
.
Print
(
"Failed to execute command"
)
log
.
Print
(
"Failed to execute command"
)
return
return
}
}
log
.
Printf
(
"Command is running for client %s with PID %d (args=%q)"
,
r
.
RemoteAddr
,
cmd
.
Process
.
Pid
,
strings
.
Join
(
argv
,
" "
))
app
.
connections
++
if
app
.
options
.
MaxConnection
!=
0
{
log
.
Printf
(
"Command is running for client %s with PID %d (args=%q), connections: %d/%d"
,
r
.
RemoteAddr
,
cmd
.
Process
.
Pid
,
strings
.
Join
(
argv
,
" "
),
app
.
connections
,
app
.
options
.
MaxConnection
)
}
else
{
log
.
Printf
(
"Command is running for client %s with PID %d (args=%q), connections: %d"
,
r
.
RemoteAddr
,
cmd
.
Process
.
Pid
,
strings
.
Join
(
argv
,
" "
),
app
.
connections
)
}
context
:=
&
clientContext
{
context
:=
&
clientContext
{
app
:
app
,
app
:
app
,
...
...
app/client_context.go
View file @
be07d42
...
@@ -79,7 +79,14 @@ func (context *clientContext) goHandleClient() {
...
@@ -79,7 +79,14 @@ func (context *clientContext) goHandleClient() {
context
.
command
.
Wait
()
context
.
command
.
Wait
()
context
.
connection
.
Close
()
context
.
connection
.
Close
()
log
.
Printf
(
"Connection closed: %s"
,
context
.
request
.
RemoteAddr
)
context
.
app
.
connections
--
if
context
.
app
.
options
.
MaxConnection
!=
0
{
log
.
Printf
(
"Connection closed: %s, connections: %d/%d"
,
context
.
request
.
RemoteAddr
,
context
.
app
.
connections
,
context
.
app
.
options
.
MaxConnection
)
}
else
{
log
.
Printf
(
"Connection closed: %s, connections: %d"
,
context
.
request
.
RemoteAddr
,
context
.
app
.
connections
)
}
}()
}()
}
}
...
...
main.go
View file @
be07d42
...
@@ -33,6 +33,7 @@ func main() {
...
@@ -33,6 +33,7 @@ func main() {
flag
{
"title-format"
,
""
,
"Title format of browser window"
},
flag
{
"title-format"
,
""
,
"Title format of browser window"
},
flag
{
"reconnect"
,
""
,
"Enable reconnection"
},
flag
{
"reconnect"
,
""
,
"Enable reconnection"
},
flag
{
"reconnect-time"
,
""
,
"Time to reconnect"
},
flag
{
"reconnect-time"
,
""
,
"Time to reconnect"
},
flag
{
"max-connection"
,
""
,
"Maximum connection to gotty, 0(default) means no limit"
},
flag
{
"once"
,
""
,
"Accept only one client and exit on disconnection"
},
flag
{
"once"
,
""
,
"Accept only one client and exit on disconnection"
},
flag
{
"permit-arguments"
,
""
,
"Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB)"
},
flag
{
"permit-arguments"
,
""
,
"Permit clients to send command line arguments in URL (e.g. http://example.com:8080/?arg=AAA&arg=BBB)"
},
flag
{
"close-signal"
,
""
,
"Signal sent to the command process when gotty close it (default: SIGHUP)"
},
flag
{
"close-signal"
,
""
,
"Signal sent to the command process when gotty close it (default: SIGHUP)"
},
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment