-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.go
105 lines (94 loc) · 2.36 KB
/
process.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) 2023, donnie <donnie4w@gmail.com>
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// github.com/donnie4w/tldb
//
package level1
import (
"context"
"strings"
"sync"
"github.com/donnie4w/gothrift/thrift"
"github.com/donnie4w/tldb/sys"
. "github.com/donnie4w/tsf/server"
)
const tlContextCtx = "tlContext"
type tlContext struct {
Id int64
Conn Itnet
RemoteAddr string
RemoteUuid int64
RemoteHost string
RemoteAdminAddr string
RemoteMqAddr string
RemoteCliAddr string
NameSpace string
CcPut int64
CcGet int64
////////////////////////////////
pongFlag int64
transport thrift.TTransport
mux *sync.Mutex
defaultCtx context.Context
cancleChan chan byte
mergeChan chan *syncBean
mergeCount int64
mergemux *sync.Mutex
////////////////////////////////
isServer bool
isClose bool
pingNum int64
pongNum int64
isAuth bool
////////////////////////////////
stat sys.STATTYPE
_stat_seq int64
////////////////////////////////
_do_reconn bool
}
func (this *tlContext) SetId(_id int64) {
this.Id = _id
}
func (this *tlContext) Close() {
defer recover()
this.mux.Lock()
defer this.mux.Unlock()
if !this.isClose {
this.isClose = true
this.transport.Close()
close(this.cancleChan)
nodeWare.del(this)
}
}
func newTlContext(transport thrift.TTransport) (tc *tlContext) {
tc = &tlContext{Id: newTxId(), mux: new(sync.Mutex), mergeChan: make(chan *syncBean, 1<<17), mergemux: &sync.Mutex{}}
tc.transport = transport
tc.Conn = &ItnetWrite{&sync.Mutex{}, transport2Client(transport)}
return
}
func newTlContext2(socket *TSocket) (tc *tlContext) {
tc = &tlContext{Id: newTxId(), mux: new(sync.Mutex), mergeChan: make(chan *syncBean, 1<<17), mergemux: &sync.Mutex{}}
tc.transport = socket
tc.Conn = &ItnetImpl{socket}
return
}
func remoteHost(transport thrift.TTransport) (_r string) {
defer recover()
if addr := transport.(*thrift.TSocket).Conn().RemoteAddr(); addr != nil {
if ss := strings.Split(addr.String(), ":"); len(ss) == 2 {
_r = ss[0]
}
}
return
}
func remoteHost2(tsocket *TSocket) (_r string) {
defer recover()
if addr := tsocket.Conn().RemoteAddr(); addr != nil {
if ss := strings.Split(addr.String(), ":"); len(ss) == 2 {
_r = ss[0]
}
}
return
}