Skip to content

Commit

Permalink
update argument parser
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlcrashr committed Jul 6, 2018
1 parent 3f49eb9 commit 67d3d4f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ int Arguments::ParseArguments(Arguments::Parameters *params, const char **args,
{
while (i < argsCnt)
{
if (i+1 >= argsCnt) return 4;
if (i+1 >= argsCnt) break;
if (strncmp(args[i+1], "\"#", 2) == 0) break;
tmp.append(args[i+1]);
A3URLCommon::StrUnqoute(&tmp);
if (tmp.at(0) == '#' || tmp.empty()) break;
params->PostData.append(tmp);
tmp.clear();
i++;
Expand All @@ -63,7 +62,7 @@ int Arguments::ParseArguments(Arguments::Parameters *params, const char **args,
{
while (i < argsCnt)
{
if (i+2 >= argsCnt) return 5;
if (i+2 >= argsCnt) break;
if (strncmp(args[i+1], "\"#", 2) == 0 || strncmp(args[i+2], "\"#", 2) == 0) break;
tmpArg.append(args[i+1]);
A3URLCommon::StrUnqoute(&tmpArg);
Expand Down
42 changes: 23 additions & 19 deletions test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,50 @@ void makeRequest() {
char *output = new char[8192];
int outputSize = 8192;
const char *function = "SENDRQ";
const char *args[10];
const char *args[12];
const char *tmp1 = "\"#url\"";
const char *tmp2 = "\"https://httpbin.org/get\"";
const char *tmp2 = "\"https://httpbin.org/post\"";
const char *tmp3 = "\"#postData\"";
const char *tmp4 = "\"test\"";
const char *tmp5 = "\"#headers\"";
const char *tmp6 = "\"User-Afhjfjfgent\"";
const char *tmp7 = "\"testtttt\"";
const char *tmp4 = "\"test1\"";
const char *tmp5 = "\"test2\"";
const char *tmp6 = "\"test3\"";
const char *tmp7 = "\"test4\"";
const char *tmp8 = "\"#headers\"";
const char *tmp9 = "\"User-Afhjfjfgent\"";
const char *tmp10 = "\"testtttt\"";
const char *tmp11 = "\"#method\"";
const char *tmp12 = "\"POST\"";
args[0] = tmp1;
args[1] = tmp2;
args[2] = tmp3;
args[3] = tmp4;
args[4] = tmp5;
args[5] = tmp6;
args[6] = tmp7;
args[7] = tmp8;
args[8] = tmp9;
args[9] = tmp10;
args[10] = tmp11;
args[11] = tmp12;

hndl->CallExtensionArgs(output, outputSize, function, args, 12);

hndl->CallExtensionArgs(output, outputSize, function, args, 7);

std::this_thread::sleep_for(std::chrono::seconds(1));


auto start = std::chrono::high_resolution_clock::now();
const char *args2[1];
args2[0] = std::string(output).c_str();
std::cout << args2[0] << std::endl;

auto start = std::chrono::high_resolution_clock::now();
hndl->CallExtensionArgs(output, outputSize, "GETRQ", args2, 1);
args2[0] = std::string(output).c_str();
std::cout << args2[0] << std::endl;
auto finish = std::chrono::high_resolution_clock::now();
std::cout << "Time Results:" << std::chrono::duration_cast<std::chrono::nanoseconds>(finish-start).count() << std::endl << "---" << std::endl;

std::cout << output << std::endl;
}

int main() {
int i = 0;
for (i = 0; i < 100; i++) {
std::cout << "starting thread " << i << std::endl;
std::thread t(makeRequest);
t.detach();
}

std::this_thread::sleep_for(std::chrono::seconds(10));
makeRequest();
return 0;
}

0 comments on commit 67d3d4f

Please sign in to comment.