xjdrew / levent

lua concurrency library based on libev, similar with gevent
MIT License
190 stars 61 forks source link

bugfix: bad argument #1 to 'func' (socket_metatable expected, got table) #28

Closed learno closed 5 years ago

learno commented 5 years ago

在_recv或_send中,由于func是对应的c接口的引用,当触发close时,closed_socket会替换掉self.cobj,_wait挂起恢复后调用func会触发参数类型错误

xjdrew commented 5 years ago

本质上是func和self.cobj不一致引起的,所以把cobj本地化,关闭的时候再读就可以返回正确的错误码了吧?这样改满足你的需求不?

function Socket:_recv(func, ...)
   local  cobj = self.cobj
    while true do
        local data, err = func(cobj, ...)
        ...
learno commented 5 years ago

本质上是func和self.cobj不一致引起的,所以把cobj本地化,关闭的时候再读就可以返回正确的错误码了吧?这样改满足你的需求不?

function Socket:_recv(func, ...)
   local  cobj = self.cobj
    while true do
        local data, err = func(cobj, ...)
        ...

可以的

learno commented 5 years ago

更新了pr