From 4b2fafbc156d5b9fe06c15d8524c498ae791d0b0 Mon Sep 17 00:00:00 2001 From: cmz <3256005191@qq.com> Date: Mon, 16 Dec 2024 22:28:49 +0800 Subject: [PATCH] cmz --- src/kernel/CommRequest - 改.h | 87 ++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/kernel/CommRequest - 改.h diff --git a/src/kernel/CommRequest - 改.h b/src/kernel/CommRequest - 改.h new file mode 100644 index 0000000..e99115a --- /dev/null +++ b/src/kernel/CommRequest - 改.h @@ -0,0 +1,87 @@ +// °æȨÉùÃ÷£¬±íÃ÷¸ÃÎļþÓÉSogou, Inc.°æȨËùÓУ¬²¢ÇÒ¸ù¾ÝApache License 2.0ÊÚȨ¡£ +/* + Copyright (c) 2019 Sogou, Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Author: Xie Han (xiehan@sogou-inc.com) +*/ + +#ifndef _COMMREQUEST_H_ +#define _COMMREQUEST_H_ + + +#include +#include +#include "SubTask.h" +#include "Communicator.h" +#include "CommScheduler.h" + +// ¶¨ÒåCommRequestÀ࣬¼Ì³Ð×ÔSubTaskºÍCommSession +class CommRequest : public SubTask, public CommSession +{ +public: + // ¹¹Ô캯Êý£¬³õʼ»¯schedulerºÍobject£¬ÉèÖÃwait_timeoutΪ0 + CommRequest(CommSchedObject* object, CommScheduler* scheduler) + { + this->scheduler = scheduler; + this->object = object; + this->wait_timeout = 0; + } + + // »ñÈ¡ÇëÇó¶ÔÏóµÄº¯Êý + CommSchedObject* get_request_object() const { return this->object; } + // ÉèÖÃÇëÇó¶ÔÏóµÄº¯Êý + void set_request_object(CommSchedObject* object) { this->object = object; } + // »ñÈ¡µÈ´ý³¬Ê±Ê±¼äµÄº¯Êý + int get_wait_timeout() const { return this->wait_timeout; } + // ÉèÖõȴý³¬Ê±Ê±¼äµÄº¯Êý + void set_wait_timeout(int timeout) { this->wait_timeout = timeout; } + +public: + // Ð麯Êýdispatch£¬ÓÃÓÚµ÷¶ÈÇëÇó + virtual void dispatch() + { + if (this->scheduler->request(this, this->object, this->wait_timeout, + &this->target) < 0) + { + this->handle(CS_STATE_ERROR, errno); + } + } + +protected: + // ״̬ºÍ´íÎóÂë³ÉÔ±±äÁ¿ + int state; + int error; + + // Ä¿±ê¶ÔÏóÖ¸Õë + CommTarget* target; + + // ³¬Ê±Ô­ÒòµÄ¶¨Òå +#define TOR_NOT_TIMEOUT 0 +#define TOR_WAIT_TIMEOUT 1 +#define TOR_CONNECT_TIMEOUT 2 +#define TOR_TRANSMIT_TIMEOUT 3 +// ³¬Ê±Ô­Òò±äÁ¿ + int timeout_reason; + + // ³ÉÔ±±äÁ¿£¬°üÀ¨³¬Ê±Ê±¼ä¡¢ÇëÇó¶ÔÏóÖ¸ÕëºÍµ÷¶ÈÆ÷Ö¸Õë + int wait_timeout; + CommSchedObject* object; + CommScheduler* scheduler; + + // Ð麯Êýhandle£¬ÓÃÓÚ´¦ÀíÇëÇó״̬ºÍ´íÎó + virtual void handle(int state, int error); +}; + +#endif \ No newline at end of file