/** * Supplies blocks of data to server_current_tcp_out. */ static void server_tcp_out(struct tcp_pcb *pcb, struct server_tcp_state *ss) { if (ss->connected) { /* If we're connected */ if (server_current_tcp_out(pcb, ss)) { /* If the current block is empty */ /* Clear our position */ ss->current_pos = 0; ss->current_len = 0; /* Select a new data block to output */ switch(ss->output_phase) { case OP_HTTP_HEADER: /* Send a header that specifies how many records we are going to send */ ss->current_len = http_header(ss->output_buffer, ss->auth, ss->records_count); ss->output_phase++; break; case OP_JSON_HEADER: /* Start the JSON object */ ss->current_len = json_header(ss->output_buffer); ss->output_phase++; break; case OP_JSON_DATA: if (ss->records_index++ < ss->records_count) { /* If there are more records to be output */ /* Read from memory, and encode as a JSON element */ ss->current_len = json_element(ss->output_buffer, get_sample(ss->mem_output_index++), /* Read in the data from memory */ (ss->records_index < ss->records_count)); /* If this isn't the last, we need a comma */ } else { ss->output_phase++; } break; case OP_JSON_FOOTER: /* End the JSON object */ ss->current_len = json_footer(ss->output_buffer); ss->output_phase++; break; case OP_WAIT_BEFORE_CLOSE: /* Wait before closing the connection */ if (ss->wait_before_close_counter++ > WAIT_BEFORE_CLOSE) { ss->output_phase++; } break; case OP_CLOSE: tcp_close(ss->pcb); /* Close the connection */ ss->output_phase++; break; } /* And output that */ server_current_tcp_out(pcb, ss); } } }
Json::Value ResponseTask::generateResponseJson() { Json::Value response; epoch_t responseStart = _recordPerformanceData ? get_epoch_nanoseconds() : 0; PapiTracer pt; pt.addEvent("PAPI_TOT_CYC"); if (_recordPerformanceData) pt.start(); auto predecessor = getResultTask(); const auto& result = predecessor->getResultTable(); if (getState() != OpFail) { if (!_isAutoCommit) { response["session_context"] = std::to_string(_txContext.tid).append(" ").append(std::to_string(_txContext.lastCid)); } if (result) { // Make header Json::Value json_header(Json::arrayValue); for (unsigned col = 0; col < result->columnCount(); ++col) { Json::Value colname(result->nameOfColumn(col)); json_header.append(colname); } // Copy the complete result response["real_size"] = result->size(); response["rows"] = generateRowsJson(result, _transmitLimit, _transmitOffset); response["header"] = json_header; } //////////////////////////////////////////////////////////////////////////////////////// // Copy Performance Data if (_recordPerformanceData) { Json::Value json_perf(Json::arrayValue); for (const auto& attr : performance_data) { Json::Value element; element["papi_event"] = Json::Value(attr->papiEvent); element["duration"] = Json::Value((Json::UInt64)attr->duration); element["data"] = Json::Value((Json::UInt64)attr->data); element["name"] = Json::Value(attr->name); element["id"] = Json::Value(attr->operatorId); element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000); element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000); element["executingThread"] = Json::Value(attr->executingThread); element["lastCore"] = Json::Value(attr->core); element["lastNode"] = Json::Value(attr->node); // Put null for in/outRows if -1 was set element["inRows"] = attr->in_rows ? Json::Value(*(attr->in_rows)) : Json::Value(); element["outRows"] = attr->out_rows ? Json::Value(*(attr->out_rows)) : Json::Value(); if (_getSubQueryPerformanceData) { element["subQueryPerformanceData"] = _scriptOperation->getSubQueryPerformanceData(); } json_perf.append(element); } pt.stop(); Json::Value responseElement; responseElement["duration"] = Json::Value((Json::UInt64)pt.value("PAPI_TOT_CYC")); responseElement["name"] = Json::Value("ResponseTask"); responseElement["id"] = Json::Value("respond"); responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000); responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000); std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id()); responseElement["executingThread"] = Json::Value(threadId); responseElement["lastCore"] = Json::Value(getCurrentCore()); responseElement["lastNode"] = Json::Value(getCurrentNode()); std::optional<size_t> result_size; if (result) { result_size = result->size(); } responseElement["inRows"] = result_size ? Json::Value(*result_size) : Json::Value(); responseElement["outRows"] = Json::Value(); json_perf.append(responseElement); response["performanceData"] = json_perf; } Json::Value jsonKeys(Json::arrayValue); for (const auto& x : _generatedKeyRefs) { for (const auto& key : *x) { Json::Value element(key); jsonKeys.append(element); } } response["generatedKeys"] = jsonKeys; response["affectedRows"] = Json::Value(_affectedRows); if (_getSubQueryPerformanceData) { response["subQueryDataflow"] = _scriptOperation->getSubQueryDataflow(); } } LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count()); return response; }
void ResponseTask::operator()() { epoch_t responseStart = get_epoch_nanoseconds(); Json::Value response; if (getDependencyCount() > 0) { PapiTracer pt; pt.addEvent("PAPI_TOT_CYC"); pt.start(); auto predecessor = getResultTask(); const auto& result = predecessor->getResultTable(); if (predecessor->getState() != OpFail) { if (result) { // Make header Json::Value json_header(Json::arrayValue); for (unsigned col = 0; col < result->columnCount(); ++col) { Json::Value colname(result->nameOfColumn(col)); json_header.append(colname); } // Copy the complete result response["real_size"] = result->size(); response["rows"] = generateRowsJson(result, _transmitLimit); response["header"] = json_header; } // Copy Performance Data Json::Value json_perf(Json::arrayValue); for (const auto & attr: performance_data) { Json::Value element; element["papi_event"] = Json::Value(attr->papiEvent); element["duration"] = Json::Value((Json::UInt64) attr->duration); element["data"] = Json::Value((Json::UInt64) attr->data); element["name"] = Json::Value(attr->name); element["id"] = Json::Value(attr->operatorId); element["startTime"] = Json::Value((double)(attr->startTime - queryStart) / 1000000); element["endTime"] = Json::Value((double)(attr->endTime - queryStart) / 1000000); element["executingThread"] = Json::Value(attr->executingThread); json_perf.append(element); } pt.stop(); Json::Value responseElement; responseElement["duration"] = Json::Value((Json::UInt64) pt.value("PAPI_TOT_CYC")); responseElement["name"] = Json::Value("ResponseTask"); responseElement["id"] = Json::Value("respond"); responseElement["startTime"] = Json::Value((double)(responseStart - queryStart) / 1000000); responseElement["endTime"] = Json::Value((double)(get_epoch_nanoseconds() - queryStart) / 1000000); std::string threadId = boost::lexical_cast<std::string>(std::this_thread::get_id()); responseElement["executingThread"] = Json::Value(threadId); json_perf.append(responseElement); response["performanceData"] = json_perf; } else { LOG4CXX_ERROR(_logger, "Error during plan execution: " << predecessor->getErrorMessage()); response["error"] = predecessor->getErrorMessage(); } LOG4CXX_DEBUG(_logger, "Table Use Count: " << result.use_count()); } else { response["error"] = "Query parsing failed, see server error log"; } connection->respond(response.toStyledString()); }
int apiqry_main() { FILE *fp; char userid[14], filename[80], buf[512], output[4096],output_utf8[4096]; struct userec *x; struct user_info *u; int i, tmp2, num; json_header(); // changemode(QUERY); strsncpy(userid, getparm("U"), 13); if (!userid[0]) strsncpy(userid,getparm("userid"), 13); if (userid[0] == '\0') { printf("{\"User\":null}"); return 0; } x = getuser(userid); if (x == 0) { printf("{\"User\":null}"); return 0; } // ��ʼ����û����� sstrcat(output, "{\"User\":{"); // ��ʾ�������� sstrcat(output, "\"UserID\":\"%s\",\"UserNickName\":\"%s\",\"LoginCounts\":%d,\"PostCounts\":%d,\"LastLogin\":\"%s\",\"LastHost\":\"%s\",", x->userid, x->username, x->numlogins, x->numposts,Ctime(x->lastlogin), x->lasthost); // ��ʾ�������� if(!strcasecmp(x->userid, currentuser.userid)){ sstrcat(output, "\"Exp\":%d,\"ExpLevel\":\"%s\",\"Perf\":%d,\"PerfLevel\":\"%s\"",countexp(x), cexp(countexp(x)), countperf(x), cperf(countperf(x))); } // ��ʾ����վ�����Ϣ if(x->userlevel & PERM_BOARDS) { sstrcat(output, "\"BOARDBM\":["); sethomefile(filename, x->userid, "mboard"); new_apply_record(filename, sizeof(struct boardmanager), (void *)bm_printboardapi, output); sstrcat(output, "],"); } if((x->userlevel & PERM_SYSOP) && (x->userlevel&PERM_ARBITRATE)) sstrcat(output, "\"Job\":\"��վ������\","); else if(x->userlevel & PERM_SYSOP) sstrcat(output, "\"Job\":\"����վ��\","); else if(x->userlevel & PERM_OBOARDS) sstrcat(output, "\"Job\":\"ʵϰվ��\","); else if(x->userlevel & PERM_ARBITRATE) sstrcat(output, "\"Job\":\"���μ�ί\","); else if(x->userlevel & PERM_SPECIAL4) sstrcat(output, "\"Job\":\"����\","); else if(x->userlevel & PERM_WELCOME) sstrcat(output, "\"Job\":\"ϵͳ����\","); else if(x->userlevel & PERM_SPECIAL7) { if((x->userlevel & PERM_SPECIAL1) && !(x->userlevel & PERM_CLOAK)) sstrcat(output, "\"Job\":\"���γ���Ա\","); else sstrcat(output, "\"Job\":\"�������Ա\","); } else if(x->userlevel & PERM_ACCOUNTS) sstrcat(output, "\"Job\":\"�ʺŹ���Ա\","); // ��ʾ��ǰ״̬��null ���� array num = 0; sstrcat(output, "\"States\":"); for (i=0; i<MAXACTIVE; ++i) { u = &(shm_utmp->uinfo[i]); if(!strcmp(u->userid, x->userid)) { if(u->active == 0 || u->pid ==0 || (u->invisible && !HAS_PERM(PERM_SEECLOAK))) continue; ++num; if(num == 1) sstrcat(output, "["); if(u->mode != USERDF4){ if(u->invisible) sstrcat(output, "\"C%s\"", ModeType(u->mode)); else sstrcat(output, "\"%s\"", ModeType(u->mode)); } else // �Զ���״̬ sstrcat(output, "%s", u->user_state_temp); } if( (num>0) && (i == MAXACTIVE - 1)) sstrcat(output, "],"); } if (num == 0 ) { sstrcat(output, "\"null\","); if( x->lastlogout != NULL ) sstrcat(output, "\"LastLogout\":\"%s\",",Ctime(x->lastlogout)); else sstrcat(output, "\"LastLogout\":null,"); } // ��ʾ˵���� sethomefile(filename,x->userid,"plans"); fp = fopen(filename, "r"); sprintf(filename, "00%s-plan", x->userid); if (fp) { sstrcat(output, "\"PersonalIntro\":\""); // ��ʼ����˵���� while(1){ if(fgets(buf,256,fp) == 0) break; if (buf[strlen(buf) - 1] == '\n'){ int currentlength; currentlength = strlen(buf); buf[currentlength - 1] = '\\'; buf[currentlength] = 'n'; buf[currentlength + 1] = 0; } if(!strncmp(buf,"bigin 644",10)){ // errlog() // fdisplay_attach() } sstrcat(output, "%s", buf); } sstrcat(output, "\","); // ��������˵���� fclose(fp); } else //û�и���˵���� sstrcat(output, "\"PersonalIntro\":null,"); // ��ʾ�����ǩ show_special_api(x->userid, output); // ������� sstrcat(output, "}}"); g2u(output,sizeof(output), output_utf8,sizeof(output_utf8)); printf("%s", output_utf8); //http_quit(); return 0; }