mirror of
https://github.com/zenith391/OCEmu.git
synced 2025-09-28 23:47:41 -04:00
remove useless locals, reduce processing with modem connection, support close all ports
This commit is contained in:
parent
ffb6911dc6
commit
beddf124fc
@ -82,20 +82,15 @@ end
|
||||
|
||||
function modem_host.datagramToPacketArray(datagram)
|
||||
compCheckArg(1,datagram,type(""))
|
||||
local packed = ser.unserialize(datagram)
|
||||
return packed
|
||||
return ser.unserialize(datagram)
|
||||
end
|
||||
|
||||
function modem_host.datagramToPacket(datagram)
|
||||
local packed = modem_host.datagramToPacketArray(datagram)
|
||||
local packet = modem_host.packedToPacket(packed)
|
||||
return packet
|
||||
return modem_host.packedToPacket(modem_host.datagramToPacketArray(datagram))
|
||||
end
|
||||
|
||||
function modem_host.packetToDatagram(packet)
|
||||
local packed = modem_host.packetToPacketArray(packet)
|
||||
local datagram = modem_host.packetArrayToDatagram(packed)
|
||||
return datagram
|
||||
return modem_host.packetArrayToDatagram(modem_host.packetToPacketArray(packet))
|
||||
end
|
||||
|
||||
function modem_host.readDatagram(client) -- client:receive()
|
||||
@ -200,6 +195,12 @@ function modem_host.processPendingMessages()
|
||||
assert(modem_host.id)
|
||||
end
|
||||
|
||||
-- do not try to process anything if this machine is not even connected to a message board
|
||||
-- not wrong without this, this is a simple optimization
|
||||
if not modem_host.connected then
|
||||
return
|
||||
end
|
||||
|
||||
modem_host.recvPendingMessages()
|
||||
|
||||
for _,packet in pairs(modem_host.messages) do
|
||||
@ -380,11 +381,19 @@ function obj.close(port) -- Closes the specified port (default: all ports). Retu
|
||||
port=checkPort(port)
|
||||
end
|
||||
|
||||
if not obj.isOpen(port) then
|
||||
return false;
|
||||
-- nil port case
|
||||
if not port then
|
||||
if not next(modem_host.open_ports) then
|
||||
return false, "no open ports"
|
||||
else
|
||||
modem_host.open_ports = {} -- close them all
|
||||
end
|
||||
elseif not obj.isOpen(port) then
|
||||
return false, "port not open"
|
||||
else
|
||||
modem_host.open_ports[port] = nil
|
||||
end
|
||||
|
||||
modem_host.open_ports[port] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user