Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved compatibility with socket API to make copas work with socket.http non-blocking requests #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -222,11 +222,11 @@ end

-- same as above but with special treatment when reading chunks,
-- unblocks on any data received.
function copas.receivePartial(client, pattern)
local s, err, part
function copas.receivePartial(client, pattern, part)
local s, err
pattern = pattern or "*l"
repeat
s, err, part = client:receive(pattern)
s, err, part = client:receive(pattern, part)
if s or ( (type(pattern)=="number") and part~="" and part ~=nil ) or
err ~= "timeout" then
_reading_log[client] = nil
@@ -310,11 +310,11 @@ local _skt_mt = {__index = {
return copas.send (self.socket, data, from, to)
end,

receive = function (self, pattern)
receive = function (self, pattern, prefix)
if (self.timeout==0) then
return copas.receivePartial(self.socket, pattern)
return copas.receivePartial(self.socket, pattern, prefix)
end
return copas.receive(self.socket, pattern)
return copas.receive(self.socket, pattern, prefix)
end,

flush = function (self)
@@ -323,8 +323,12 @@ local _skt_mt = {__index = {

settimeout = function (self,time)
self.timeout=time
return
return true
end,

skip = function(self, ...) return self.socket:skip(...) end,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this skip line must go, otherwise it is good to merge. skip is a method of the socket module, eg. socket.skip, it is not a method of a socket object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good; I think you are right about this based on my review of the code.


close = function(self, ...) return self.socket:close(...) end,
}}

-- wraps a UDP socket, copy of TCP one adapted for UDP.
@@ -352,7 +356,7 @@ local _skt_mt_udp = {__index = {

settimeout = function (self,time)
self.timeout=time
return
return true
end,
}}