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
Show 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
...
...
@@ -21,6 +21,7 @@
*
use ReadFromUDP as the uniform UDP read interface
*
close net.UDPConn when connected failed
*
close net.Conn when connected failed
*
Session::EndPointType() -> Session::EndPoint()
-
2018/03/17
> improvement
...
...
client.go
View file @
96c2170a
...
...
@@ -68,7 +68,7 @@ func newClient(t EndPointType, opts ...ClientOption) *client {
c
.
init
(
opts
...
)
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
)
...
...
@@ -131,7 +131,7 @@ func (c *client) dialTCP() Session {
err
=
errSelfConnect
}
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
)
...
...
@@ -158,6 +158,7 @@ func (c *client) dialUDP() Session {
}
conn
,
err
=
net
.
DialUDP
(
"udp"
,
localAddr
,
peerAddr
)
if
err
==
nil
&&
conn
.
LocalAddr
()
.
String
()
==
conn
.
RemoteAddr
()
.
String
()
{
conn
.
Close
()
err
=
errSelfConnect
}
if
err
!=
nil
{
...
...
@@ -187,7 +188,7 @@ func (c *client) dialUDP() Session {
continue
}
//if err == nil {
return
newUDPSession
(
conn
,
c
.
endPointType
)
return
newUDPSession
(
conn
,
c
)
//}
}
}
...
...
@@ -212,7 +213,7 @@ func (c *client) dialWS() Session {
err
=
errSelfConnect
}
if
err
==
nil
{
ss
=
newWSSession
(
conn
,
c
.
endPointType
)
ss
=
newWSSession
(
conn
,
c
)
if
ss
.
(
*
session
)
.
maxMsgLen
>
0
{
conn
.
SetReadLimit
(
int64
(
ss
.
(
*
session
)
.
maxMsgLen
))
}
...
...
@@ -289,7 +290,7 @@ func (c *client) dialWSS() Session {
err
=
errSelfConnect
}
if
err
==
nil
{
ss
=
newWSSession
(
conn
,
c
.
endPointType
)
ss
=
newWSSession
(
conn
,
c
)
if
ss
.
(
*
session
)
.
maxMsgLen
>
0
{
conn
.
SetReadLimit
(
int64
(
ss
.
(
*
session
)
.
maxMsgLen
))
}
...
...
conn.go
View file @
96c2170a
...
...
@@ -414,7 +414,7 @@ func (u *gettyUDPConn) Write(udpCtx interface{}) (int, error) {
if
buf
,
ok
=
ctx
.
Pkg
.
([]
byte
);
!
ok
{
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
if
peerAddr
==
nil
{
return
0
,
ErrNullPeerAddr
...
...
getty.go
View file @
96c2170a
...
...
@@ -126,7 +126,7 @@ type Session interface {
Stat
()
string
IsClosed
()
bool
// get endpoint type
EndPoint
Type
()
EndPointType
EndPoint
()
EndPoint
SetMaxMsgLen
(
int
)
SetName
(
string
)
...
...
server.go
View file @
96c2170a
...
...
@@ -212,7 +212,7 @@ func (s *server) accept(newSession NewSessionCallback) (Session, error) {
return
nil
,
errSelfConnect
}
ss
:=
newTCPSession
(
conn
,
s
.
endPointType
)
ss
:=
newTCPSession
(
conn
,
s
)
err
=
newSession
(
ss
)
if
err
!=
nil
{
conn
.
Close
()
...
...
@@ -267,7 +267,7 @@ func (s *server) runUDPEventLoop(newSession NewSessionCallback) {
ss
Session
)
ss
=
newUDPSession
(
s
.
pktListener
.
(
*
net
.
UDPConn
),
s
.
endPointType
)
ss
=
newUDPSession
(
s
.
pktListener
.
(
*
net
.
UDPConn
),
s
)
if
err
:=
newSession
(
ss
);
err
!=
nil
{
panic
(
err
.
Error
())
}
...
...
@@ -317,7 +317,7 @@ func (s *wsHandler) serveWSRequest(w http.ResponseWriter, r *http.Request) {
return
}
// conn.SetReadLimit(int64(handler.maxMsgLen))
ss
:=
newWSSession
(
conn
,
s
.
server
.
endPointType
)
ss
:=
newWSSession
(
conn
,
s
.
server
)
err
=
s
.
newSession
(
ss
)
if
err
!=
nil
{
conn
.
Close
()
...
...
session.go
View file @
96c2170a
...
...
@@ -51,7 +51,7 @@ var (
// getty base session
type
session
struct
{
name
string
endPoint
Type
EndPointType
endPoint
EndPoint
maxMsgLen
int32
// net read Write
Connection
...
...
@@ -75,10 +75,10 @@ type session struct {
lock
sync
.
RWMutex
}
func
newSession
(
endPoint
Type
EndPointType
,
conn
Connection
)
*
session
{
func
newSession
(
endPoint
EndPoint
,
conn
Connection
)
*
session
{
ss
:=
&
session
{
name
:
defaultSessionName
,
endPoint
Type
:
endPointType
,
endPoint
:
endPoint
,
maxMsgLen
:
maxReadBufLen
,
Connection
:
conn
,
done
:
make
(
chan
gxsync
.
Empty
),
...
...
@@ -94,25 +94,25 @@ func newSession(endPointType EndPointType, conn Connection) *session {
return
ss
}
func
newTCPSession
(
conn
net
.
Conn
,
endPoint
Type
EndPointType
)
Session
{
func
newTCPSession
(
conn
net
.
Conn
,
endPoint
EndPoint
)
Session
{
c
:=
newGettyTCPConn
(
conn
)
session
:=
newSession
(
endPoint
Type
,
c
)
session
:=
newSession
(
endPoint
,
c
)
session
.
name
=
defaultTCPSessionName
return
session
}
func
newUDPSession
(
conn
*
net
.
UDPConn
,
endPoint
Type
EndPointType
)
Session
{
func
newUDPSession
(
conn
*
net
.
UDPConn
,
endPoint
EndPoint
)
Session
{
c
:=
newGettyUDPConn
(
conn
)
session
:=
newSession
(
endPoint
Type
,
c
)
session
:=
newSession
(
endPoint
,
c
)
session
.
name
=
defaultUDPSessionName
return
session
}
func
newWSSession
(
conn
*
websocket
.
Conn
,
endPoint
Type
EndPointType
)
Session
{
func
newWSSession
(
conn
*
websocket
.
Conn
,
endPoint
EndPoint
)
Session
{
c
:=
newGettyWSConn
(
conn
)
session
:=
newSession
(
endPoint
Type
,
c
)
session
:=
newSession
(
endPoint
,
c
)
session
.
name
=
defaultWSSessionName
return
session
...
...
@@ -149,8 +149,8 @@ func (s *session) Conn() net.Conn {
return
nil
}
func
(
s
*
session
)
EndPoint
Type
()
EndPointType
{
return
s
.
endPoint
Type
func
(
s
*
session
)
EndPoint
()
EndPoint
{
return
s
.
endPoint
}
func
(
s
*
session
)
gettyConn
()
*
gettyConn
{
...
...
@@ -294,7 +294,7 @@ func (s *session) RemoveAttribute(key interface{}) {
}
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.
...
...
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