-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
53 lines (45 loc) · 707 Bytes
/
Copy pathutil.go
File metadata and controls
53 lines (45 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package anthem
import (
"io"
"log"
"net"
)
type errContain chan error
var(
errList = make( chan errContain,1024 ) //管道池
)
func generalErrChan()errContain{
if len(errList)==0{
return make(chan error,1)
}
return <-errList
}
func recycleErrChan(c errContain){
errList<-c
}
func SerToCli(ser, cli net.Conn)error{
log.Println("start translate")
ch:=generalErrChan()
defer recycleErrChan(ch)
go func() {
_,err:=io.Copy(cli,ser)
if err!=nil{
ch<-err
}
}()
if len(ch)!=0{
return <-ch
}
_,err:=io.Copy(ser,cli)
if err!=nil{
ch<-err
}
if len(ch)!=0{
return <-ch
}
return nil
}
type Msg struct {
Type string `json:"type"` // beats,msg,
Port string `json:"port"`
}