Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
3d09b747
Unverified
Commit
3d09b747
authored
Feb 25, 2024
by
Gregor Hartmann
Committed by
GitHub
Feb 25, 2024
Browse files
Fifo fixes (#3638)
parent
0b879ce1
Changes
2
Hide whitespace changes
Inline
Side-by-side
lua_modules/fifo/fifo.lua
View file @
3d09b747
-- A generic fifo module. See docs/lua-modules/fifo.md for use examples.
-- A generic fifo module. See docs/lua-modules/fifo.md for use examples.
local
t
r
,
ti
=
table.remove
,
table.insert
local
t
ableRemove
,
tableInsert
=
table.remove
,
table.insert
-- Remove an element and pass it to k, together with a boolean indicating that
-- Remove an element and pass it to k, together with a boolean indicating that
-- this is the last element in the queue; if that returns a value, leave that
-- this is the last element in the queue; if that returns a value, leave that
...
@@ -17,29 +17,33 @@ local tr, ti = table.remove, table.insert
...
@@ -17,29 +17,33 @@ local tr, ti = table.remove, table.insert
--
--
-- Returns 'true' if the queue contained at least one non-phantom entry,
-- Returns 'true' if the queue contained at least one non-phantom entry,
-- 'false' otherwise.
-- 'false' otherwise.
local
function
dequeue
(
q
,
k
)
local
function
dequeue
(
q
,
k
)
if
#
q
>
0
if
#
q
>
0
then
then
local
new
,
again
=
k
(
q
[
1
],
#
q
==
1
)
local
new
,
again
=
k
(
q
[
1
],
#
q
==
1
)
if
new
==
nil
then
if
new
==
nil
tableRemove
(
q
,
1
)
then
tr
(
q
,
1
)
else
if
again
then
return
dequeue
(
q
,
k
)
end
-- note tail call
q
[
1
]
=
new
else
q
[
1
]
=
new
end
end
if
again
then
return
true
return
dequeue
(
q
,
k
)
else
q
.
_go
=
true
;
return
false
end
-- note tail call
return
true
else
q
.
_go
=
true
return
false
end
end
end
end
-- Queue a on queue q and dequeue with `k` if the fifo had previously emptied.
-- Queue a on queue q and dequeue with `k` if the fifo had previously emptied.
local
function
queue
(
q
,
a
,
k
)
local
function
queue
(
q
,
a
,
k
)
t
i
(
q
,
a
)
t
ableInsert
(
q
,
a
)
if
k
~=
nil
and
q
.
_go
then
q
.
_go
=
false
;
dequeue
(
q
,
k
)
end
if
k
~=
nil
and
q
.
_go
then
q
.
_go
=
false
;
dequeue
(
q
,
k
)
end
end
end
-- return a table containing just the FIFO constructor
-- return a table containing just the FIFO constructor
return
{
return
{
[
'new'
]
=
function
()
[
'new'
]
=
function
()
return
{
[
'_go'
]
=
true
;
[
'queue'
]
=
queue
;
[
'dequeue'
]
=
dequeue
}
return
{
[
'_go'
]
=
true
;
[
'queue'
]
=
queue
;
[
'dequeue'
]
=
dequeue
}
end
end
}
}
lua_modules/fifo/fifosock.lua
View file @
3d09b747
...
@@ -58,7 +58,15 @@ local function wrap(sock)
...
@@ -58,7 +58,15 @@ local function wrap(sock)
-- Either that was a function or we've hit our coalescing limit or
-- Either that was a function or we've hit our coalescing limit or
-- we didn't ship above. Ship now, if there's something to ship.
-- we didn't ship above. Ship now, if there's something to ship.
if
s
~=
nil
then
if
s
~=
nil
then
if
sslan
==
0
then
sock
:
send
(
s
)
else
sock
:
send
(
ssla
..
s
)
end
if
sslan
==
0
then
if
#
s
>
0
then
sock
:
send
(
s
)
else
return
ns
or
nil
,
true
end
else
sock
:
send
(
ssla
..
s
)
end
ssla
,
sslan
=
nil
,
0
;
gc
()
ssla
,
sslan
=
nil
,
0
;
gc
()
return
ns
or
nil
,
false
return
ns
or
nil
,
false
elseif
sslan
~=
0
then
elseif
sslan
~=
0
then
...
...
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