Software /
code /
prosody
Comparison
net/server_epoll.lua @ 10278:94c584d67533
net.server_epoll: Make it easy to override handler for incoming data
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 29 Sep 2019 14:50:04 +0200 |
parent | 10234:d4390c427a66 |
child | 10279:0e1701197722 |
comparison
equal
deleted
inserted
replaced
10277:45a58127a3e5 | 10278:94c584d67533 |
---|---|
187 return nil, err; | 187 return nil, err; |
188 end | 188 end |
189 return err; | 189 return err; |
190 end | 190 end |
191 | 191 |
192 -- Allow this one to be overridden | |
193 function interface:onincoming(...) | |
194 return self:on("incoming", ...); | |
195 end | |
196 | |
192 -- Return the file descriptor number | 197 -- Return the file descriptor number |
193 function interface:getfd() | 198 function interface:getfd() |
194 if self.conn then | 199 if self.conn then |
195 return self.conn:getfd(); | 200 return self.conn:getfd(); |
196 end | 201 end |
358 -- Called when socket is readable | 363 -- Called when socket is readable |
359 function interface:onreadable() | 364 function interface:onreadable() |
360 local data, err, partial = self.conn:receive(self.read_size or cfg.read_size); | 365 local data, err, partial = self.conn:receive(self.read_size or cfg.read_size); |
361 if data then | 366 if data then |
362 self:onconnect(); | 367 self:onconnect(); |
363 self:on("incoming", data); | 368 self:onincoming(data); |
364 else | 369 else |
365 if err == "wantread" then | 370 if err == "wantread" then |
366 self:set(true, nil); | 371 self:set(true, nil); |
367 err = "timeout"; | 372 err = "timeout"; |
368 elseif err == "wantwrite" then | 373 elseif err == "wantwrite" then |
369 self:set(nil, true); | 374 self:set(nil, true); |
370 err = "timeout"; | 375 err = "timeout"; |
371 end | 376 end |
372 if partial and partial ~= "" then | 377 if partial and partial ~= "" then |
373 self:onconnect(); | 378 self:onconnect(); |
374 self:on("incoming", partial, err); | 379 self:onincoming(partial, err); |
375 end | 380 end |
376 if err ~= "timeout" then | 381 if err ~= "timeout" then |
377 self:on("disconnect", err); | 382 self:on("disconnect", err); |
378 self:destroy() | 383 self:destroy() |
379 return; | 384 return; |