-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jiekai
committed
Apr 25, 2016
1 parent
987f53f
commit 82952c3
Showing
4 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cmd/relay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package monitor | ||
|
||
import "github.com/golang/glog" | ||
|
||
var openPipe chan struct{} | ||
var closePipe chan struct{} | ||
|
||
func Init() { | ||
openPipe = make(chan struct{}) | ||
closePipe = make(chan struct{}) | ||
go monitor() | ||
} | ||
|
||
func monitor() { | ||
pipeCount := 0 | ||
for { | ||
select { | ||
case <-openPipe: | ||
pipeCount++ | ||
glog.Infof("a new pipe opened. %v pipe(s) open", pipeCount) | ||
case <-closePipe: | ||
pipeCount-- | ||
glog.Infof("an old pipe closed. %v pipe(s) open", pipeCount) | ||
} | ||
} | ||
} | ||
|
||
func PipeOpen() { | ||
openPipe <- struct{}{} | ||
} | ||
|
||
func PipeClose() { | ||
closePipe <- struct{}{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters