Commit d5967faf authored by alexstocks's avatar alexstocks

fix grammar bugs

parent 234e107d
......@@ -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
)
......
......@@ -72,7 +72,7 @@ type gettyTCPConn struct {
}
// create gettyTCPConn
func newGettyTCPConn(conn net.Conn) *gettyConn {
func newGettyTCPConn(conn net.Conn) *gettyTCPConn {
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,
......
......@@ -126,14 +126,14 @@ func (this *Server) RunEventloop(newSession NewSessionCallback) {
}()
}
type WSHandler struct {
type wsHandler struct {
server *Server
newSession NewSessionCallback
upgrader websocket.Upgrader
}
func NewWSHandler(server *Server) *WSHandler {
return &WSHandler{
func newWSHandler(server *Server) wsHandler {
return wsHandler{
server: server,
upgrader: websocket.Upgrader{
// HandshakeTimeout: server.HTTPTimeout,
......@@ -142,7 +142,7 @@ func NewWSHandler(server *Server) *WSHandler {
}
}
func (this *WSHandler) ServeHTTPServeHTTP(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: NewWSHandler(this),
Handler: newWSHandler(this),
// ReadTimeout: server.HTTPTimeout,
// WriteTimeout: server.HTTPTimeout,
}.Serve(this.listener)
}).Serve(this.listener)
}()
}
......
......@@ -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
length uint32
arr []byte
)
length = 0
for i := 0; i < len(pkgs); i++ {
len += uint32(len(pkgs[i]))
length += 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, length)
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()
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment