Skip to content

Revert "Refactor Msg class" #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ tests/testargs.log
tests/testargs.trs
tests/test-setup.sh
tests/listing.txt
unittests/testargs
unittests/testargs.trs
# others
compile_commands.json
.vs*
4 changes: 2 additions & 2 deletions client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ int main(int argc, char **argv)

string native;

if (umsg && *umsg == Msg::NATIVE_ENV) {
if (umsg && umsg->type == M_NATIVE_ENV) {
native = static_cast<UseNativeEnvMsg*>(umsg)->nativeVersion;
}

Expand Down Expand Up @@ -600,7 +600,7 @@ int main(int argc, char **argv)

/* If we can't talk to the daemon anymore we need to fall back
to lock file locking. */
if (!startme || *startme != Msg::JOB_LOCAL_BEGIN) {
if (!startme || startme->type != M_JOB_LOCAL_BEGIN) {
delete startme;
delete local_daemon;
return build_local(job, nullptr);
Expand Down
20 changes: 10 additions & 10 deletions client/remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ static UseCSMsg *get_server(MsgChannel *local_daemon)
timeout = 60 * 60;
Msg *umsg = local_daemon->get_msg( timeout );

if (!umsg || *umsg != Msg::USE_CS) {
log_warning() << "reply was not expected use_cs " << (umsg ? umsg->to_string() : Msg(Msg::UNKNOWN).to_string()) << endl;
if (!umsg || umsg->type != M_USE_CS) {
log_warning() << "reply was not expected use_cs " << (umsg ? (char)umsg->type : '0') << endl;
ostringstream unexpected_msg;
unexpected_msg << "Error 1 - expected use_cs reply, but got " << (umsg ? umsg->to_string() : Msg(Msg::UNKNOWN).to_string()) << " instead";
unexpected_msg << "Error 1 - expected use_cs reply, but got " << (umsg ? (char)umsg->type : '0') << " instead";
delete umsg;
throw client_error(1, unexpected_msg.str());
}
Expand All @@ -260,7 +260,7 @@ static UseCSMsg *get_server(MsgChannel *local_daemon)

static void check_for_failure(Msg *msg, MsgChannel *cserver)
{
if (msg && *msg == Msg::STATUS_TEXT) {
if (msg && msg->type == M_STATUS_TEXT) {
log_error() << "Remote status (compiled on " << cserver->name << "): "
<< static_cast<StatusTextMsg*>(msg)->text << endl;
throw client_error(23, "Error 23 - Remote status (compiled on " + cserver->name + ")\n" +
Expand Down Expand Up @@ -361,11 +361,11 @@ static void receive_file(const string& output_file, MsgChannel* cserver)

check_for_failure(msg, cserver);

if (*msg == Msg::END) {
if (msg->type == M_END) {
break;
}

if (*msg != Msg::FILE_CHUNK) {
if (msg->type != M_FILE_CHUNK) {
unlink(tmp_file.c_str());
delete msg;
throw client_error(20, "Error 20 - unexpected message");
Expand Down Expand Up @@ -482,7 +482,7 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_

Msg *verify_msg = cserver->get_msg(60);

if (verify_msg && *verify_msg == Msg::VERIFY_ENV_RESULT) {
if (verify_msg && verify_msg->type == M_VERIFY_ENV_RESULT) {
if (!static_cast<VerifyEnvResultMsg*>(verify_msg)->ok) {
// The remote can't handle the environment at all (e.g. kernel too old),
// mark it as never to be used again for this environment.
Expand Down Expand Up @@ -609,8 +609,8 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_

check_for_failure(msg, cserver);

if (*msg != Msg::COMPILE_RESULT) {
log_warning() << "waited for compile result, but got " << msg->to_string() << endl;
if (msg->type != M_COMPILE_RESULT) {
log_warning() << "waited for compile result, but got " << (char)msg->type << endl;
delete msg;
throw client_error(13, "Error 13 - did not get compile response message");
}
Expand Down Expand Up @@ -670,7 +670,7 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_
// Handle pending status messages, if any.
if(cserver) {
while(Msg* msg = cserver->get_msg(0, true)) {
if(*msg == Msg::STATUS_TEXT)
if(msg->type == M_STATUS_TEXT)
log_error() << "Remote status (compiled on " << cserver->name << "): "
<< static_cast<StatusTextMsg*>(msg)->text << endl;
delete msg;
Expand Down
2 changes: 1 addition & 1 deletion daemon/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ pid_t start_install_environment(const std::string &basename, const std::string &
string dirname = basename + "/target=" + target;
Msg *msg = c->get_msg(30);

if (!msg || *msg != Msg::FILE_CHUNK) {
if (!msg || msg->type != M_FILE_CHUNK) {
trace() << "Expected first file chunk\n";
return 0;
}
Expand Down
46 changes: 23 additions & 23 deletions daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,13 +1091,13 @@ bool Daemon::handle_file_chunk_env(Client *client, Msg *msg)
the file chunk to the child, but we can't let the child
handle MsgChannel itself due to MsgChannel's stupid
caching layer inbetween, which causes us to lose partial
data after the END msg of the env transfer. */
data after the M_END msg of the env transfer. */

assert(client);
assert(client->status == Client::TOINSTALL || client->status == Client::WAITINSTALL);
assert(client->pipe_to_child >= 0);

if (*msg == Msg::FILE_CHUNK) {
if (msg->type == M_FILE_CHUNK) {
FileChunkMsg *fcmsg = static_cast<FileChunkMsg *>(msg);
ssize_t len = fcmsg->len;
off_t off = 0;
Expand Down Expand Up @@ -1129,7 +1129,7 @@ bool Daemon::handle_file_chunk_env(Client *client, Msg *msg)
return true;
}

if (*msg == Msg::END) {
if (msg->type == M_END) {
trace() << "received end of environment, waiting for child" << endl;
close(client->pipe_to_child);
client->pipe_to_child = -1;
Expand All @@ -1143,7 +1143,7 @@ bool Daemon::handle_file_chunk_env(Client *client, Msg *msg)
}

// unexpected message type
log_error() << "protocol error while receiving environment (" << msg->to_string() << ")" << endl;
log_error() << "protocol error while receiving environment (" << msg->type << ")" << endl;
handle_end(client, 138);
return false;
}
Expand Down Expand Up @@ -1176,7 +1176,7 @@ bool Daemon::handle_env_install_child_done(Client *client)
if( !success )
return finish_transfer_env( client, true ); // cancel
if( client->pipe_to_child >= 0 ) {
// we still haven't received END message, wait for that
// we still haven't received M_END message, wait for that
assert( client->status == Client::TOINSTALL );
return true;
}
Expand Down Expand Up @@ -1896,37 +1896,37 @@ bool Daemon::handle_activity(Client *client)
return ret;
}

switch (*msg) {
case Msg::GET_NATIVE_ENV:
switch (msg->type) {
case M_GET_NATIVE_ENV:
ret = handle_get_native_env(client, dynamic_cast<GetNativeEnvMsg *>(msg));
break;
case Msg::COMPILE_FILE:
case M_COMPILE_FILE:
ret = handle_compile_file(client, msg);
break;
case Msg::TRANFER_ENV:
case M_TRANFER_ENV:
ret = handle_transfer_env(client, dynamic_cast<EnvTransferMsg*>(msg));
break;
case Msg::GET_CS:
case M_GET_CS:
ret = handle_get_cs(client, msg);
break;
case Msg::END:
case M_END:
handle_end(client, 119);
ret = false;
break;
case Msg::JOB_LOCAL_BEGIN:
case M_JOB_LOCAL_BEGIN:
ret = handle_local_job(client, msg);
break;
case Msg::JOB_DONE:
case M_JOB_DONE:
ret = handle_job_done(client, dynamic_cast<JobDoneMsg *>(msg));
break;
case Msg::VERIFY_ENV:
case M_VERIFY_ENV:
ret = handle_verify_env(client, dynamic_cast<VerifyEnvMsg *>(msg));
break;
case Msg::BLACKLIST_HOST_ENV:
case M_BLACKLIST_HOST_ENV:
ret = handle_blacklist_host_env(client, msg);
break;
default:
log_error() << "protocol error " << msg->to_string() << " on client "
log_error() << "protocol error " << msg->type << " on client "
<< client->dump() << endl;
client->channel->send_msg(EndMsg());
handle_end(client, 120);
Expand Down Expand Up @@ -2065,28 +2065,28 @@ void Daemon::answer_client_requests()

ret = 0;

switch (*msg) {
case Msg::PING:
switch (msg->type) {
case M_PING:

if (!IS_PROTOCOL_VERSION(27, scheduler)) {
ret = !send_scheduler(PingMsg());
}

break;
case Msg::USE_CS:
case M_USE_CS:
ret = scheduler_use_cs(static_cast<UseCSMsg *>(msg));
break;
case Msg::NO_CS:
case M_NO_CS:
ret = scheduler_no_cs(static_cast<NoCSMsg *>(msg));
break;
case Msg::GET_INTERNALS:
case M_GET_INTERNALS:
ret = scheduler_get_internals();
break;
case Msg::CS_CONF:
case M_CS_CONF:
ret = handle_cs_conf(static_cast<ConfCSMsg *>(msg));
break;
default:
log_error() << "unknown scheduler type " << msg->to_string() << endl;
log_error() << "unknown scheduler type " << (char)msg->type << endl;
ret = 1;
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/workit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ int work_it(CompileJob &j, unsigned int job_stat[], MsgChannel *client, CompileR
fcmsg = nullptr;
delete msg;
} else {
if (*msg == Msg::END) {
if (msg->type == M_END) {
input_complete = true;

if (!fcmsg && sock_in[1] != -1) {
Expand All @@ -460,7 +460,7 @@ int work_it(CompileJob &j, unsigned int job_stat[], MsgChannel *client, CompileR
}

delete msg;
} else if (*msg == Msg::FILE_CHUNK) {
} else if (msg->type == M_FILE_CHUNK) {
fcmsg = static_cast<FileChunkMsg*>(msg);
off = 0;

Expand Down
36 changes: 18 additions & 18 deletions scheduler/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ static bool handle_line(CompileServer *cs, Msg *_m)
msg = it->get_msg();
}

if (msg && *msg == Msg::STATUS_TEXT) {
if (msg && msg->type == M_STATUS_TEXT) {
if (!cs->send_msg(TextMsg(dynamic_cast<StatusTextMsg *>(msg)->text))) {
return false;
}
Expand Down Expand Up @@ -1758,17 +1758,17 @@ static bool try_login(CompileServer *cs, Msg *m)
{
bool ret = true;

switch (*m) {
case Msg::LOGIN:
switch (m->type) {
case M_LOGIN:
cs->setType(CompileServer::DAEMON);
ret = handle_login(cs, m);
break;
case Msg::MON_LOGIN:
case M_MON_LOGIN:
cs->setType(CompileServer::MONITOR);
ret = handle_mon_login(cs, m);
break;
default:
log_info() << "Invalid first message " << m->to_string() << endl;
log_info() << "Invalid first message " << (char)m->type << endl;
ret = false;
break;
}
Expand Down Expand Up @@ -1899,43 +1899,43 @@ static bool handle_activity(CompileServer *cs)
return try_login(cs, m);
}

switch (*m) {
case Msg::JOB_BEGIN:
switch (m->type) {
case M_JOB_BEGIN:
ret = handle_job_begin(cs, m);
break;
case Msg::JOB_DONE:
case M_JOB_DONE:
ret = handle_job_done(cs, m);
break;
case Msg::PING:
case M_PING:
ret = handle_ping(cs, m);
break;
case Msg::STATS:
case M_STATS:
ret = handle_stats(cs, m);
break;
case Msg::END:
case M_END:
handle_end(cs, m);
ret = false;
break;
case Msg::JOB_LOCAL_BEGIN:
case M_JOB_LOCAL_BEGIN:
ret = handle_local_job(cs, m);
break;
case Msg::JOB_LOCAL_DONE:
case M_JOB_LOCAL_DONE:
ret = handle_local_job_done(cs, m);
break;
case Msg::LOGIN:
case M_LOGIN:
ret = handle_relogin(cs, m);
break;
case Msg::TEXT:
case M_TEXT:
ret = handle_line(cs, m);
break;
case Msg::GET_CS:
case M_GET_CS:
ret = handle_cs_request(cs, m);
break;
case Msg::BLACKLIST_HOST_ENV:
case M_BLACKLIST_HOST_ENV:
ret = handle_blacklist_host_env(cs, m);
break;
default:
log_info() << "Invalid message type arrived " << m->to_string() << endl;
log_info() << "Invalid message type arrived " << (char)m->type << endl;
handle_end(cs, m);
ret = false;
break;
Expand Down
Loading