forked from yespon/yazi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4a0aab
commit 88f8ae4
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "PingTask.h" | ||
using namespace yazi::task; | ||
|
||
#include "Logger.h" | ||
#include "Singleton.h" | ||
using namespace yazi::utility; | ||
|
||
#include "SocketHandler.h" | ||
using namespace yazi::socket; | ||
#include <cstdio> | ||
#include <unistd.h> | ||
|
||
|
||
PingTask::PingTask(Socket * socket) : Task(socket) | ||
{ | ||
} | ||
|
||
PingTask::~PingTask() | ||
{ | ||
} | ||
|
||
void PingTask::run() | ||
{ | ||
debug("Ping task run"); | ||
SocketHandler * handler = Singleton<SocketHandler>::instance(); | ||
|
||
Socket * socket = static_cast<Socket *>(m_data); | ||
char buf[8192]; | ||
memset(buf, 0, 8192); | ||
int len = socket->recv(buf, 8192); | ||
if (len > 0) | ||
{ | ||
debug("recv msg len: %d", len); | ||
socket->send("+OK\r\n", 5); | ||
handler->attach(socket); | ||
} | ||
else | ||
{ | ||
debug("Ping task socket closed by peer"); | ||
handler->remove(socket); | ||
} | ||
} | ||
|
||
void PingTask::destroy() | ||
{ | ||
debug("Ping task destroy"); | ||
delete this; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "Task.h" | ||
using namespace yazi::thread; | ||
|
||
#include "Socket.h" | ||
using namespace yazi::socket; | ||
|
||
namespace yazi { | ||
namespace task { | ||
|
||
class PingTask : public Task | ||
{ | ||
public: | ||
PingTask(Socket * socket); | ||
virtual ~PingTask(); | ||
|
||
virtual void run(); | ||
|
||
virtual void destroy(); | ||
}; | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters