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
139942f5
Commit
139942f5
authored
Mar 10, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix: delete readdeadline for websocket connections
parent
6133edd0
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
57 additions
and
91 deletions
+57
-91
echo.go
echo/tcp-echo/client/app/echo.go
+3
-3
main.go
echo/tcp-echo/client/app/main.go
+2
-2
readwriter.go
echo/tcp-echo/client/app/readwriter.go
+1
-1
version.go
echo/tcp-echo/client/app/version.go
+1
-1
echo.go
echo/tcp-echo/server/app/echo.go
+3
-3
readwriter.go
echo/tcp-echo/server/app/readwriter.go
+1
-1
server.go
echo/tcp-echo/server/app/server.go
+2
-2
version.go
echo/tcp-echo/server/app/version.go
+1
-1
change_log.md
echo/ws-echo/change_log.md
+4
-0
echo.go
echo/ws-echo/client/app/echo.go
+3
-3
main.go
echo/ws-echo/client/app/main.go
+2
-2
readwriter.go
echo/ws-echo/client/app/readwriter.go
+1
-1
version.go
echo/ws-echo/client/app/version.go
+1
-1
main.js
echo/ws-echo/js-client/main.js
+4
-4
echo.go
echo/ws-echo/server/app/echo.go
+3
-3
handler.go
echo/ws-echo/server/app/handler.go
+2
-0
readwriter.go
echo/ws-echo/server/app/readwriter.go
+1
-1
server.go
echo/ws-echo/server/app/server.go
+2
-2
version.go
echo/ws-echo/server/app/version.go
+1
-1
cert.sh
echo/ws-echo/server/profiles/test/cert/cert.sh
+0
-4
server.crt
echo/ws-echo/server/profiles/test/cert/server.crt
+0
-14
server.key
echo/ws-echo/server/profiles/test/cert/server.key
+0
-15
echo.go
echo/wss-echo/client/app/echo.go
+3
-3
main.go
echo/wss-echo/client/app/main.go
+3
-3
readwriter.go
echo/wss-echo/client/app/readwriter.go
+1
-1
version.go
echo/wss-echo/client/app/version.go
+1
-1
echo.go
echo/wss-echo/server/app/echo.go
+3
-3
readwriter.go
echo/wss-echo/server/app/readwriter.go
+1
-1
server.go
echo/wss-echo/server/app/server.go
+6
-13
version.go
echo/wss-echo/server/app/version.go
+1
-1
No files found.
echo/tcp-echo/client/app/echo.go
View file @
139942f5
...
...
@@ -54,7 +54,7 @@ const (
)
var
(
ErrNotEnoughSt
eam
=
errors
.
New
(
"packet stream is not enough"
)
ErrNotEnoughSt
ream
=
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
,
ErrNotEnoughSt
r
eam
}
// 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
,
ErrNotEnoughSt
r
eam
}
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
...
...
echo/tcp-echo/client/app/main.go
View file @
139942f5
...
...
@@ -93,8 +93,8 @@ func newSession(session getty.Session) error {
session
.
SetEventListener
(
newEchoMessageHandler
())
session
.
SetRQLen
(
conf
.
GettySessionParam
.
PkgRQSize
)
session
.
SetWQLen
(
conf
.
GettySessionParam
.
PkgWQSize
)
session
.
SetRead
Deadline
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Deadline
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetRead
Timeout
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Timeout
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetCronPeriod
((
int
)(
conf
.
heartbeatPeriod
.
Nanoseconds
()
/
1e6
))
session
.
SetWaitTime
(
conf
.
GettySessionParam
.
waitTimeout
)
log
.
Debug
(
"client new session:%s
\n
"
,
session
.
Stat
())
...
...
echo/tcp-echo/client/app/readwriter.go
View file @
139942f5
...
...
@@ -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
==
ErrNotEnoughSt
r
eam
{
return
nil
,
0
,
nil
}
...
...
echo/tcp-echo/client/app/version.go
View file @
139942f5
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
0
1"
Version
=
"0.8.1"
)
echo/tcp-echo/server/app/echo.go
View file @
139942f5
...
...
@@ -54,7 +54,7 @@ const (
)
var
(
ErrNotEnoughSt
eam
=
errors
.
New
(
"packet stream is not enough"
)
ErrNotEnoughSt
ream
=
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
,
ErrNotEnoughSt
r
eam
}
// 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
,
ErrNotEnoughSt
r
eam
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
...
...
echo/tcp-echo/server/app/readwriter.go
View file @
139942f5
...
...
@@ -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
==
ErrNotEnoughSt
r
eam
{
return
nil
,
0
,
nil
}
...
...
echo/tcp-echo/server/app/server.go
View file @
139942f5
...
...
@@ -98,8 +98,8 @@ func newSession(session getty.Session) error {
session
.
SetEventListener
(
newEchoMessageHandler
())
session
.
SetRQLen
(
conf
.
GettySessionParam
.
PkgRQSize
)
session
.
SetWQLen
(
conf
.
GettySessionParam
.
PkgWQSize
)
session
.
SetRead
Deadline
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Deadline
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetRead
Timeout
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Timeout
(
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
())
...
...
echo/tcp-echo/server/app/version.go
View file @
139942f5
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
0
1"
Version
=
"0.8.1"
)
echo/ws-echo/change_log.md
View file @
139942f5
...
...
@@ -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;
...
...
echo/ws-echo/client/app/echo.go
View file @
139942f5
...
...
@@ -49,7 +49,7 @@ const (
)
var
(
ErrNotEnoughSt
eam
=
errors
.
New
(
"packet stream is not enough"
)
ErrNotEnoughSt
ream
=
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
,
ErrNotEnoughSt
r
eam
}
// 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
,
ErrNotEnoughSt
r
eam
}
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
...
...
echo/ws-echo/client/app/main.go
View file @
139942f5
...
...
@@ -101,8 +101,8 @@ func newSession(session getty.Session) error {
session
.
SetEventListener
(
newEchoMessageHandler
())
session
.
SetRQLen
(
conf
.
GettySessionParam
.
PkgRQSize
)
session
.
SetWQLen
(
conf
.
GettySessionParam
.
PkgWQSize
)
session
.
SetRead
Deadline
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Deadline
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetRead
Timeout
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Timeout
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetCronPeriod
((
int
)(
conf
.
heartbeatPeriod
.
Nanoseconds
()
/
1e6
))
session
.
SetWaitTime
(
conf
.
GettySessionParam
.
waitTimeout
)
log
.
Debug
(
"client new session:%s
\n
"
,
session
.
Stat
())
...
...
echo/ws-echo/client/app/readwriter.go
View file @
139942f5
...
...
@@ -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
==
ErrNotEnoughSt
r
eam
{
return
nil
,
0
,
nil
}
...
...
echo/ws-echo/client/app/version.go
View file @
139942f5
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.8.
0
1"
Version
=
"0.8.1"
)
echo/ws-echo/js-client/main.js
View file @
139942f5
...
...
@@ -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
'
});
}
});
echo/ws-echo/server/app/echo.go
View file @
139942f5
...
...
@@ -49,7 +49,7 @@ const (
)
var
(
ErrNotEnoughSt
eam
=
errors
.
New
(
"packet stream is not enough"
)
ErrNotEnoughSt
ream
=
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
,
ErrNotEnoughSt
r
eam
}
// 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
,
ErrNotEnoughSt
r
eam
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
...
...
echo/ws-echo/server/app/handler.go
View file @
139942f5
...
...
@@ -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
)
...
...
echo/ws-echo/server/app/readwriter.go
View file @
139942f5
...
...
@@ -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
==
ErrNotEnoughSt
r
eam
{
return
nil
,
0
,
nil
}
...
...
echo/ws-echo/server/app/server.go
View file @
139942f5
...
...
@@ -106,8 +106,8 @@ func newSession(session getty.Session) error {
session
.
SetEventListener
(
newEchoMessageHandler
())
session
.
SetRQLen
(
conf
.
GettySessionParam
.
PkgRQSize
)
session
.
SetWQLen
(
conf
.
GettySessionParam
.
PkgWQSize
)
session
.
SetRead
Deadline
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Deadline
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetRead
Timeout
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Timeout
(
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
())
...
...
echo/ws-echo/server/app/version.go
View file @
139942f5
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
4.04
"
Version
=
"0.
8.1
"
)
echo/ws-echo/server/profiles/test/cert/cert.sh
deleted
100644 → 0
View file @
6133edd0
#!/usr/bin/env bash
openssl genrsa
-out
server.key 2048
openssl req
-new
-x509
-key
server.key
-out
server.crt
echo/ws-echo/server/profiles/test/cert/server.crt
deleted
100644 → 0
View file @
6133edd0
-----BEGIN CERTIFICATE-----
MIICHjCCAYegAwIBAgIQKpKqamBqmZ0hfp8sYb4uNDANBgkqhkiG9w0BAQsFADAS
MRAwDgYDVQQKEwdBY21lIENvMCAXDTcwMDEwMTAwMDAwMFoYDzIwODQwMTI5MTYw
MDAwWjASMRAwDgYDVQQKEwdBY21lIENvMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
iQKBgQC5Nxsk6WjeaYazRYiGxHZ5G3FXSlSjV7lZeebItdEPzO8kVPIGCSTy/M5X
Nnpp3uVDFXQub0/O5t9Y6wcuqpUGMOV+XL7MZqSZlodXm0XhNYzCAjZ+URNjTHGP
NXIqdDEG5Ba8SXMOfY6H97+QxugZoAMFZ+N83ggr12IYNO/FbQIDAQABo3MwcTAO
BgNVHQ8BAf8EBAMCAqQwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDwYDVR0TAQH/BAUw
AwEB/zA5BgNVHREEMjAwgglsb2NhbGhvc3SCC2V4YW1wbGUuY29thwR/AAABhxAA
AAAAAAAAAAAAAAAAAAABMA0GCSqGSIb3DQEBCwUAA4GBAE5dr9q7ORmKZ7yZqeSL
305armc13A7UxffUajeJFujpl2jOqnb5PuKJ7fn5HQKGB0qSq3IHsFua2WONXcTW
Vn4gS0k50IaDpW+yl+ArIo0QwbjPIAcFysX10p9dVO7A1uEpHbRDzefem6r9uVGk
i7dOLEoC8hkfk6nJsNEIEqu6
-----END CERTIFICATE-----
echo/ws-echo/server/profiles/test/cert/server.key
deleted
100644 → 0
View file @
6133edd0
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQC5Nxsk6WjeaYazRYiGxHZ5G3FXSlSjV7lZeebItdEPzO8kVPIG
CSTy/M5XNnpp3uVDFXQub0/O5t9Y6wcuqpUGMOV+XL7MZqSZlodXm0XhNYzCAjZ+
URNjTHGPNXIqdDEG5Ba8SXMOfY6H97+QxugZoAMFZ+N83ggr12IYNO/FbQIDAQAB
AoGBAJgvuXQY/fxSxUWkysvBvn9Al17cSrN0r23gBkvBaakMASvfSIbBGMU4COwM
bYV0ivkWNcK539/oQHk1lU85Bv0K9V9wtuFrYW0mN3TU6jnl6eEnzW5oy0Z9TwyY
wuGQOSXGr/aDVu8Wr7eOmSvn6j8rWO2dSMHCllJnSBoqQ1aZAkEA5YQspoMhUaq+
kC53GTgMhotnmK3fWfWKrlLf0spsaNl99W3+plwqxnJbye+5uEutRR1PWSWCCKq5
bN9veOXViwJBAM6WS5aeKO/JX09O0Ang9Y0+atMKO0YjX6fNFE2UJ5Ewzyr4DMZK
TmBpyzm4x/GhV9ukqcDcd3dNlUOtgRqY3+cCQQDCGmssk1+dUpqBE1rT8CvfqYv+
eqWWzerwDNSPz3OppK4630Bqby4Z0GNCP8RAUXgDKIuPqAH11HSm17vNcgqLAkA8
8FCzyUvCD+CxgEoV3+oPFA5m2mnJsr2QvgnzKHTTe1ZhEnKSO3ELN6nfCQbR3AoS
nGwGnAIRiy0wnYmr0tSZAkEAsWFm/D7sTQhX4Qnh15ZDdUn1WSWjBZevUtJnQcpx
TjihZq2sd3uK/XrzG+w7B+cPZlrZtQ94sDSVQwWl/sxB4A==
-----END RSA PRIVATE KEY-----
echo/wss-echo/client/app/echo.go
View file @
139942f5
...
...
@@ -49,7 +49,7 @@ const (
)
var
(
ErrNotEnoughSt
eam
=
errors
.
New
(
"packet stream is not enough"
)
ErrNotEnoughSt
ream
=
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
,
ErrNotEnoughSt
r
eam
}
// 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
,
ErrNotEnoughSt
r
eam
}
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
...
...
echo/wss-echo/client/app/main.go
View file @
139942f5
...
...
@@ -101,8 +101,8 @@ func newSession(session getty.Session) error {
session
.
SetEventListener
(
newEchoMessageHandler
())
session
.
SetRQLen
(
conf
.
GettySessionParam
.
PkgRQSize
)
session
.
SetWQLen
(
conf
.
GettySessionParam
.
PkgWQSize
)
session
.
SetRead
Deadline
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Deadline
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetRead
Timeout
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Timeout
(
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
.
New
WS
Client
(
(
int
)(
conf
.
ConnectionNum
),
conf
.
connectInterval
,
gxnet
.
WSHostAddress
(
conf
.
ServerHost
,
conf
.
ServerPort
,
conf
.
ServerPath
),
...
...
echo/wss-echo/client/app/readwriter.go
View file @
139942f5
...
...
@@ -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
==
ErrNotEnoughSt
r
eam
{
return
nil
,
0
,
nil
}
...
...
echo/wss-echo/client/app/version.go
View file @
139942f5
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
4.04
"
Version
=
"0.
8.1
"
)
echo/wss-echo/server/app/echo.go
View file @
139942f5
...
...
@@ -49,7 +49,7 @@ const (
)
var
(
ErrNotEnoughSt
eam
=
errors
.
New
(
"packet stream is not enough"
)
ErrNotEnoughSt
ream
=
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
,
ErrNotEnoughSt
r
eam
}
// 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
,
ErrNotEnoughSt
r
eam
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
...
...
echo/wss-echo/server/app/readwriter.go
View file @
139942f5
...
...
@@ -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
==
ErrNotEnoughSt
r
eam
{
return
nil
,
0
,
nil
}
...
...
echo/wss-echo/server/app/server.go
View file @
139942f5
...
...
@@ -106,8 +106,8 @@ func newSession(session getty.Session) error {
session
.
SetEventListener
(
newEchoMessageHandler
())
session
.
SetRQLen
(
conf
.
GettySessionParam
.
PkgRQSize
)
session
.
SetWQLen
(
conf
.
GettySessionParam
.
PkgWQSize
)
session
.
SetRead
Deadline
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Deadline
(
conf
.
GettySessionParam
.
tcpWriteTimeout
)
session
.
SetRead
Timeout
(
conf
.
GettySessionParam
.
tcpReadTimeout
)
session
.
SetWrite
Timeout
(
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
)
}
}
...
...
echo/wss-echo/server/app/version.go
View file @
139942f5
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
4.04
"
Version
=
"0.
8.1
"
)
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