Commit 139942f5 authored by AlexStocks's avatar AlexStocks

bugfix: delete readdeadline for websocket connections

parent 6133edd0
......@@ -54,7 +54,7 @@ const (
)
var (
ErrNotEnoughSteam = errors.New("packet stream is not enough")
ErrNotEnoughStream = errors.New("packet stream is not enough")
ErrTooLargePackage = errors.New("package length is exceed the echo package's legal maximum length.")
ErrIllegalMagic = errors.New("package magic is not right.")
)
......@@ -116,7 +116,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
)
if buf.Len() < echoPkgHeaderLen {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// header
......@@ -129,7 +129,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return 0, ErrIllegalMagic
}
if buf.Len() < (int)(this.H.Len) {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
if maxEchoStringLen < this.H.Len-1 {
return 0, ErrTooLargePackage
......
......@@ -93,8 +93,8 @@ func newSession(session getty.Session) error {
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetReadTimeout(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("client new session:%s\n", session.Stat())
......
......@@ -38,7 +38,7 @@ func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}
buf = bytes.NewBuffer(data)
len, err = pkg.Unmarshal(buf)
if err != nil {
if err == ErrNotEnoughSteam {
if err == ErrNotEnoughStream {
return nil, 0, nil
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.01"
Version = "0.8.1"
)
......@@ -54,7 +54,7 @@ const (
)
var (
ErrNotEnoughSteam = errors.New("packet stream is not enough")
ErrNotEnoughStream = errors.New("packet stream is not enough")
ErrTooLargePackage = errors.New("package length is exceed the echo package's legal maximum length.")
ErrIllegalMagic = errors.New("package magic is not right.")
)
......@@ -116,7 +116,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
)
if buf.Len() < echoPkgHeaderLen {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// header
......@@ -129,7 +129,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return 0, ErrIllegalMagic
}
if buf.Len() < (int)(this.H.Len) {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if maxEchoStringLen < this.H.Len-1 {
......
......@@ -38,7 +38,7 @@ func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}
buf = bytes.NewBuffer(data)
len, err = pkg.Unmarshal(buf)
if err != nil {
if err == ErrNotEnoughSteam {
if err == ErrNotEnoughStream {
return nil, 0, nil
}
......
......@@ -98,8 +98,8 @@ func newSession(session getty.Session) error {
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetReadTimeout(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.sessionTimeout.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("app accepts new session:%s\n", session.Stat())
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.01"
Version = "0.8.1"
)
......@@ -10,6 +10,10 @@
## develop history ##
---
- 2018/03/09
> improvement
* use getty 0.8.1
- 2017/04/27
> improvement
* enable wss client just using cert file;
......
......@@ -49,7 +49,7 @@ const (
)
var (
ErrNotEnoughSteam = errors.New("packet stream is not enough")
ErrNotEnoughStream = errors.New("packet stream is not enough")
ErrTooLargePackage = errors.New("package length is exceed the echo package's legal maximum length.")
ErrIllegalMagic = errors.New("package magic is not right.")
)
......@@ -111,7 +111,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
)
if buf.Len() < echoPkgHeaderLen {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// header
......@@ -124,7 +124,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return 0, ErrIllegalMagic
}
if buf.Len() < (int)(this.H.Len) {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
if maxEchoStringLen < this.H.Len-1 {
return 0, ErrTooLargePackage
......
......@@ -101,8 +101,8 @@ func newSession(session getty.Session) error {
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetReadTimeout(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("client new session:%s\n", session.Stat())
......
......@@ -38,7 +38,7 @@ func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}
buf = bytes.NewBuffer(data)
len, err = pkg.Unmarshal(buf)
if err != nil {
if err == ErrNotEnoughSteam {
if err == ErrNotEnoughStream {
return nil, 0, nil
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.8.01"
Version = "0.8.1"
)
......@@ -49,7 +49,7 @@ $(function() {
if (socket.readyState != socket.OPEN) {
if (!silence) {
addChatMessage({
Message: '!!Connection closed'
Message: '!!Connection closed\n'
});
}
return
......@@ -125,7 +125,7 @@ $(function() {
socket.close();
socket = null;
addChatMessage({
Message: '!!SYSTEM-WS-Close, connection disconnect'
Message: '!!SYSTEM-WS-Close, connection disconnect\n'
})
}
}
......@@ -226,13 +226,13 @@ $(function() {
// console.log("socket.onclose" + e.reason)
disconnect();
addChatMessage({
Message: e.reason + '!!SYSTEM-WS-Close, connection closed'
Message: e.reason + '!!SYSTEM-WS-Close, connection closed\n'
});
};
socket.onerror = function() {
addChatMessage({
Message: '!!SYSTEM-WS-Error, connection closed'
Message: '!!SYSTEM-WS-Error, connection closed\n'
});
}
});
......@@ -49,7 +49,7 @@ const (
)
var (
ErrNotEnoughSteam = errors.New("packet stream is not enough")
ErrNotEnoughStream = errors.New("packet stream is not enough")
ErrTooLargePackage = errors.New("package length is exceed the echo package's legal maximum length.")
ErrIllegalMagic = errors.New("package magic is not right.")
)
......@@ -111,7 +111,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
)
if buf.Len() < echoPkgHeaderLen {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// header
......@@ -124,7 +124,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return 0, ErrIllegalMagic
}
if buf.Len() < (int)(this.H.Len) {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if maxEchoStringLen < this.H.Len-1 {
......
......@@ -126,6 +126,7 @@ func (this *EchoMessageHandler) OnCron(session getty.Session) {
flag bool
active time.Time
)
this.rwlock.RLock()
if _, ok := this.sessionMap[session]; ok {
active = session.GetActive()
......@@ -136,6 +137,7 @@ func (this *EchoMessageHandler) OnCron(session getty.Session) {
}
}
this.rwlock.RUnlock()
if flag {
this.rwlock.Lock()
delete(this.sessionMap, session)
......
......@@ -41,7 +41,7 @@ func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}
len, err = pkg.Unmarshal(buf)
log.Debug("pkg.Read:%#v", pkg)
if err != nil {
if err == ErrNotEnoughSteam {
if err == ErrNotEnoughStream {
return nil, 0, nil
}
......
......@@ -106,8 +106,8 @@ func newSession(session getty.Session) error {
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetReadTimeout(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("app accepts new session:%s\n", session.Stat())
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.4.04"
Version = "0.8.1"
)
#!/usr/bin/env bash
openssl genrsa -out server.key 2048
openssl req -new -x509 -key server.key -out server.crt
-----BEGIN CERTIFICATE-----
MIICHjCCAYegAwIBAgIQKpKqamBqmZ0hfp8sYb4uNDANBgkqhkiG9w0BAQsFADAS
MRAwDgYDVQQKEwdBY21lIENvMCAXDTcwMDEwMTAwMDAwMFoYDzIwODQwMTI5MTYw
MDAwWjASMRAwDgYDVQQKEwdBY21lIENvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
iQKBgQC5Nxsk6WjeaYazRYiGxHZ5G3FXSlSjV7lZeebItdEPzO8kVPIGCSTy/M5X
Nnpp3uVDFXQub0/O5t9Y6wcuqpUGMOV+XL7MZqSZlodXm0XhNYzCAjZ+URNjTHGP
NXIqdDEG5Ba8SXMOfY6H97+QxugZoAMFZ+N83ggr12IYNO/FbQIDAQABo3MwcTAO
BgNVHQ8BAf8EBAMCAqQwEwYDVR0lBAwwCgYIKwYBBQ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iy0wnYmr0tSZAkEAsWFm/D7sTQhX4Qnh15ZDdUn1WSWjBZevUtJnQcpx
TjihZq2sd3uK/XrzG+w7B+cPZlrZtQ94sDSVQwWl/sxB4A==
-----END RSA PRIVATE KEY-----
......@@ -49,7 +49,7 @@ const (
)
var (
ErrNotEnoughSteam = errors.New("packet stream is not enough")
ErrNotEnoughStream = errors.New("packet stream is not enough")
ErrTooLargePackage = errors.New("package length is exceed the echo package's legal maximum length.")
ErrIllegalMagic = errors.New("package magic is not right.")
)
......@@ -111,7 +111,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
)
if buf.Len() < echoPkgHeaderLen {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// header
......@@ -124,7 +124,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return 0, ErrIllegalMagic
}
if buf.Len() < (int)(this.H.Len) {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
if maxEchoStringLen < this.H.Len-1 {
return 0, ErrTooLargePackage
......
......@@ -101,8 +101,8 @@ func newSession(session getty.Session) error {
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetReadTimeout(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("client new session:%s\n", session.Stat())
......@@ -119,7 +119,7 @@ func initClient() {
conf.CertFile,
)
} else {
client.gettyClient = getty.NewClient(
client.gettyClient = getty.NewWSClient(
(int)(conf.ConnectionNum),
conf.connectInterval,
gxnet.WSHostAddress(conf.ServerHost, conf.ServerPort, conf.ServerPath),
......
......@@ -38,7 +38,7 @@ func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}
buf = bytes.NewBuffer(data)
len, err = pkg.Unmarshal(buf)
if err != nil {
if err == ErrNotEnoughSteam {
if err == ErrNotEnoughStream {
return nil, 0, nil
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.4.04"
Version = "0.8.1"
)
......@@ -49,7 +49,7 @@ const (
)
var (
ErrNotEnoughSteam = errors.New("packet stream is not enough")
ErrNotEnoughStream = errors.New("packet stream is not enough")
ErrTooLargePackage = errors.New("package length is exceed the echo package's legal maximum length.")
ErrIllegalMagic = errors.New("package magic is not right.")
)
......@@ -111,7 +111,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
)
if buf.Len() < echoPkgHeaderLen {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// header
......@@ -124,7 +124,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return 0, ErrIllegalMagic
}
if buf.Len() < (int)(this.H.Len) {
return 0, ErrNotEnoughSteam
return 0, ErrNotEnoughStream
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if maxEchoStringLen < this.H.Len-1 {
......
......@@ -41,7 +41,7 @@ func (this *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}
len, err = pkg.Unmarshal(buf)
log.Debug("pkg.Read:%#v", pkg)
if err != nil {
if err == ErrNotEnoughSteam {
if err == ErrNotEnoughStream {
return nil, 0, nil
}
......
......@@ -106,8 +106,8 @@ func newSession(session getty.Session) error {
session.SetEventListener(newEchoMessageHandler())
session.SetRQLen(conf.GettySessionParam.PkgRQSize)
session.SetWQLen(conf.GettySessionParam.PkgWQSize)
session.SetReadDeadline(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteDeadline(conf.GettySessionParam.tcpWriteTimeout)
session.SetReadTimeout(conf.GettySessionParam.tcpReadTimeout)
session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout)
session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6))
session.SetWaitTime(conf.GettySessionParam.waitTimeout)
log.Debug("app accepts new session:%s\n", session.Stat())
......@@ -117,7 +117,6 @@ func newSession(session getty.Session) error {
func initServer() {
var (
err error
addr string
portList []string
pathList []string
......@@ -145,23 +144,17 @@ func initServer() {
panic("the @Ports's length is not equal to @Paths.")
}
for idx, port := range portList {
server = getty.NewServer()
// addr = *host + ":" + port
// addr = conf.Host + ":" + port
addr = gxnet.HostAddress2(conf.Host, port)
err = server.Listen("tcp", addr)
if err != nil {
panic(fmt.Sprintf("server.Listen(tcp, addr:%s) = error{%#v}", addr, err))
}
// run server
if conf.CertFile != "" && conf.KeyFile != "" {
server.RunWSSEventLoop(newSession, pathList[idx], conf.CertFile, conf.KeyFile, conf.CACert)
server = getty.NewWSSServer(addr, pathList[idx], conf.CertFile, conf.KeyFile, conf.CACert)
log.Debug("server bind addr{wss://%s/%s} ok!", addr, pathList[idx])
} else {
server.RunWSEventLoop(newSession, pathList[idx])
server = getty.NewWSServer(addr, pathList[idx])
log.Debug("server bind addr{ws://%s/%s} ok!", addr, pathList[idx])
}
server.RunEventloop(newSession)
// run server
serverList = append(serverList, server)
}
}
......
......@@ -10,5 +10,5 @@
package main
var (
Version = "0.4.04"
Version = "0.8.1"
)
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