Index: jive/share/jive/slim/SlimServer.lua =================================================================== --- jive/share/jive/slim/SlimServer.lua (revision 1998) +++ jive/share/jive/slim/SlimServer.lua (working copy) @@ -248,6 +248,7 @@ -- are we connected to the server? active = false, + connecting = false, -- queue of artwork to fetch artworkFetchQueue = {}, @@ -354,6 +355,8 @@ function connect(self) log:info(self, ":connect()") + self.connecting = true + -- artwork pool connects on demand self.comet:connect() end @@ -362,6 +365,8 @@ function disconnect(self) log:info(self, ":disconnect()") + self.connecting = false + self.artworkPool:close() self.comet:disconnect() end @@ -405,7 +410,8 @@ =cut --]] function idFor(self, ip, port, name) - return tostring(ip) .. ":" .. tostring(port) + -- XXXX remove this function and just use SC name + return name end @@ -419,16 +425,35 @@ =cut --]] -function updateFromUdp(self, name) +function updateFromUdp(self, ip, port, name) log:debug(self, ":updateFromUdp()") -- update the name in all cases if self.name ~= name then - log:info(self, ": Renamed to ", name) self.name = name end + if self.plumbing.ip ~= ip or self.plumbing.port ~= port then + log:info(self, ": IP Address changed to ", ip , ":", port, " connecting=", self.connecting) + + local connecting = self.connecting + + -- close old comet connection + self:disconnect() + + -- open new comet connection + self.plumbing.ip = ip + self.plumbing.port = port + self.artworkPool = HttpPool(self.jnt, name, ip, port, 2, 1, Task.PRIORITY_LOW) + self.comet = Comet(self.jnt, ip, port, '/cometd', name) + + -- reconnect, if we were already connected + if connecting then + self:connect() + end + end + self.plumbing.lastSeen = Framework:getTicks() end Index: jive/share/jive/slim/SlimServers.lua =================================================================== --- jive/share/jive/slim/SlimServers.lua (revision 1998) +++ jive/share/jive/slim/SlimServers.lua (working copy) @@ -94,7 +94,7 @@ -- update the server with the name info, might have changed -- also keeps track of the last time we've seen the server for deletion - self._servers[ss_id]:updateFromUdp(ss_name) + self._servers[ss_id]:updateFromUdp(ss_ip, ss_port, ss_name) end @@ -462,6 +462,19 @@ end +-- restart discovery if the current slimserver disconnects +function notify_serverDisconnected(self, slimserver) + if not self.currentPlayer or self.currentPlayer:getSlimServer() ~= slimserver then + return + end + + -- start discovery, use a timer to make sure we don't loop + -- back into the Comet class while handling the event. + self.discoverState = 'discover' + self.discoverTimer:restart(1) +end + + -- restart discovery on new network function notify_networkConnected(self) log:info("network connected") Index: jive/share/jive/net/Comet.lua =================================================================== --- jive/share/jive/net/Comet.lua (revision 1998) +++ jive/share/jive/net/Comet.lua (working copy) @@ -174,6 +174,8 @@ function connect(self) log:debug(self, ": connect state=", self.state) + self.isactive = true + if self.state == CONNECTING or self.state == CONNECTED then -- Already connecting/connected return @@ -184,7 +186,6 @@ _state(self, UNCONNECTED) end - self.isactive = true _handshake(self) end @@ -192,6 +193,8 @@ function disconnect(self) log:debug(self, ": disconnect state=", self.state) + self.isactive = false + if self.state == UNCONNECTED or self.state == UNCONNECTING then -- Already disconnecting/unconnected return @@ -203,7 +206,6 @@ return end - self.isactive = false _disconnect(self) end @@ -442,7 +444,7 @@ -- Send immediately unless we're batching queries if self.state ~= CONNECTED or self.batch ~= 0 then if self.state ~= CONNECTED then - self.jnt:notify('cometDisconnected', self, #self.pending_reqs) + self.jnt:notify('cometDisconnected', self, #self.pending_reqs + #self.sent_reqs) end return id @@ -522,7 +524,7 @@ self.chttp:close() self.rhttp:close() - self.jnt:notify('cometDisconnected', self, #self.pending_reqs) + self.jnt:notify('cometDisconnected', self, #self.pending_reqs + #self.sent_reqs) end end @@ -609,6 +611,14 @@ log:debug(self, ": _handshake OK, clientId: ", self.clientId) + -- Rewrite clientId in requests to be reset + for i, req in ipairs(self.sent_reqs) do + if req.data.response then + req.data.response = string.gsub(req.data.response, "/(%x+)/", "/" .. self.clientId .. "/") + end + end + + -- Continue with connect phase, note we are still not CONNECTED _connect(self) else Index: jive/share/jive/net/Socket.lua =================================================================== --- jive/share/jive/net/Socket.lua (revision 1998) +++ jive/share/jive/net/Socket.lua (working copy) @@ -134,23 +134,21 @@ -- t_add/remove/read/write function t_addRead(self, pump, timeout) - if not self.readPump then - -- task to iterate over all read pumps - local task = Task(tostring(self) .. "(R)", - self, - function(self, networkErr) - while self.readPump do - if not self.readPump(networkErr) then - self, networkErr = Task:yield(false) - end + -- task to iterate over all read pumps + local task = Task(tostring(self) .. "(R)", + self, + function(self, networkErr) + while self.readPump do + if not self.readPump(networkErr) then + self, networkErr = Task:yield(false) end - end, - _taskError, - self.priority) - self.jnt:t_addRead(self.t_sock, task, timeout) - end + end + end, + _taskError, + self.priority) self.readPump = pump + self.jnt:t_addRead(self.t_sock, task, timeout) end function t_removeRead(self) @@ -161,23 +159,21 @@ end function t_addWrite(self, pump, timeout) - if not self.writePump then - -- task to iterate over all write pumps - local task = Task(tostring(self) .. "(W)", - self, - function(self, networkErr) - while self.writePump do - if not self.writePump(networkErr) then - self, networkErr = Task:yield(false) - end + -- task to iterate over all write pumps + local task = Task(tostring(self) .. "(W)", + self, + function(self, networkErr) + while self.writePump do + if not self.writePump(networkErr) then + self, networkErr = Task:yield(false) end - end, - _taskError, - self.priority) - self.jnt:t_addWrite(self.t_sock, task, timeout) - end - + end + end, + _taskError, + self.priority) + self.writePump = pump + self.jnt:t_addWrite(self.t_sock, task, timeout) end function t_removeWrite(self) Index: jive/share/jive/net/SocketHttp.lua =================================================================== --- jive/share/jive/net/SocketHttp.lua (revision 1998) +++ jive/share/jive/net/SocketHttp.lua (working copy) @@ -61,7 +61,9 @@ local BLOCKSIZE = 4096 -local SOCKET_TIMEOUT = 70 -- timeout for socket operations (seconds) +-- timeout for socket operations +local SOCKET_CONNECT_TIMEOUT = 10 -- connect in 10 seconds +local SOCKET_TIMEOUT = 70 -- response in 70 seconds --[[ @@ -346,7 +348,7 @@ self:t_nextSendState(true, 't_sendComplete') end - self:t_addWrite(pump, SOCKET_TIMEOUT) + self:t_addWrite(pump, SOCKET_CONNECT_TIMEOUT) end