Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Netpoll
Commits
07573124
Unverified
Commit
07573124
authored
3 years ago
by
Joway
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
fix: check is active when flush (#118)
parent
6bb3b137
develop
feat/main_poll
fix/until
fix/write-close
main
online/fix_close_buffer
online/register_poller
perf/poller-num
test/lock_reading
test/op_using_now
v0.2.4
v0.2.3
v0.2.2
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
connection_impl.go
+2
-2
connection_impl.go
netpoll_test.go
+31
-0
netpoll_test.go
with
33 additions
and
2 deletions
+33
-2
connection_impl.go
+
2
-
2
View file @
07573124
...
...
@@ -205,7 +205,7 @@ func (c *connection) MallocLen() (length int) {
// If empty, it will call syscall.Write to send data directly,
// otherwise the buffer will be sent asynchronously by the epoll trigger.
func
(
c
*
connection
)
Flush
()
error
{
if
!
c
.
lock
(
flushing
)
{
if
!
c
.
IsActive
()
||
!
c
.
lock
(
flushing
)
{
return
Exception
(
ErrConnClosed
,
"when flush"
)
}
defer
c
.
unlock
(
flushing
)
...
...
@@ -267,7 +267,7 @@ func (c *connection) Read(p []byte) (n int, err error) {
// Write will Flush soon.
func
(
c
*
connection
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
if
!
c
.
lock
(
flushing
)
{
if
!
c
.
IsActive
()
||
!
c
.
lock
(
flushing
)
{
return
0
,
Exception
(
ErrConnClosed
,
"when write"
)
}
defer
c
.
unlock
(
flushing
)
...
...
This diff is collapsed.
Click to expand it.
netpoll_test.go
+
31
-
0
View file @
07573124
...
...
@@ -245,6 +245,37 @@ func TestCloseCallbackWhenOnConnect(t *testing.T) {
MustNil
(
t
,
err
)
}
func
TestCloseAndWrite
(
t
*
testing
.
T
)
{
var
network
,
address
=
"tcp"
,
":18888"
var
sendMsg
=
[]
byte
(
"hello"
)
var
loop
=
newTestEventLoop
(
network
,
address
,
func
(
ctx
context
.
Context
,
connection
Connection
)
error
{
_
,
err
:=
connection
.
Reader
()
.
Next
(
len
(
sendMsg
))
MustNil
(
t
,
err
)
err
=
connection
.
Close
()
MustNil
(
t
,
err
)
return
nil
},
)
var
conn
,
err
=
DialConnection
(
network
,
address
,
time
.
Second
)
MustNil
(
t
,
err
)
_
,
err
=
conn
.
Writer
()
.
WriteBinary
(
sendMsg
)
MustNil
(
t
,
err
)
err
=
conn
.
Writer
()
.
Flush
()
MustNil
(
t
,
err
)
time
.
Sleep
(
time
.
Millisecond
*
100
)
// wait for poller close connection
_
,
err
=
conn
.
Writer
()
.
WriteBinary
(
sendMsg
)
MustNil
(
t
,
err
)
err
=
conn
.
Writer
()
.
Flush
()
MustTrue
(
t
,
errors
.
Is
(
err
,
ErrConnClosed
))
err
=
loop
.
Shutdown
(
context
.
Background
())
MustNil
(
t
,
err
)
}
func
newTestEventLoop
(
network
,
address
string
,
onRequest
OnRequest
,
opts
...
Option
)
EventLoop
{
var
listener
,
_
=
CreateListener
(
network
,
address
)
var
eventLoop
,
_
=
NewEventLoop
(
onRequest
,
opts
...
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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
Menu
Projects
Groups
Snippets
Help