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
09d0a578
Commit
09d0a578
authored
Mar 17, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accumulate all interfaces
parent
78dcd589
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
79 deletions
+172
-79
conn.go
conn.go
+0
-42
getty.go
getty.go
+172
-0
session.go
session.go
+0
-37
No files found.
conn.go
View file @
09d0a578
...
...
@@ -35,48 +35,6 @@ var (
)
/////////////////////////////////////////
// compress
/////////////////////////////////////////
type
CompressType
int
const
(
CompressNone
CompressType
=
flate
.
NoCompression
// 0
CompressZip
=
flate
.
DefaultCompression
// -1
CompressBestSpeed
=
flate
.
BestSpeed
// 1
CompressBestCompression
=
flate
.
BestCompression
// 9
CompressHuffman
=
flate
.
HuffmanOnly
// -2
CompressSnappy
=
10
)
/////////////////////////////////////////
// connection interfacke
/////////////////////////////////////////
type
Connection
interface
{
ID
()
uint32
SetCompressType
(
CompressType
)
LocalAddr
()
string
RemoteAddr
()
string
incReadPkgCount
()
incWritePkgCount
()
// update session's active time
UpdateActive
()
// get session's active time
GetActive
()
time
.
Time
readTimeout
()
time
.
Duration
// SetReadTimeout sets deadline for the future read calls.
SetReadTimeout
(
time
.
Duration
)
writeTimeout
()
time
.
Duration
// SetWriteTimeout sets deadline for the future read calls.
SetWriteTimeout
(
time
.
Duration
)
Write
(
interface
{})
(
int
,
error
)
// don't distinguish between tcp connection and websocket connection. Because
// gorilla/websocket/conn.go:(Conn)Close also invoke net.Conn.Close
close
(
int
)
}
/////////////////////////////////////////
// getty connection
/////////////////////////////////////////
...
...
codec
.go
→
getty
.go
View file @
09d0a578
/******************************************************
# DESC :
codec
interface
# DESC :
getty
interface
# MAINTAINER : Alex Stocks
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-08-17 11:20
# FILE :
codec
.go
# FILE :
getty
.go
******************************************************/
package
getty
import
(
"compress/flate"
"errors"
"net"
"time"
)
// NewSessionCallback will be invoked when server accepts a new client connection or client connects to server successfully.
...
...
@@ -61,10 +64,100 @@ type EventListener interface {
OnMessage
(
Session
,
interface
{})
}
/////////////////////////////////////////
// compress
/////////////////////////////////////////
type
CompressType
int
const
(
CompressNone
CompressType
=
flate
.
NoCompression
// 0
CompressZip
=
flate
.
DefaultCompression
// -1
CompressBestSpeed
=
flate
.
BestSpeed
// 1
CompressBestCompression
=
flate
.
BestCompression
// 9
CompressHuffman
=
flate
.
HuffmanOnly
// -2
CompressSnappy
=
10
)
/////////////////////////////////////////
// connection interfacke
/////////////////////////////////////////
type
Connection
interface
{
ID
()
uint32
SetCompressType
(
CompressType
)
LocalAddr
()
string
RemoteAddr
()
string
incReadPkgCount
()
incWritePkgCount
()
// update session's active time
UpdateActive
()
// get session's active time
GetActive
()
time
.
Time
readTimeout
()
time
.
Duration
// SetReadTimeout sets deadline for the future read calls.
SetReadTimeout
(
time
.
Duration
)
writeTimeout
()
time
.
Duration
// SetWriteTimeout sets deadline for the future read calls.
SetWriteTimeout
(
time
.
Duration
)
Write
(
interface
{})
(
int
,
error
)
// don't distinguish between tcp connection and websocket connection. Because
// gorilla/websocket/conn.go:(Conn)Close also invoke net.Conn.Close
close
(
int
)
}
/////////////////////////////////////////
// Session interfacke
/////////////////////////////////////////
var
(
ErrSessionClosed
=
errors
.
New
(
"session Already Closed"
)
ErrSessionBlocked
=
errors
.
New
(
"session Full Blocked"
)
ErrMsgTooLong
=
errors
.
New
(
"Message Too Long"
)
)
type
Session
interface
{
Connection
Reset
()
Conn
()
net
.
Conn
Stat
()
string
IsClosed
()
bool
SetMaxMsgLen
(
int
)
SetName
(
string
)
SetEventListener
(
EventListener
)
SetPkgHandler
(
ReadWriter
)
SetReader
(
Reader
)
SetWriter
(
Writer
)
SetCronPeriod
(
int
)
SetRQLen
(
int
)
SetWQLen
(
int
)
SetWaitTime
(
time
.
Duration
)
GetAttribute
(
interface
{})
interface
{}
SetAttribute
(
interface
{},
interface
{})
RemoveAttribute
(
interface
{})
// the Writer will invoke this function.
// for udp session, the first parameter should be UDPContext. Otherwise its type is []byte.
WritePkg
(
interface
{},
time
.
Duration
)
error
WriteBytes
([]
byte
)
error
WriteBytesArray
(
...
[]
byte
)
error
Close
()
}
/////////////////////////////////////////
// EndPoint interfacke
/////////////////////////////////////////
type
EndPoint
interface
{
// get endpoint type
Type
()
EndPointType
// run event loop
RunEventLoop
(
newSession
NewSessionCallback
)
// check the endpoint has been closed
IsClosed
()
bool
// close the endpoint and free its resource
Close
()
}
...
...
@@ -74,5 +167,6 @@ type Client interface {
type
Server
interface
{
EndPoint
// get the network listener
Listener
()
net
.
Listener
}
session.go
View file @
09d0a578
...
...
@@ -11,7 +11,6 @@ package getty
import
(
"bytes"
"errors"
"fmt"
"net"
"runtime"
...
...
@@ -47,45 +46,9 @@ const (
/////////////////////////////////////////
var
(
ErrSessionClosed
=
errors
.
New
(
"session Already Closed"
)
ErrSessionBlocked
=
errors
.
New
(
"session Full Blocked"
)
ErrMsgTooLong
=
errors
.
New
(
"Message Too Long"
)
)
var
(
wheel
=
gxtime
.
NewWheel
(
gxtime
.
TimeMillisecondDuration
(
100
),
1200
)
// wheel longest span is 2 minute
)
type
Session
interface
{
Connection
Reset
()
Conn
()
net
.
Conn
Stat
()
string
IsClosed
()
bool
SetMaxMsgLen
(
int
)
SetName
(
string
)
SetEventListener
(
EventListener
)
SetPkgHandler
(
ReadWriter
)
SetReader
(
Reader
)
SetWriter
(
Writer
)
SetCronPeriod
(
int
)
SetRQLen
(
int
)
SetWQLen
(
int
)
SetWaitTime
(
time
.
Duration
)
GetAttribute
(
interface
{})
interface
{}
SetAttribute
(
interface
{},
interface
{})
RemoveAttribute
(
interface
{})
// the Writer will invoke this function.
// for udp session, the first parameter should be UDPContext. Otherwise its type is []byte.
WritePkg
(
interface
{},
time
.
Duration
)
error
WriteBytes
([]
byte
)
error
WriteBytesArray
(
...
[]
byte
)
error
Close
()
}
// getty base session
type
session
struct
{
name
string
...
...
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