From ae823bf9068b1ce2a632dea961547080bc86e2fa Mon Sep 17 00:00:00 2001 From: xwhqsj Date: Sat, 2 Nov 2019 21:51:04 +0800 Subject: [PATCH] update socket --- callJvmThreadpool/client.cpp | 12 ------------ callJvmThreadpool/server.cpp | 1 - callJvmThreadpool/threadpool.cpp | 28 +++++++++++++++++----------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/callJvmThreadpool/client.cpp b/callJvmThreadpool/client.cpp index 51a1abe..39d6283 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 f453079..b86d741 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 bdbb76f..09e17ff 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); } -- GitLab