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
10a4efd0
Commit
10a4efd0
authored
Sep 04, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add (server)Listen
parent
d63a5e25
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
10 deletions
+18
-10
README.md
README.md
+7
-3
server.go
server.go
+10
-7
utils.go
utils.go
+1
-0
No files found.
README.md
View file @
10a4efd0
...
...
@@ -9,6 +9,10 @@
## develop history ##
---
-
2016/09/04
> 1 add server.go:(Server)Listen
>
> 2 version: 0.3.02
-
2016/09/03
> 1 modify return value of session.go:(Session)Close from void to error
...
...
@@ -17,9 +21,9 @@
>
> 3 session.go:Session{*gettyConn, readDeadline, writeDeadline} -> session.go:Session{gettyConn, rDeadline, wDeadline}
>
> 4 session.go:(Session)Reset
> 4
add
session.go:(Session)Reset
>
> 5 session.go:(Session)SetConn
> 5
add
session.go:(Session)SetConn
>
> 6 add elastic sleep time machanism in client.go:(Client)RunEventLoop
>
...
...
server.go
View file @
10a4efd0
...
...
@@ -22,8 +22,7 @@ import (
type
Server
struct
{
// net
host
string
port
int
addr
string
listener
net
.
Listener
sync
.
Once
...
...
@@ -58,17 +57,21 @@ func (this *Server) IsClosed() bool {
}
}
// (Server)Bind's functionality is equal to (Server)Listen.
func
(
this
*
Server
)
Bind
(
network
string
,
host
string
,
port
int
)
error
{
if
port
<=
0
{
return
errors
.
New
(
"port<=0 illegal"
)
}
this
.
host
=
host
this
.
port
=
port
listener
,
err
:=
net
.
Listen
(
network
,
HostAddress
(
host
,
port
))
return
this
.
Listen
(
network
,
HostAddress
(
host
,
port
))
}
func
(
this
*
Server
)
Listen
(
network
string
,
addr
string
)
error
{
listener
,
err
:=
net
.
Listen
(
network
,
addr
)
if
err
!=
nil
{
return
err
}
this
.
addr
=
addr
this
.
listener
=
listener
return
nil
...
...
@@ -85,7 +88,7 @@ func (this *Server) RunEventloop(newSession SessionCallback) {
)
for
{
if
this
.
IsClosed
()
{
log
.
Warn
(
"Server{%s
:%d} stop acceptting client connect request."
,
this
.
host
,
this
.
port
)
log
.
Warn
(
"Server{%s
} stop acceptting client connect request."
,
this
.
addr
)
return
}
if
delay
!=
0
{
...
...
@@ -104,7 +107,7 @@ func (this *Server) RunEventloop(newSession SessionCallback) {
}
continue
}
log
.
Info
(
"Server{%s
:%d}.Accept() = err {%+v}"
,
this
.
host
,
this
.
port
,
err
)
log
.
Info
(
"Server{%s
}.Accept() = err {%#v}"
,
this
.
addr
,
err
)
continue
}
delay
=
0
...
...
utils.go
View file @
10a4efd0
...
...
@@ -16,6 +16,7 @@ import (
"strconv"
)
// HostAddress composes a ip:port style address. Its opposite function is net.SplitHostPort.
func
HostAddress
(
host
string
,
port
int
)
string
{
return
net
.
JoinHostPort
(
host
,
strconv
.
Itoa
(
port
))
}
...
...
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