From a89c689ccb4d053ae71cc6d6787e842aa40e3669 Mon Sep 17 00:00:00 2001 From: Eric Buxkemper Date: Mon, 9 Nov 2015 18:16:10 -0600 Subject: [PATCH] V7 --- simpleclient.cpp | 73 +++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/simpleclient.cpp b/simpleclient.cpp index 6af61d9..dac456e 100755 --- a/simpleclient.cpp +++ b/simpleclient.cpp @@ -106,41 +106,58 @@ int main(int argc, char * argv[]) { break; } } - - string channel_name; - for(int i=0; i < w; i++){ - channel_name = chan.send_request("newthread"); - cout << "Chan: " << channel_name << endl; - RequestChannel* worker_ret = new RequestChannel(channel_name, RequestChannel::CLIENT_SIDE); - Worker_Thread(argv, worker_ret); + + // 0 is the parent. + + + for(int i=0; i < 3; i++){ + //stat thread + + pid = fork(); + if(pid != 0){ + + break; + } + + } + + RequestChannel* worker_ret; + string channel_name; + if(pid == 0){ + for(int i=0; i < w; i++){ + + channel_name = chan.send_request("newthread"); + cout << "Chan: " << channel_name << endl; + worker_ret = new RequestChannel(channel_name, RequestChannel::CLIENT_SIDE); + + pid = fork(); + if(pid != 0) { + Worker_Thread(argv, worker_ret); + break; + } + } + chan.send_request("quit"); + } else { + } - - chan.send_request("quit"); - } - usleep(1000000); + usleep(1000000); +} + +void* Worker_Thread(char* arg[], RequestChannel* chan){ + while(true){ + string req = Request_Buffer->pop(); + cout << "Request: " << req << endl; + string response = chan->send_request(req); + cout << "Response: " << response << endl; + } + chan->send_request("quit"); } void* Req_Thread(string name){ Request_Buffer->push("data" + name); } -void* Worker_Thread(char* arg[], RequestChannel* chan){ - //handles the data moving between the Server and Bounded Buffer - //control chan("control", RequestChannel::CLIENT_SIDE); - //string channel_name = control.send_request("newthread"); - //RequestChannel * channel_ret = new RequestChannel(channel_name, RequestChannel::CLIENT_SIDE); - while(true){ - - string req = Request_Buffer->pop(); - cout << "Request: " << req << endl; - string response = chan->send_request(req); - cout << "Response: " << response << endl; - - } - chan->send_request("quit"); -} - -string local_send_request(){ +void* local_send_request(){ }