2019-07-28 10:31:56 +08:00
|
|
|
|
#include <iostream>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include "lib_acl.h"
|
|
|
|
|
#include "acl_cpp/lib_acl.hpp"
|
|
|
|
|
|
|
|
|
|
static int __timeout = 0;
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
STATUS_T_HDR,
|
|
|
|
|
STATUS_T_DAT,
|
|
|
|
|
} status_t;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͷ
|
2015-05-18 20:05:22 +08:00
|
|
|
|
struct DAT_HDR
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
int len; // <20><><EFBFBD><EFBFBD><EFBFBD>峤<EFBFBD><E5B3A4>
|
|
|
|
|
char cmd[64]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>첽<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
|
|
|
|
class io_callback : public acl::aio_callback
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
io_callback(acl::aio_socket_stream* client)
|
2019-06-16 20:10:40 +08:00
|
|
|
|
: status_(STATUS_T_HDR)
|
|
|
|
|
, client_(client)
|
|
|
|
|
, i_(0)
|
2015-05-18 20:05:22 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 20:10:40 +08:00
|
|
|
|
~io_callback(void)
|
2015-05-18 20:05:22 +08:00
|
|
|
|
{
|
|
|
|
|
std::cout << "delete io_callback now ..." << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param data {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
|
|
|
|
|
* @param len {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
|
|
|
|
bool read_callback(char* data, int len)
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><>ǰ״̬<D7B4>Ǵ<EFBFBD><C7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷʱ
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (status_ == STATUS_T_HDR) {
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (len != sizeof(DAT_HDR)) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
printf("invalid len(%d) != DAT_HDR(%d)\r\n",
|
|
|
|
|
len, (int) sizeof(DAT_HDR));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>峤<EFBFBD>ȣ<EFBFBD><C8A3><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
|
|
|
|
|
DAT_HDR* req_hdr = (DAT_HDR*) data;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>תΪ<D7AA><CEAA><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
req_hdr->len = ntohl(req_hdr->len);
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (req_hdr->len <= 0) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
printf("invalid len: %d\r\n", req_hdr->len);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><EFBFBD>״̬λ<CCAC><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
status_ = STATUS_T_DAT;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20>첽<EFBFBD><ECB2BD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client_->read(req_hdr->len, __timeout);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (status_ != STATUS_T_DAT) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
printf("invalid status: %d\r\n", (int) status_);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (i_++ < 10) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
printf("req len: %d, dat: %s\r\n", len, data);
|
2019-06-16 20:10:40 +08:00
|
|
|
|
}
|
2015-05-18 20:05:22 +08:00
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><>Զ<EFBFBD>̿ͻ<CCBF><CDBB>˻<EFBFBD>д<EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
|
|
|
|
|
#define OK "+OK"
|
|
|
|
|
size_t dat_len = sizeof(OK) - 1;
|
|
|
|
|
|
|
|
|
|
DAT_HDR res_hdr;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>תΪ<D7AA><CEAA><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
2015-12-12 23:00:03 +08:00
|
|
|
|
res_hdr.len = (int) htonl((unsigned long) dat_len);
|
2015-05-18 20:05:22 +08:00
|
|
|
|
ACL_SAFE_STRNCPY(res_hdr.cmd, "ok", sizeof(res_hdr.cmd));
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20>첽д<ECB2BD><D0B4>Ӧ<EFBFBD><D3A6><EFBFBD>ݰ<EFBFBD>: <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
|
|
|
|
|
client_->write(&res_hdr, sizeof(res_hdr));
|
2015-06-29 17:33:11 +08:00
|
|
|
|
client_->write(OK, (int) dat_len);
|
2015-05-18 20:05:22 +08:00
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>״̬Ϊ<CCAC><CEAA>ȡ<EFBFBD><C8A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
status_ = STATUS_T_HDR;
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>ͷ
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client_->read(sizeof(DAT_HDR), __timeout);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ɹ<EFBFBD><EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
2019-06-16 20:10:40 +08:00
|
|
|
|
bool write_callback(void)
|
2015-05-18 20:05:22 +08:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʱ<EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
2019-06-16 20:10:40 +08:00
|
|
|
|
void close_callback(void)
|
2015-05-18 20:05:22 +08:00
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ڴ˴<DAB4>ɾ<EFBFBD><C9BE><EFBFBD>ö<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD>ֹ<EFBFBD>ڴ<EFBFBD>й¶
|
2015-05-18 20:05:22 +08:00
|
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* ʵ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD>ʱ<EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><EFBFBD><EFBFBD>رո<EFBFBD><EFBFBD>첽<EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
2019-06-16 20:10:40 +08:00
|
|
|
|
bool timeout_callback(void)
|
2015-05-18 20:05:22 +08:00
|
|
|
|
{
|
|
|
|
|
std::cout << "Timeout, delete it ..." << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
status_t status_;
|
|
|
|
|
acl::aio_socket_stream* client_;
|
2019-06-16 20:10:40 +08:00
|
|
|
|
int i_;
|
2015-05-18 20:05:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
|
|
|
|
class io_accept_callback : public acl::aio_accept_callback
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-06-16 20:10:40 +08:00
|
|
|
|
io_accept_callback(void) {}
|
|
|
|
|
~io_accept_callback(void)
|
2015-05-18 20:05:22 +08:00
|
|
|
|
{
|
|
|
|
|
printf(">>io_accept_callback over!\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>麯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˻ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param client {aio_socket_stream*} <EFBFBD>첽<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>֪ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
*/
|
|
|
|
|
bool accept_callback(acl::aio_socket_stream* client)
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
io_callback* callback = new io_callback(client);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ע<><D7A2><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD>Ķ<EFBFBD><C4B6>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client->add_read_callback(callback);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ע<><D7A2><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD><EFBFBD>д<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client->add_write_callback(callback);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ע<><D7A2><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD>Ĺرջص<D5BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client->add_close_callback(callback);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// ע<><D7A2><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD>ij<EFBFBD>ʱ<EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client->add_timeout_callback(callback);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>ͷ
|
2015-05-18 20:05:22 +08:00
|
|
|
|
client->read(sizeof(DAT_HDR), __timeout);
|
2019-06-16 20:10:40 +08:00
|
|
|
|
return true;
|
2015-05-18 20:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void usage(const char* procname)
|
|
|
|
|
{
|
|
|
|
|
printf("usage: %s -h[help]\r\n"
|
|
|
|
|
" -l ip:port[:1900]\r\n"
|
|
|
|
|
" -t timeout\r\n"
|
|
|
|
|
" -k[use kernel event: epoll/iocp/kqueue/devpool]\r\n",
|
|
|
|
|
procname);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
bool use_kernel = false;
|
|
|
|
|
int ch;
|
|
|
|
|
acl::string addr(":1900");
|
|
|
|
|
|
2019-06-16 20:10:40 +08:00
|
|
|
|
while ((ch = getopt(argc, argv, "l:hkt:")) > 0) {
|
|
|
|
|
switch (ch) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
case 'h':
|
|
|
|
|
usage(argv[0]);
|
2019-06-16 20:10:40 +08:00
|
|
|
|
return 0;
|
2015-05-18 20:05:22 +08:00
|
|
|
|
case 'l':
|
|
|
|
|
addr = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'k':
|
|
|
|
|
use_kernel = true;
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
__timeout = atoi(optarg);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><>ʼ<EFBFBD><CABC>ACL<43><4C>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WIN32<33><32>һ<EFBFBD><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UNIXƽ̨<C6BD>¿ɲ<C2BF><C9B2><EFBFBD><EFBFBD><EFBFBD>)
|
2019-06-16 20:10:40 +08:00
|
|
|
|
acl::acl_cpp_init();
|
|
|
|
|
|
2015-05-18 20:05:22 +08:00
|
|
|
|
acl::log::stdout_open(true);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
acl::aio_handle handle(use_kernel ? acl::ENGINE_KERNEL : acl::ENGINE_SELECT);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽<EFBFBD><ECB2BD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
acl::aio_listen_stream* sstream = new acl::aio_listen_stream(&handle);
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ĵ<EFBFBD>ַ
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (!sstream->open(addr.c_str())) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
std::cout << "open " << addr.c_str() << " error!" << std::endl;
|
|
|
|
|
sstream->close();
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// XXX: Ϊ<>˱<EFBFBD>֤<EFBFBD>ܹرռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD> check һ<><D2BB>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
handle.check();
|
|
|
|
|
|
|
|
|
|
getchar();
|
2019-06-16 20:10:40 +08:00
|
|
|
|
return 1;
|
2015-05-18 20:05:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3A3ACB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
io_accept_callback callback;
|
|
|
|
|
sstream->add_accept_callback(&callback);
|
|
|
|
|
std::cout << "Listen: " << addr.c_str() << " ok!" << std::endl;
|
|
|
|
|
|
2019-06-16 20:10:40 +08:00
|
|
|
|
while (true) {
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <20><><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ټ<EFBFBD><D9BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>˳<EFBFBD>
|
2019-06-16 20:10:40 +08:00
|
|
|
|
if (!handle.check()) {
|
2015-05-18 20:05:22 +08:00
|
|
|
|
std::cout << "pkg_server stop now ..." << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
sstream->close();
|
|
|
|
|
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// XXX: Ϊ<>˱<EFBFBD>֤<EFBFBD>ܹرռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ڴ˴<DAB4><CBB4><EFBFBD> check һ<><D2BB>
|
2015-05-18 20:05:22 +08:00
|
|
|
|
handle.check();
|
|
|
|
|
|
2019-06-16 20:10:40 +08:00
|
|
|
|
return 0;
|
2015-05-18 20:05:22 +08:00
|
|
|
|
}
|