PLS multiclient build
This commit is contained in:
parent
3937ec1db9
commit
8f2b453f74
2 changed files with 10 additions and 22 deletions
|
@ -26,7 +26,6 @@ int main( int argc, char * argv[] ) {
|
|||
for (int i = 0; i < buffers; i ++ ) {
|
||||
ringbuf[i] = new buffer;
|
||||
ringbuf[i]->data = (char*) malloc(size_per_buffer);
|
||||
ringbuf[i]->data[0] = i+'a';
|
||||
}
|
||||
for (int i = 0; i < buffers; i ++ ) { std::cout << "Buffer[" << i << "][0]: " << ringbuf[i]->data[0] << "\n"; }
|
||||
int connections = atoi(argv[3]);
|
||||
|
@ -53,14 +52,14 @@ int main( int argc, char * argv[] ) {
|
|||
|
||||
while(true) {
|
||||
loopcount ++;
|
||||
std::cout << "#" << loopcount << "\n";
|
||||
inp_amount = fread(&input,1,11,stdin);
|
||||
if (input[0] == 9) {
|
||||
std::cout << "9!!\n";
|
||||
open_connection = get_empty(connectionList,connections);
|
||||
if (open_connection != -1) {
|
||||
connectionList[open_connection]->connect( (SWUnixSocket *)listener.accept(&BError) );
|
||||
if (connectionList[open_connection]->is_connected()) {
|
||||
std::cout << "#" << loopcount << ": ";
|
||||
std::cout << "!!Client " << open_connection << " connected.!!\n";
|
||||
connectionList[open_connection]->send_msg(&header[0],13,NULL);
|
||||
}
|
||||
}
|
||||
|
@ -78,14 +77,14 @@ int main( int argc, char * argv[] ) {
|
|||
position_current ++;
|
||||
}
|
||||
ringbuf[current_buffer]->size = position_current;
|
||||
std::cout << "Total message read!\n";
|
||||
// std::cout << "Total message read!\n";
|
||||
for (int i = 0; i < connections; i++) {
|
||||
std::cout << "Checking connection " << i << "\n";
|
||||
if (connectionList[i]->is_connected()) {
|
||||
std::cout << "Connected...\n";
|
||||
// std::cout << "Client " << i << " connected, sending..\n";
|
||||
if ( connectionList[i]->myConnection->send(&ringbuf[current_buffer]->data[0], ringbuf[current_buffer]->size, &BError) == -1) {
|
||||
std::cout << " -1 :(\n";
|
||||
connectionList[i]->disconnect();
|
||||
std::cout << "#" << loopcount << ": ";
|
||||
std::cout << "!!Client " << i << " disconnected.!!\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,7 @@ void user::set_buffer(buffer * newBuffer) {
|
|||
sent = 0;
|
||||
}
|
||||
|
||||
int user::get_number() {
|
||||
return myBuffer->number;
|
||||
}
|
||||
int user::get_number() { return myBuffer->number; }
|
||||
|
||||
bool user::complete_send() {
|
||||
if (sent == myBuffer->size) { return true; }
|
||||
|
@ -31,17 +29,8 @@ void user::disconnect() {
|
|||
}
|
||||
}
|
||||
|
||||
void user::connect(SWUnixSocket * newConnection) {
|
||||
myConnection = newConnection;
|
||||
}
|
||||
void user::connect(SWUnixSocket * newConnection) { myConnection = newConnection; }
|
||||
|
||||
bool user::is_connected( ) {
|
||||
std::cout << " - Checking...:";
|
||||
if (myConnection) { std::cout << " true\n"; return true; }
|
||||
std::cout << " false\n";
|
||||
return false;
|
||||
}
|
||||
bool user::is_connected( ) { return myConnection; }
|
||||
|
||||
int user::send_msg(char * message, int length, SWBaseSocket::SWBaseError * BError) {
|
||||
return myConnection->send(message,length,BError);
|
||||
}
|
||||
int user::send_msg(char * message, int length, SWBaseSocket::SWBaseError * BError) { return myConnection->send(message,length,BError); }
|
||||
|
|
Loading…
Add table
Reference in a new issue