summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanjie Wu <hanjiew@andrew.cmu.edu>2023-12-19 03:28:14 -0500
committerHanjie Wu <hanjiew@andrew.cmu.edu>2023-12-19 03:28:14 -0500
commit67785e3ebff3d9d07bd95674099c84c2bb78c558 (patch)
tree6285af85c8e8ffb7357a1048eefa31f0024a7e5f
parent2d3d731726d77099fe50a0e3c228af2263d42ffb (diff)
bugfixHEAD
-rw-r--r--src/uTPCore.cc46
-rw-r--r--src/uTPCore.h3
2 files changed, 29 insertions, 20 deletions
diff --git a/src/uTPCore.cc b/src/uTPCore.cc
index 4113f959..436fe25b 100644
--- a/src/uTPCore.cc
+++ b/src/uTPCore.cc
@@ -96,9 +96,9 @@ uint64 uTPCore::stateChangeCallback(utp_callback_arguments* arg)
uTPCore* utp = (uTPCore*)utp_get_userdata(arg->socket);
if (arg->state == UTP_STATE_CONNECT || arg->state == UTP_STATE_WRITABLE) {
utp->isWritable_ = true;
- if (utp->command_ != nullptr && utp->writeCheck_ == true) {
- utp->command_->setStatusActive();
- utp->command_->writeEventReceived();
+ if (utp->writeCommand_ != nullptr && utp->writeCheck_ == true) {
+ utp->writeCommand_->setStatusActive();
+ utp->writeCommand_->writeEventReceived();
}
}
return 0;
@@ -119,9 +119,9 @@ uint64 uTPCore::readCallback(utp_callback_arguments* arg)
else {
utp_read_drained(utp->s_);
}
- if (utp->command_ != nullptr && utp->readCheck_ == true) {
- utp->command_->setStatusActive();
- utp->command_->readEventReceived();
+ if (utp->readCommand_ != nullptr && utp->readCheck_ == true) {
+ utp->readCommand_->setStatusActive();
+ utp->readCommand_->readEventReceived();
}
return 0;
}
@@ -131,9 +131,13 @@ uint64 uTPCore::errorCallback(utp_callback_arguments* arg)
uTPCore* utp = (uTPCore*)utp_get_userdata(arg->socket);
if (utp != nullptr) {
utp->errNum_ = arg->error_code + 1;
- if (utp->command_ != nullptr) {
- utp->command_->setStatusActive();
- utp->command_->errorEventReceived();
+ if (utp->readCommand_ != nullptr) {
+ utp->readCommand_->setStatusActive();
+ utp->readCommand_->errorEventReceived();
+ }
+ if (utp->writeCommand_ != nullptr) {
+ utp->writeCommand_->setStatusActive();
+ utp->writeCommand_->errorEventReceived();
}
}
return 0;
@@ -198,7 +202,8 @@ uTPCore::uTPCore(utp_socket* s)
errNum_(0),
readCheck_(false),
writeCheck_(false),
- command_(nullptr),
+ readCommand_(nullptr),
+ writeCommand_(nullptr),
SocketCore(SOCK_DGRAM)
{
buf_.resize(16_k);
@@ -221,12 +226,12 @@ void uTPCore::establishConnection(const std::string& host, uint16_t port,
struct addrinfo* rp;
for (rp = res; rp; rp = rp->ai_next) {
s_ = utp_create_socket(rp->ai_family == AF_INET ? ctx_ : ctx6_);
- utp_set_userdata(s_, (void*)this);
if (utp_connect(s_, rp->ai_addr, rp->ai_addrlen) != 0) {
utp_close(s_);
s_ = nullptr;
continue;
}
+ utp_set_userdata(s_, (void*)this);
return;
}
throw DL_ABORT_EX(
@@ -304,7 +309,8 @@ void uTPCore::closeConnection()
utp_close(s_);
}
s_ = nullptr;
- command_ = nullptr;
+ readCommand_ = nullptr;
+ writeCommand_ = nullptr;
}
std::string uTPCore::getSocketError() const
@@ -321,29 +327,31 @@ std::string uTPCore::getSocketError() const
void uTPCore::setRWCheck(Command* command, int is_add, int is_read)
{
if (is_add == true) {
- command_ = command;
if (is_read == true) {
readCheck_ = true;
+ readCommand_ = command;
if (isReadable(0)) {
- command_->setStatusActive();
- command_->readEventReceived();
+ readCommand_->setStatusActive();
+ readCommand_->readEventReceived();
}
}
else {
writeCheck_ = true;
+ writeCommand_ = command;
if (isWritable(0)) {
- command_->setStatusActive();
- command_->writeEventReceived();
+ writeCommand_->setStatusActive();
+ writeCommand_->writeEventReceived();
}
}
}
else {
- command_ = command;
if (is_read == true) {
readCheck_ = false;
+ readCommand_ = nullptr;
}
else {
writeCheck_ = false;
+ writeCommand_ = nullptr;
}
}
}
@@ -387,7 +395,7 @@ bool uTPListenCommand::execute()
A2_LOG_INFO_EX("Exception thrown while receiving UDP message.", e);
}
utp_check_timeouts(ctx_);
- e_->addRoutineCommand(std::unique_ptr<Command>(this));
+ e_->addCommand(std::unique_ptr<Command>(this));
return false;
}
diff --git a/src/uTPCore.h b/src/uTPCore.h
index 838d0500..f844bab7 100644
--- a/src/uTPCore.h
+++ b/src/uTPCore.h
@@ -27,7 +27,8 @@ private:
bool readCheck_;
bool writeCheck_;
- Command* command_;
+ Command* readCommand_;
+ Command* writeCommand_;
static utp_context* ctx_;
static utp_context* ctx6_;