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
d5967faf
Commit
d5967faf
authored
Oct 08, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix grammar bugs
parent
234e107d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
23 deletions
+23
-23
client.go
client.go
+1
-1
conn.go
conn.go
+5
-5
server.go
server.go
+8
-9
session.go
session.go
+9
-8
No files found.
client.go
View file @
d5967faf
...
...
@@ -93,7 +93,7 @@ func (this *Client) dialTCP() *Session {
func
(
this
*
Client
)
dialWS
()
*
Session
{
var
(
err
error
conn
websocket
.
Conn
conn
*
websocket
.
Conn
dialer
websocket
.
Dialer
)
...
...
conn.go
View file @
d5967faf
...
...
@@ -72,7 +72,7 @@ type gettyTCPConn struct {
}
// create gettyTCPConn
func
newGettyTCPConn
(
conn
net
.
Conn
)
*
gettyConn
{
func
newGettyTCPConn
(
conn
net
.
Conn
)
*
getty
TCP
Conn
{
if
conn
==
nil
{
panic
(
"newGettyTCPConn(conn):@conn is nil"
)
}
...
...
@@ -85,7 +85,7 @@ func newGettyTCPConn(conn net.Conn) *gettyConn {
peerAddr
=
conn
.
RemoteAddr
()
.
String
()
}
return
gettyTCPConn
{
return
&
gettyTCPConn
{
conn
:
conn
,
gettyConn
:
gettyConn
{
ID
:
atomic
.
AddUint32
(
&
connID
,
1
),
...
...
@@ -139,7 +139,7 @@ type gettyWSConn struct {
}
// create websocket connection
func
newGettyWSConn
(
conn
websocket
.
Conn
)
*
gettyWSConn
{
func
newGettyWSConn
(
conn
*
websocket
.
Conn
)
*
gettyWSConn
{
if
conn
==
nil
{
panic
(
"newGettyWSConn(conn):@conn is nil"
)
}
...
...
@@ -152,8 +152,8 @@ func newGettyWSConn(conn websocket.Conn) *gettyWSConn {
peerAddr
=
conn
.
RemoteAddr
()
.
String
()
}
return
gettyWSConn
{
conn
:
conn
,
return
&
gettyWSConn
{
conn
:
*
conn
,
gettyConn
:
gettyConn
{
ID
:
atomic
.
AddUint32
(
&
connID
,
1
),
local
:
localAddr
,
...
...
server.go
View file @
d5967faf
...
...
@@ -126,14 +126,14 @@ func (this *Server) RunEventloop(newSession NewSessionCallback) {
}()
}
type
WS
Handler
struct
{
type
ws
Handler
struct
{
server
*
Server
newSession
NewSessionCallback
upgrader
websocket
.
Upgrader
}
func
NewWSHandler
(
server
*
Server
)
*
WS
Handler
{
return
&
WS
Handler
{
func
newWSHandler
(
server
*
Server
)
ws
Handler
{
return
ws
Handler
{
server
:
server
,
upgrader
:
websocket
.
Upgrader
{
// HandshakeTimeout: server.HTTPTimeout,
...
...
@@ -142,7 +142,7 @@ func NewWSHandler(server *Server) *WSHandler {
}
}
func
(
this
*
WSHandler
)
ServeHTTP
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
this
wsHandler
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
Method
!=
"GET"
{
http
.
Error
(
w
,
"Method not allowed"
,
405
)
return
...
...
@@ -160,7 +160,6 @@ func (this *WSHandler) ServeHTTPServeHTTP(w http.ResponseWriter, r *http.Request
return
}
if
conn
.
RemoteAddr
()
.
String
()
==
conn
.
LocalAddr
()
.
String
()
{
return
nil
,
errSelfConnect
log
.
Warn
(
"conn.localAddr{%s} == conn.RemoteAddr"
,
conn
.
LocalAddr
()
.
String
(),
conn
.
RemoteAddr
()
.
String
())
return
}
...
...
@@ -170,7 +169,7 @@ func (this *WSHandler) ServeHTTPServeHTTP(w http.ResponseWriter, r *http.Request
if
err
!=
nil
{
conn
.
Close
()
log
.
Warn
(
"Server{%s}.newSession(session{%#v}) = err {%#v}"
,
this
.
server
.
addr
,
session
,
err
)
return
nil
return
}
session
.
RunEventLoop
()
}
...
...
@@ -179,12 +178,12 @@ func (this *Server) RunWSEventLoop(newSession NewSessionCallback) {
this
.
wg
.
Add
(
1
)
go
func
()
{
defer
this
.
wg
.
Done
()
http
.
Server
{
(
&
http
.
Server
{
Addr
:
this
.
addr
,
Handler
:
N
ewWSHandler
(
this
),
Handler
:
n
ewWSHandler
(
this
),
// ReadTimeout: server.HTTPTimeout,
// WriteTimeout: server.HTTPTimeout,
}
.
Serve
(
this
.
listener
)
}
)
.
Serve
(
this
.
listener
)
}()
}
...
...
session.go
View file @
d5967faf
...
...
@@ -102,7 +102,7 @@ func NewTCPSession(conn net.Conn) *Session {
}
}
func
NewWSSession
(
conn
websocket
.
Conn
)
*
Session
{
func
NewWSSession
(
conn
*
websocket
.
Conn
)
*
Session
{
return
&
Session
{
name
:
defaultSessionName
,
conn
:
newGettyWSConn
(
conn
),
...
...
@@ -330,12 +330,13 @@ func (this *Session) WriteBytesArray(pkgs ...[]byte) error {
// get len
var
(
l
int
len
uint32
arr
[]
byte
l
int
len
gth
uint32
arr
[]
byte
)
length
=
0
for
i
:=
0
;
i
<
len
(
pkgs
);
i
++
{
len
+=
uint32
(
len
(
pkgs
[
i
]))
len
gth
+=
uint32
(
len
(
pkgs
[
i
]))
}
// // check len
...
...
@@ -346,7 +347,7 @@ func (this *Session) WriteBytesArray(pkgs ...[]byte) error {
// }
// merge the pkgs
arr
=
make
([]
byte
,
len
)
arr
=
make
([]
byte
,
len
gth
)
l
=
0
for
i
:=
0
;
i
<
len
(
pkgs
);
i
++
{
copy
(
arr
[
l
:
],
pkgs
[
i
])
...
...
@@ -486,9 +487,9 @@ func (this *Session) handlePackage() {
}
}()
if
this
.
conn
.
(
gettyTCPConn
)
{
if
_
,
ok
:=
this
.
conn
.
(
*
gettyTCPConn
);
ok
{
err
=
this
.
handleTCPPackage
()
}
else
{
}
else
if
_
,
ok
:=
this
.
conn
.
(
*
gettyWSConn
);
ok
{
err
=
this
.
handleWSPackage
()
}
}
...
...
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