本文整理汇总了C++中SocketHandler::getConnectionMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketHandler::getConnectionMessage方法的具体用法?C++ SocketHandler::getConnectionMessage怎么用?C++ SocketHandler::getConnectionMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketHandler
的用法示例。
在下文中一共展示了SocketHandler::getConnectionMessage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SocketHandler
/**
* Connection dealer
* @param arg should be (int *), indicates the socket_fd
* @return NULL
*/
void * connection_handler(void * arg) {
int * client_fd = (int *) arg;
SocketHandler * socket = new SocketHandler(* client_fd);
delete client_fd;
string message = socket->getConnectionMessage();
vector <string> details = split(message, '\n');
if (details[0] == CONFIG->Getjudger_string()) {
// format: judger_string\nOJ
LOG("Judger connected, OJ: " + details[1]);
if (judgers.size() < MAX_JUDGER_NUMBER) {
pthread_t thread_id;
JudgerArgs * arg = new JudgerArgs(socket, details[1]);
pthread_create(&thread_id, NULL, judger_handler, (void *) arg);
pthread_detach(thread_id);
} else {
LOG("Too many judgers, refuse to setup new handler.");
// because it won't be deleted afterwards
delete socket;
}
} else if (details[0] == CONFIG->Getsubmit_string()) {
// format: submit_string\nrunid\nOJ
LOG("Received a submit, runid: " + details[1] + ", oj: " + details[2]);
insert_run(new Submit(NEED_JUDGE, details[1], details[2]));
} else if (details[0] == CONFIG->Getpretest_string()) {
// format: pretest_string\nrunid\nOJ
LOG("Received a pretest request, runid: " + details[1] + ", oj: " +
details[2]);
insert_run(new Submit(DO_PRETEST, details[1], details[2]));
} else if (details[0] == CONFIG->Geterror_rejudge_string()) {
// format: error_rejudge_string\nrunid\nOJ
LOG("Received an error rejudge request, runid: " + details[1] + ", oj: " +
details[2]);
insert_run(new Submit(NEED_JUDGE, details[1], details[2]));
} else if (details[0] == CONFIG->Getchallenge_string()) {
// format: challenge_string\nchallenge_id\nOJ
LOG("Received a challenge request, runid: " + details[1] + ", oj: " +
details[2]);
insert_run(new Submit(DO_CHALLENGE, details[1], details[2]));
} else if (details[0] == CONFIG->Getrejudge_string()) {
// format: rejudge_string\nproblem_id\ncontest_id
LOG("Received a rejudge request, pid: " + details[1] + ", cid: " +
details[2]);
DatabaseHandler * db = get_db_instance();
vector <map<string, string> > result = db->Getall_results("\
SELECT runid, vname \
FROM status, problem \
WHERE result='Rejudging' AND \
contest_belong='" + db->escape(details[2]) + "' AND \
status.pid='" + db->escape(details[1]) + "' AND \
status.pid=problem.pid \
ORDER BY runid \
");
delete db;
for (vector <map<string, string> >::iterator it = result.begin();
it != result.end(); ++it) {
insert_run(new Submit(NEED_JUDGE, (*it)["runid"], (*it)["vname"]));
}
} else if (details[0] == CONFIG->Gettestall_string()) {