This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
csce313-mp4pinie64backup/simpleclient.cpp

128 lines
3.5 KiB
C++
Raw Normal View History

2015-11-05 18:33:21 -06:00
/*
File: simpleclient.C
Author: R. Bettati
Department of Computer Science
Texas A&M University
Date : 2013/01/31
Simple client main program for MP3 in CSCE 313
*/
/*--------------------------------------------------------------------------*/
/* DEFINES */
/*--------------------------------------------------------------------------*/
/* -- (none) -- */
/*--------------------------------------------------------------------------*/
/* INCLUDES */
/*--------------------------------------------------------------------------*/
#include <cassert>
#include <cstring>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include "reqchannel.h"
#include "semaphore.h"
2015-11-06 11:56:25 -06:00
#include "BoundedBuffer.h"
2015-11-05 18:33:21 -06:00
using namespace std;
/*--------------------------------------------------------------------------*/
/* DATA STRUCTURES */
/*--------------------------------------------------------------------------*/
/* -- (none) -- */
/*--------------------------------------------------------------------------*/
/* CONSTANTS */
/*--------------------------------------------------------------------------*/
/* -- (none) -- */
/*--------------------------------------------------------------------------*/
/* FORWARDS */
/*--------------------------------------------------------------------------*/
/* -- (none) -- */
/*--------------------------------------------------------------------------*/
/* MAIN FUNCTION */
/*--------------------------------------------------------------------------*/
int main(int argc, char * argv[]) {
2015-11-06 11:56:25 -06:00
2015-11-06 11:30:46 -06:00
int option = -1;
2015-11-06 12:48:11 -06:00
unsigned int n;
unsigned int b;
unsigned int w;
2015-11-06 11:30:46 -06:00
while ((option = getopt(argc, argv, "n:b:w:")) != -1){
switch (option){
case 'n' :
n = atoi(optarg);
break;
case 'b' :
b = atoi(optarg);
break;
case 'w' :
w = atoi(optarg);
break;
}
}
2015-11-06 11:56:25 -06:00
cout << "TEST: " << n << b << w << endl;
2015-11-05 18:33:21 -06:00
Semaphore sema(5);
cout << "CLIENT STARTED:" << endl;
pid_t pid = fork();
if(pid == 0){
cout << "Establishing control channel... " << flush;
RequestChannel chan("control", RequestChannel::CLIENT_SIDE);
cout << "done." << endl;
/* -- Start sending a sequence of requests */
string reply1 = chan.send_request("hello");
cout << "Reply to request 'hello' is '" << reply1 << "'" << endl;
string reply2 = chan.send_request("data Joe Smith");
cout << "Reply to request 'data Joe Smith' is '" << reply2 << "'" << endl;
string reply3 = chan.send_request("data Jane Smith");
cout << "Reply to request 'data Jane Smith' is '" << reply3 << "'" << endl;
string reply5 = chan.send_request("newthread");
cout << "Reply to request 'newthread' is " << reply5 << "'" << endl;
RequestChannel chan2(reply5, RequestChannel::CLIENT_SIDE);
string reply6 = chan2.send_request("data John Doe");
cout << "Reply to request 'data John Doe' is '" << reply6 << "'" << endl;
string reply7 = chan2.send_request("quit");
cout << "Reply to request 'quit' is '" << reply7 << "'" << endl;
string reply4 = chan.send_request("quit");
cout << "Reply to request 'quit' is '" << reply4 << "'" << endl;
}else{
execve("dataserver", argv, argv);
}
usleep(1000000);
}
2015-11-06 11:30:46 -06:00
/*
void* Worker_Thread();
void* Req_Thread();
void*
*/