diff --git a/callJvmThreadpool/client.cpp b/callJvmThreadpool/client.cpp index 51a1abe3f736ca2b7524e859a7c41179457e753f..39d6283bae6dfc4d6d795a925244e6697fbbd6e1 100644 --- a/callJvmThreadpool/client.cpp +++ b/callJvmThreadpool/client.cpp @@ -52,15 +52,3 @@ int main() read(sock, buffer, 1024); printf("%s\n", buffer); } - -int i; -for(i = 0; i < strlen(buffer); i++) -{ -if(buffer[i] == '$') -{ -strncpy(psql, buffer, i); -strncpy(dbn, buffer + i + 1, strlen(buffer) - i - 1); -} -} -printf("%s\n", psql); -printf("%s\n", dbn); diff --git a/callJvmThreadpool/server.cpp b/callJvmThreadpool/server.cpp index f453079b8caac626f843b02f3dca98074a22861f..b86d741cb074f272cfd1b058bade02166bbbcad5 100644 --- a/callJvmThreadpool/server.cpp +++ b/callJvmThreadpool/server.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #define PORT 8080 diff --git a/callJvmThreadpool/threadpool.cpp b/callJvmThreadpool/threadpool.cpp index bdbb76f6e36ae69d7eff8344fdceb68632b1bfe7..09e17ffff02218983d196e4dbc749ff7dd6f2096 100644 --- a/callJvmThreadpool/threadpool.cpp +++ b/callJvmThreadpool/threadpool.cpp @@ -7,8 +7,9 @@ #include #include #include -#include +#include #include +#include #include #include "tpool.h" @@ -39,23 +40,28 @@ void* handle_stream(void* myJvm, void* arg) { int server_fd = (int&)arg; char buf[1024]; - char* psql; - char* dbn; + read(server_fd, buf, 1024); printf("%s\n", buf); - int i; - for(i = 0; i < strlen(buf); i++) + char* psql; + char* dbn; + char delims[] = "$"; + char *res = nullptr; + std::vector resvec; + + res = strtok(buf, delims); + while (res != nullptr) { - if(buf[i] == '$') - { - strncpy(psql, buf, i); - strncpy(dbn, buf + i + 1, strlen(buf) - i - 1); - } + resvec.push_back(res); + res = strtok(nullptr, delims); } - jvmThreads(arg, psql, dbn); + psql = resvec[0]; + dbn = resvec[1]; + + jvmThreads(myJvm, psql, dbn); }