Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
96c2170a
Commit
96c2170a
authored
Mar 19, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Session::EndPointType() -> Session::EndPoint()
parent
3e82e215
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
33 deletions
+35
-33
change_log.md
change_log.md
+3
-2
client.go
client.go
+6
-5
conn.go
conn.go
+1
-1
getty.go
getty.go
+1
-1
server.go
server.go
+3
-3
session.go
session.go
+21
-21
No files found.
change_log.md
View file @
96c2170a
...
@@ -19,8 +19,9 @@
...
@@ -19,8 +19,9 @@
*
nerr -> netError
*
nerr -> netError
*
check udp connection alive after connect()
*
check udp connection alive after connect()
*
use ReadFromUDP as the uniform UDP read interface
*
use ReadFromUDP as the uniform UDP read interface
*
close net.UDPConn when connected failed
*
close net.UDPConn when connected failed
*
close net.Conn when connected failed
*
close net.Conn when connected failed
*
Session::EndPointType() -> Session::EndPoint()
-
2018/03/17
-
2018/03/17
> improvement
> improvement
...
...
client.go
View file @
96c2170a
...
@@ -68,7 +68,7 @@ func newClient(t EndPointType, opts ...ClientOption) *client {
...
@@ -68,7 +68,7 @@ func newClient(t EndPointType, opts ...ClientOption) *client {
c
.
init
(
opts
...
)
c
.
init
(
opts
...
)
if
c
.
number
<=
0
||
c
.
addr
==
""
{
if
c
.
number
<=
0
||
c
.
addr
==
""
{
panic
(
fmt
.
Sprintf
(
"
@connNum:%d, @serverAddr:%s"
,
c
.
number
,
c
.
addr
))
panic
(
fmt
.
Sprintf
(
"
client type:%s, @connNum:%d, @serverAddr:%s"
,
t
,
c
.
number
,
c
.
addr
))
}
}
c
.
ssMap
=
make
(
map
[
Session
]
gxsync
.
Empty
,
c
.
number
)
c
.
ssMap
=
make
(
map
[
Session
]
gxsync
.
Empty
,
c
.
number
)
...
@@ -131,7 +131,7 @@ func (c *client) dialTCP() Session {
...
@@ -131,7 +131,7 @@ func (c *client) dialTCP() Session {
err
=
errSelfConnect
err
=
errSelfConnect
}
}
if
err
==
nil
{
if
err
==
nil
{
return
newTCPSession
(
conn
,
c
.
endPointType
)
return
newTCPSession
(
conn
,
c
)
}
}
log
.
Info
(
"net.DialTimeout(addr:%s, timeout:%v) = error{%s}"
,
c
.
addr
,
err
)
log
.
Info
(
"net.DialTimeout(addr:%s, timeout:%v) = error{%s}"
,
c
.
addr
,
err
)
...
@@ -158,6 +158,7 @@ func (c *client) dialUDP() Session {
...
@@ -158,6 +158,7 @@ func (c *client) dialUDP() Session {
}
}
conn
,
err
=
net
.
DialUDP
(
"udp"
,
localAddr
,
peerAddr
)
conn
,
err
=
net
.
DialUDP
(
"udp"
,
localAddr
,
peerAddr
)
if
err
==
nil
&&
conn
.
LocalAddr
()
.
String
()
==
conn
.
RemoteAddr
()
.
String
()
{
if
err
==
nil
&&
conn
.
LocalAddr
()
.
String
()
==
conn
.
RemoteAddr
()
.
String
()
{
conn
.
Close
()
err
=
errSelfConnect
err
=
errSelfConnect
}
}
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -187,7 +188,7 @@ func (c *client) dialUDP() Session {
...
@@ -187,7 +188,7 @@ func (c *client) dialUDP() Session {
continue
continue
}
}
//if err == nil {
//if err == nil {
return
newUDPSession
(
conn
,
c
.
endPointType
)
return
newUDPSession
(
conn
,
c
)
//}
//}
}
}
}
}
...
@@ -212,7 +213,7 @@ func (c *client) dialWS() Session {
...
@@ -212,7 +213,7 @@ func (c *client) dialWS() Session {
err
=
errSelfConnect
err
=
errSelfConnect
}
}
if
err
==
nil
{
if
err
==
nil
{
ss
=
newWSSession
(
conn
,
c
.
endPointType
)
ss
=
newWSSession
(
conn
,
c
)
if
ss
.
(
*
session
)
.
maxMsgLen
>
0
{
if
ss
.
(
*
session
)
.
maxMsgLen
>
0
{
conn
.
SetReadLimit
(
int64
(
ss
.
(
*
session
)
.
maxMsgLen
))
conn
.
SetReadLimit
(
int64
(
ss
.
(
*
session
)
.
maxMsgLen
))
}
}
...
@@ -289,7 +290,7 @@ func (c *client) dialWSS() Session {
...
@@ -289,7 +290,7 @@ func (c *client) dialWSS() Session {
err
=
errSelfConnect
err
=
errSelfConnect
}
}
if
err
==
nil
{
if
err
==
nil
{
ss
=
newWSSession
(
conn
,
c
.
endPointType
)
ss
=
newWSSession
(
conn
,
c
)
if
ss
.
(
*
session
)
.
maxMsgLen
>
0
{
if
ss
.
(
*
session
)
.
maxMsgLen
>
0
{
conn
.
SetReadLimit
(
int64
(
ss
.
(
*
session
)
.
maxMsgLen
))
conn
.
SetReadLimit
(
int64
(
ss
.
(
*
session
)
.
maxMsgLen
))
}
}
...
...
conn.go
View file @
96c2170a
...
@@ -414,7 +414,7 @@ func (u *gettyUDPConn) Write(udpCtx interface{}) (int, error) {
...
@@ -414,7 +414,7 @@ func (u *gettyUDPConn) Write(udpCtx interface{}) (int, error) {
if
buf
,
ok
=
ctx
.
Pkg
.
([]
byte
);
!
ok
{
if
buf
,
ok
=
ctx
.
Pkg
.
([]
byte
);
!
ok
{
return
0
,
fmt
.
Errorf
(
"illegal @udpCtx.Pkg{%#v} type"
,
udpCtx
)
return
0
,
fmt
.
Errorf
(
"illegal @udpCtx.Pkg{%#v} type"
,
udpCtx
)
}
}
if
u
.
ss
.
EndPointType
()
==
UDP_ENDPOINT
{
if
u
.
ss
.
EndPoint
()
.
EndPoint
Type
()
==
UDP_ENDPOINT
{
peerAddr
=
ctx
.
PeerAddr
peerAddr
=
ctx
.
PeerAddr
if
peerAddr
==
nil
{
if
peerAddr
==
nil
{
return
0
,
ErrNullPeerAddr
return
0
,
ErrNullPeerAddr
...
...
getty.go
View file @
96c2170a
...
@@ -126,7 +126,7 @@ type Session interface {
...
@@ -126,7 +126,7 @@ type Session interface {
Stat
()
string
Stat
()
string
IsClosed
()
bool
IsClosed
()
bool
// get endpoint type
// get endpoint type
EndPoint
Type
()
EndPointType
EndPoint
()
EndPoint
SetMaxMsgLen
(
int
)
SetMaxMsgLen
(
int
)
SetName
(
string
)
SetName
(
string
)
...
...
server.go
View file @
96c2170a
...
@@ -212,7 +212,7 @@ func (s *server) accept(newSession NewSessionCallback) (Session, error) {
...
@@ -212,7 +212,7 @@ func (s *server) accept(newSession NewSessionCallback) (Session, error) {
return
nil
,
errSelfConnect
return
nil
,
errSelfConnect
}
}
ss
:=
newTCPSession
(
conn
,
s
.
endPointType
)
ss
:=
newTCPSession
(
conn
,
s
)
err
=
newSession
(
ss
)
err
=
newSession
(
ss
)
if
err
!=
nil
{
if
err
!=
nil
{
conn
.
Close
()
conn
.
Close
()
...
@@ -267,7 +267,7 @@ func (s *server) runUDPEventLoop(newSession NewSessionCallback) {
...
@@ -267,7 +267,7 @@ func (s *server) runUDPEventLoop(newSession NewSessionCallback) {
ss
Session
ss
Session
)
)
ss
=
newUDPSession
(
s
.
pktListener
.
(
*
net
.
UDPConn
),
s
.
endPointType
)
ss
=
newUDPSession
(
s
.
pktListener
.
(
*
net
.
UDPConn
),
s
)
if
err
:=
newSession
(
ss
);
err
!=
nil
{
if
err
:=
newSession
(
ss
);
err
!=
nil
{
panic
(
err
.
Error
())
panic
(
err
.
Error
())
}
}
...
@@ -317,7 +317,7 @@ func (s *wsHandler) serveWSRequest(w http.ResponseWriter, r *http.Request) {
...
@@ -317,7 +317,7 @@ func (s *wsHandler) serveWSRequest(w http.ResponseWriter, r *http.Request) {
return
return
}
}
// conn.SetReadLimit(int64(handler.maxMsgLen))
// conn.SetReadLimit(int64(handler.maxMsgLen))
ss
:=
newWSSession
(
conn
,
s
.
server
.
endPointType
)
ss
:=
newWSSession
(
conn
,
s
.
server
)
err
=
s
.
newSession
(
ss
)
err
=
s
.
newSession
(
ss
)
if
err
!=
nil
{
if
err
!=
nil
{
conn
.
Close
()
conn
.
Close
()
...
...
session.go
View file @
96c2170a
...
@@ -50,9 +50,9 @@ var (
...
@@ -50,9 +50,9 @@ var (
// getty base session
// getty base session
type
session
struct
{
type
session
struct
{
name
string
name
string
endPoint
Type
EndPointType
endPoint
EndPoint
maxMsgLen
int32
maxMsgLen
int32
// net read Write
// net read Write
Connection
Connection
// pkgHandler ReadWriter
// pkgHandler ReadWriter
...
@@ -75,16 +75,16 @@ type session struct {
...
@@ -75,16 +75,16 @@ type session struct {
lock
sync
.
RWMutex
lock
sync
.
RWMutex
}
}
func
newSession
(
endPoint
Type
EndPointType
,
conn
Connection
)
*
session
{
func
newSession
(
endPoint
EndPoint
,
conn
Connection
)
*
session
{
ss
:=
&
session
{
ss
:=
&
session
{
name
:
defaultSessionName
,
name
:
defaultSessionName
,
endPoint
Type
:
endPointType
,
endPoint
:
endPoint
,
maxMsgLen
:
maxReadBufLen
,
maxMsgLen
:
maxReadBufLen
,
Connection
:
conn
,
Connection
:
conn
,
done
:
make
(
chan
gxsync
.
Empty
),
done
:
make
(
chan
gxsync
.
Empty
),
period
:
period
,
period
:
period
,
wait
:
pendingDuration
,
wait
:
pendingDuration
,
attrs
:
gxcontext
.
NewValuesContext
(
nil
),
attrs
:
gxcontext
.
NewValuesContext
(
nil
),
}
}
ss
.
Connection
.
setSession
(
ss
)
ss
.
Connection
.
setSession
(
ss
)
...
@@ -94,25 +94,25 @@ func newSession(endPointType EndPointType, conn Connection) *session {
...
@@ -94,25 +94,25 @@ func newSession(endPointType EndPointType, conn Connection) *session {
return
ss
return
ss
}
}
func
newTCPSession
(
conn
net
.
Conn
,
endPoint
Type
EndPointType
)
Session
{
func
newTCPSession
(
conn
net
.
Conn
,
endPoint
EndPoint
)
Session
{
c
:=
newGettyTCPConn
(
conn
)
c
:=
newGettyTCPConn
(
conn
)
session
:=
newSession
(
endPoint
Type
,
c
)
session
:=
newSession
(
endPoint
,
c
)
session
.
name
=
defaultTCPSessionName
session
.
name
=
defaultTCPSessionName
return
session
return
session
}
}
func
newUDPSession
(
conn
*
net
.
UDPConn
,
endPoint
Type
EndPointType
)
Session
{
func
newUDPSession
(
conn
*
net
.
UDPConn
,
endPoint
EndPoint
)
Session
{
c
:=
newGettyUDPConn
(
conn
)
c
:=
newGettyUDPConn
(
conn
)
session
:=
newSession
(
endPoint
Type
,
c
)
session
:=
newSession
(
endPoint
,
c
)
session
.
name
=
defaultUDPSessionName
session
.
name
=
defaultUDPSessionName
return
session
return
session
}
}
func
newWSSession
(
conn
*
websocket
.
Conn
,
endPoint
Type
EndPointType
)
Session
{
func
newWSSession
(
conn
*
websocket
.
Conn
,
endPoint
EndPoint
)
Session
{
c
:=
newGettyWSConn
(
conn
)
c
:=
newGettyWSConn
(
conn
)
session
:=
newSession
(
endPoint
Type
,
c
)
session
:=
newSession
(
endPoint
,
c
)
session
.
name
=
defaultWSSessionName
session
.
name
=
defaultWSSessionName
return
session
return
session
...
@@ -149,8 +149,8 @@ func (s *session) Conn() net.Conn {
...
@@ -149,8 +149,8 @@ func (s *session) Conn() net.Conn {
return
nil
return
nil
}
}
func
(
s
*
session
)
EndPoint
Type
()
EndPointType
{
func
(
s
*
session
)
EndPoint
()
EndPoint
{
return
s
.
endPoint
Type
return
s
.
endPoint
}
}
func
(
s
*
session
)
gettyConn
()
*
gettyConn
{
func
(
s
*
session
)
gettyConn
()
*
gettyConn
{
...
@@ -294,7 +294,7 @@ func (s *session) RemoveAttribute(key interface{}) {
...
@@ -294,7 +294,7 @@ func (s *session) RemoveAttribute(key interface{}) {
}
}
func
(
s
*
session
)
sessionToken
()
string
{
func
(
s
*
session
)
sessionToken
()
string
{
return
fmt
.
Sprintf
(
"{%s:%
d:%s<->%s}"
,
s
.
name
,
s
.
ID
(),
s
.
LocalAddr
(),
s
.
RemoteAddr
())
return
fmt
.
Sprintf
(
"{%s:%
s:%d:%s<->%s}"
,
s
.
name
,
s
.
EndPoint
()
.
EndPointType
()
,
s
.
ID
(),
s
.
LocalAddr
(),
s
.
RemoteAddr
())
}
}
// Queued Write, for handler.
// Queued Write, for handler.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment