-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_lib.cpp
More file actions
631 lines (574 loc) · 19.8 KB
/
client_lib.cpp
File metadata and controls
631 lines (574 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
#include "commons.h"
#include "client.h"
#include "key_store_client.h"
#include "utils.h"
server_connections::server_connections(struct Server_info* servers, uint32_t number_of_servers){
string key;
/* Create connection with all servers */
for (uint32_t i = 0; i < number_of_servers; i++) {
key = string(servers[i].ip) + ":" + to_string(servers[i].port);
#ifdef DEBUG_FLAG
cout<<"\n\n"<<__func__ <<": Creating new connection with file server :"<< key <<endl;
#endif
connections[key] = new key_store_client(grpc::CreateChannel(key, grpc::InsecureChannelCredentials()));
}
}
server_connections::~server_connections(){
/* Delete all the connection */
map<string, key_store_client*>::iterator it = connections.begin();
while(it!=connections.end()){
delete it->second;
it++;
}
}
struct Client* client_instance(const uint32_t id, const char* protocol, const struct Server_info* servers, uint32_t number_of_servers)
{
struct Client* cl = new Client;
cl->id = id;
string proto = string(protocol);
memcpy(cl->protocol, protocol, proto.length());
cl->number_of_servers = number_of_servers;
cl->servers = new struct Server_info[number_of_servers];
//cout<<(sizeof(struct Server_info)*number_of_servers) << " " << number_of_servers <<endl;
memcpy(cl->servers, servers, sizeof(struct Server_info)*number_of_servers);
client_wrapper *cl_w = new struct client_wrapper_i;
cl_w->cl = cl ;
cl_w->conn = new server_connections(cl->servers, number_of_servers);
/*Append the client information to client list */
client_list_mutex.lock();
client_list[id] = cl_w;
client_list_mutex.unlock();
return cl;
}
void
make_req_payload (KeyStoreRequest *payload,
request_t *req) {
/*Fill protocol*/
if (req->protocol == CM) {
payload->set_protocol(KeyStoreRequest::CM);
}
if (req->protocol == ABD) {
payload->set_protocol(KeyStoreRequest::ABD);
}
if (req->protocol == MP) {
payload->set_protocol(KeyStoreRequest::MP);
}
if (req->type == WRITE_QUERY) {
payload->set_type(KeyStoreRequest::WRITE_QUERY);
/* NO tag*/
/* No clientId */
payload->set_key(req->key,req->key_sz);
payload->set_keysz(req->key_sz);
/* NO value */
payload->set_valuesz(0);
}
if (req->type == WRITE) {
payload->set_type(KeyStoreRequest::WRITE);
payload->set_integer(req->tag.integer);
payload->set_clientid(req->tag.client_id);
payload->set_key(req->key,req->key_sz);
payload->set_keysz(req->key_sz);
payload->set_value(req->value,req->value_sz);
payload->set_valuesz(req->value_sz);
}
if (req->type == READ_QUERY) {
payload->set_type(KeyStoreRequest::READ_QUERY);
payload->set_key(req->key,req->key_sz);
payload->set_keysz(req->key_sz);
payload->set_valuesz(0);
}
// Not needed
if (req->type == READ) {
payload->set_type(KeyStoreRequest::READ);
payload->set_key(req->key,req->key_sz);
payload->set_keysz(req->key_sz);
payload->set_valuesz(0);
}
}
void
print_request(request_t *req) {
cout<< "Printing request" <<endl;
cout<<" Type :"<< getstring_c_request_type(req->type)<<endl;
cout<<" protocol :"<<req->protocol<<endl;
cout<<" Integer :"<<req->tag.integer<<endl;
cout<<" Client_id:"<<req->tag.client_id<<endl;
cout<<" key :"<<req->key<<endl;
cout<<" key_sz :"<<req->key_sz<<endl;
if(req->value_sz)
cout<<" value :"<<req->value<<endl;
cout<<" value_sz:"<<req->value_sz<<endl;
}
response_t*
extract_response_from_payload(KeyStoreResponse *Response, KeyStoreRequest req, bool overide_key ) {
response_t *c_response = new response_t;
c_response->code = get_c_return_code(Response->code());
if (Response->protocol() == KeyStoreResponse::CM) {
c_response->protocol = CM;
}
if (Response->protocol() == KeyStoreResponse::ABD) {
c_response->protocol = ABD;
c_response->tag.integer = Response->integer();
c_response->tag.client_id = Response->clientid();
}
if (Response->protocol() == KeyStoreResponse::MP) {
c_response->protocol = MP;
}
if (overide_key) {
// #ifdef DEBUG_FLAG
// cout<<" "<<__func__<<"Response key size= "<<Response->key().size();
// cout<<" "<<__func__<<"Response key received = "<<Response->key();
// #endif
c_response->key = new char[Response->keysz()+1];
memset(c_response->key, 0, Response->keysz()+1);
memcpy(c_response->key, Response->key().c_str(), Response->keysz());
// #ifdef DEBUG_FLAG
// cout<<" "<<__func__<<"Response after mem_cpy = "<<c_response->key;
// #endif
} else {
// #ifdef DEBUG_FLAG
// cout<<" "<<__func__<<"\tResponse key received = "<<req.key()<<endl;
// #endif
c_response->key = new char[req.keysz()+1];
memset(c_response->key, 0, req.keysz()+1);
memcpy(c_response->key, req.key().c_str(), req.keysz());
// #ifdef DEBUG_FLAG
// cout<<" "<<__func__<<"\tResponse after mem_cpy = "<<c_response->key<<endl;
// #endif
}
c_response->key_sz = Response->keysz();
if(Response->valuesz()) {
// #ifdef DEBUG_FLAG
// cout<<" "<<__func__<<"Response value size= "<<Response->value().size()<<endl;
// cout<<" "<<__func__<<"Response value received = "<<Response->value()<<endl;
// #endif
c_response->value = new char[Response->valuesz()+1];
memset(c_response->value, 0, Response->valuesz()+1);
memcpy(c_response->value, Response->value().c_str(), Response->valuesz());
// #ifdef DEBUG_FLAG
// cout<<__func__<<"Response value after mem_cpy = "<<c_response->value<<endl;
// #endif
} else {
#ifdef DEBUG_FLAG
cout<<" Value from server is Invalid/Not_applicable"<<endl;
#endif
}
c_response->value_sz = Response->valuesz();
return c_response;
}
void
send_to_server_handler(key_store_client* connection_stub,
promise<response_t*>&& keyStoreResponsePromise, KeyStoreRequest *req){
//send_to_server_handler(key_store_client* connection_stub, KeyStoreRequest *req){
KeyStoreResponse Response;
ClientContext Context;
response_t *c_response = NULL; // This will be returned back in Promise
#ifdef DEBUG_FLAG
std::cout << "Sending message to server "<<endl;
#endif
Status status = connection_stub->stub_->KeyStoreRequestHandler(&Context, *req, &Response);
if (status.ok()) {
c_response = extract_response_from_payload(&Response, *req, 0);
#ifdef DEBUG_FLAG
std::cout << "Got the response from server, returning now"<<endl;
#endif
keyStoreResponsePromise.set_value(c_response);
} else {
std::cout << status.error_code() << ": " << status.error_message()
<< std::endl;
return ;
}
return;
}
/* Agnostic to type of message, return the response */
void send_message_to_all_server(promise<vector<response_t*>>& prom, client_wrapper *cw, request_t *c_req) {
KeyStoreRequest ReqPayload;
int number_of_servers = cw->conn->connections.size();
int majority = (number_of_servers/2+1), num_resp_collected = 0;
std::chrono::system_clock::time_point span ;
vector<response_t*> vec_resp ;
vector<promise<response_t*>> vec_prom; // Stores Promises
vector<future<response_t*>> vec_fut; // Stores future
vector<future<void>> vec_temp_fut; // Stores async return future, we dont use it but asyn
// become sync if we dont store it.
make_req_payload(&ReqPayload, c_req);
#ifdef DEBUG_FLAG
print_request(c_req);
#endif
int i = 0;
for (auto it = cw->conn->connections.begin(); it!=cw->conn->connections.end(); it++) {
promise<response_t*> pm = promise<response_t*>();
future<response_t*> fu = pm.get_future();
vec_prom.emplace_back(std::move(pm));
vec_fut.emplace_back(std::move(fu));
vec_temp_fut.emplace_back(std::async(std::launch::async, send_to_server_handler,
it->second, std::move(vec_prom[i]), &ReqPayload));
// vec_temp_fut.emplace_back(std::async(std::launch::async, send_to_server_handler,
// it->second, ref(vec_prom[i]), &ReqPayload));
i++;
}
#ifdef DEBUG_FLAG
cout << "Majority is: " <<majority<<endl;
#endif
while(1) {
for (auto &future:vec_fut){
span = std::chrono::system_clock::now() + std::chrono::milliseconds(10);
//cout<<count++ <<endl;
if (future.valid() && future.wait_until(span)== std::future_status::ready) {
vec_resp.push_back(future.get());
num_resp_collected++;
}
}
if(num_resp_collected >= majority){
#ifdef DEBUG_FLAG
cout<<"Got the majority:"<< num_resp_collected<< ", returning now"<<endl;
#endif
prom.set_value(vec_resp);
break;
}
}
// caller will clean the "vec_resp"
// vec_prom, vec_fut and vec_temp_fut are local variable, will be freed
}
void delete_response_t(response_t *resp) {
if(resp->key_sz) delete resp->key;
if(resp->value_sz)delete resp->value;
delete resp;
}
void delete_request_t(request_t *rep) {
if(rep->key_sz) delete rep->key;
if(rep->value_sz)delete rep->value;
delete rep;
}
response_t* find_majority_tag (vector<response_t*> &vec_c_resp) {
response_t* max_resp = vec_c_resp[0];
for(auto it = vec_c_resp.begin(); it!= vec_c_resp.end();) {
if ((*it)->tag.integer >= max_resp->tag.integer) {
if ((*it)->tag.integer == max_resp->tag.integer) {
if((*it)->tag.client_id > max_resp->tag.client_id){
delete_response_t (max_resp);
max_resp = *it;
vec_c_resp.erase(it);
continue;
} else {
vec_c_resp.erase(it);
continue;
}
}
}
delete_response_t(*it);
vec_c_resp.erase(it);
}
return max_resp;
}
/* Agnostic to type of message, return the response */
void send_message_to_one_server(promise<response_t*>& prom, client_wrapper *cw, request_t *c_req) {
KeyStoreRequest ReqPayload;
int number_of_servers = cw->conn->connections.size();
std::chrono::system_clock::time_point span ;
promise<response_t*> pm;
future<response_t*> fu;
response_t* c_resp ;
vector<future<void>> vec_temp_fut; // Stores async return future, we dont use it but asyn
// become sync if we dont store it.
make_req_payload(&ReqPayload, c_req);
#ifdef DEBUG_FLAG
print_request(c_req);
#endif
uint32_t i = 0;
for (auto it = cw->conn->connections.begin(); it!=cw->conn->connections.end(); it++) {
if( c_req->tag.client_id %number_of_servers == i) {
#ifdef DEBUG_FLAG
cout<<"CM/MP: Sending to server = "<< c_req->tag.client_id%number_of_servers<<endl;
#endif
pm = promise<response_t*>();
fu = pm.get_future();
vec_temp_fut.emplace_back(std::async(std::launch::async, send_to_server_handler,
it->second, std::move(pm), &ReqPayload));
}
i++;
}
if (fu.valid()) {
c_resp = fu.get();
}
#ifdef DEBUG_FLAG
cout<<"CM/MP: Got the Response returning now"<<endl;
#endif
prom.set_value(c_resp);
// caller will clean the "vec_resp"
// vec_prom, vec_fut and vec_temp_fut are local variable, will be freed
}
int put(const struct Client* c, const char* key, uint32_t key_size,
const char* value, uint32_t value_size){
vector<response_t*> vec_c_resp ;
response_t *max_resp = NULL;
#ifdef DEBUG_FLAG
cout<<"key_size" <<key_size<<endl;
#endif
/* Based on the client ID, fetch the server connection and call the function */
if (string(c->protocol) == "CM") {
response_t *c_resp = NULL;
#ifdef DEBUG_FLAG
cout<< "CM protocol: Put request"<<endl;
#endif
request_t *c_req = new request_t;
c_req->type = WRITE;
c_req->protocol = CM;
c_req->tag.integer = 0; // Since query will fetch the integer
c_req->tag.client_id = c->id;
c_req->key = new char[key_size+1];
memset(c_req->key, 0, key_size+1);
memcpy(c_req->key, key, key_size);
c_req->key_sz = key_size;
c_req->value = new char[value_size+1];
memset(c_req->value, 0, value_size+1);
memcpy(c_req->value, value, value_size);
c_req->value_sz = value_size;
promise<response_t*> pm = promise<response_t*>();
future <response_t*> fu = pm.get_future();
thread t1(send_message_to_one_server, ref(pm), client_list[c->id], c_req);
t1.detach();
c_resp = fu.get();
delete_response_t(c_resp);
delete_request_t (c_req);
return 0;
} else if (string(c->protocol) == "ABD"){
/* ABD algorithm case */
#ifdef DEBUG_FLAG
cout<< "ABD protocol: Put request"<<endl;
#endif
/* Send the write_query */
request_t *c_req = new request_t;
c_req->type = WRITE_QUERY;
c_req->protocol = ABD;
c_req->tag.integer = 0; // Since query will fetch the integer
c_req->tag.client_id = c->id;
c_req->key = new char[key_size+1];
memset(c_req->key,0,key_size+1);
memcpy(c_req->key, key, key_size);
c_req->key_sz = key_size;
c_req->value_sz = 0;
promise<vector<response_t*>> pm = promise<vector<response_t*>>();
future <vector<response_t*>> fu = pm.get_future();
thread t1(send_message_to_all_server, ref(pm), client_list[c->id], c_req);
t1.detach();
vec_c_resp = fu.get();
max_resp = find_majority_tag(vec_c_resp);
/*Send the write request*/
c_req->type = WRITE;
c_req->tag.integer = max_resp->tag.integer + 1;
c_req->value = new char[value_size+1];
memset(c_req->value, 0,value_size+1);
memcpy(c_req->value, value, value_size);
c_req->value_sz = value_size;
delete_response_t(max_resp);
promise<vector<response_t*>> pm1 = promise<vector<response_t*>>();
future <vector<response_t*>> fu1 = pm1.get_future();
thread t2(send_message_to_all_server, ref(pm1), client_list[c->id], c_req);
t2.detach();
vec_c_resp = fu1.get();
max_resp = find_majority_tag(vec_c_resp);
delete_response_t(max_resp);
delete_request_t (c_req);
return 0;
} else {
response_t *c_resp = NULL;
#ifdef DEBUG_FLAG
cout<< "MP protocol: Put request"<<endl;
#endif
request_t *c_req = new request_t;
c_req->type = WRITE;
c_req->protocol = MP;
c_req->tag.integer = 0;
c_req->tag.client_id = c->id;
c_req->key = new char[key_size+1];
memset(c_req->key, 0, key_size+1);
memcpy(c_req->key, key, key_size);
c_req->key_sz = key_size;
c_req->value = new char[value_size+1];
memset(c_req->value, 0, value_size+1);
memcpy(c_req->value, value, value_size);
c_req->value_sz = value_size;
promise<response_t*> pm = promise<response_t*>();
future <response_t*> fu = pm.get_future();
thread t1(send_message_to_one_server, ref(pm), client_list[c->id], c_req);
t1.detach();
c_resp = fu.get();
delete_response_t(c_resp);
delete_request_t (c_req);
return 0;
}
return 1;
}
int get(const struct Client* c, const char* key, uint32_t key_size,
char** value, uint32_t *value_size){
vector<response_t*> vec_c_resp;
response_t *max_resp = NULL;
/* Based on the client ID, fetch the server connection and call the function */
if (string(c->protocol) == "CM") {
response_t *c_resp = NULL;
#ifdef DEBUG_FLAG
cout<< "CM protocol: Get request"<<endl;
#endif
request_t *c_req = new request_t;
c_req->type = READ;
c_req->protocol = CM;
c_req->tag.integer = 0; // Since query will fetch the integer
c_req->tag.client_id = c->id;
c_req->key = new char[key_size+1];
memset(c_req->key, 0, key_size+1);
memcpy(c_req->key, key, key_size);
c_req->key_sz = key_size;
c_req->value_sz = 0;
promise<response_t*> pm = promise<response_t*>();
future <response_t*> fu = pm.get_future();
thread t1(send_message_to_one_server, ref(pm), client_list[c->id], c_req);
t1.detach();
c_resp = fu.get();
*value = new char[c_resp->value_sz+1];
memcpy(*value, c_resp->value, c_resp->value_sz);
(*value)[c_resp->value_sz] = '\0';
*value_size = c_resp->value_sz;
#ifdef DEBUG_FLAG
cout <<"Returning following value in CM GET operation :" <<endl;
cout<<" Value:"<<*value <<endl;
cout<<" Size :"<<*value_size<<endl;
#endif
if (c_resp->value_sz == 0) {
*value = new char[1];
memset(*value, 0, 1);
*value_size = 0;
cout<< "Read was issued on non-existent key" <<endl;
return 0;
}
return 0;
} else if (string(c->protocol) == "ABD") {
/* ABD algorithm case */
#ifdef DEBUG_FLAG
cout<< "ABD protocol: Get request"<<endl;
#endif
/* Send the write_query */
request_t *c_req = new request_t;
c_req->type = READ_QUERY;
c_req->protocol = ABD;
c_req->tag.integer = 0; // Since query will fetch the integer
c_req->tag.client_id = c->id;
c_req->key = new char[key_size+1];
memset(c_req->key, 0, key_size+1);
memcpy(c_req->key, key, key_size);
c_req->key_sz = key_size;
c_req->value_sz = 0;
promise<vector<response_t*>> pm = promise<vector<response_t*>>();
future <vector<response_t*>> fu = pm.get_future();
thread t1(send_message_to_all_server, ref(pm), client_list[c->id], c_req);
t1.detach();
vec_c_resp = fu.get();
max_resp = find_majority_tag(vec_c_resp);
/*Send the write request*/
if (max_resp->value_sz) {
c_req->type = WRITE;
c_req->tag.integer = max_resp->tag.integer;
c_req->tag.client_id = max_resp->tag.client_id;
c_req->value = new char[max_resp->value_sz+1];
memset(c_req->value,0,max_resp->value_sz+1);
memcpy(c_req->value, max_resp->value, max_resp->value_sz);
c_req->value_sz = max_resp->value_sz;
delete_response_t(max_resp);
promise<vector<response_t*>> pm1 = promise<vector<response_t*>>();
future <vector<response_t*>> fu1 = pm1.get_future();
thread t2(send_message_to_all_server, ref(pm1), client_list[c->id], c_req);
t2.detach();
vec_c_resp = fu1.get();
max_resp = find_majority_tag(vec_c_resp);
delete_response_t(max_resp);
/* fill the result */
*value = new char[c_req->value_sz+1];
memcpy(*value, c_req->value, c_req->value_sz);
(*value)[c_req->value_sz] = '\0';
*value_size = c_req->value_sz;
#ifdef DEBUG_FLAG
cout <<"Returning following value in GET operation :" <<endl;
cout<<" Value:"<<*value <<endl;
cout<<" Size :"<<*value_size<<endl;
#endif
delete_request_t(c_req);
} else {
*value = new char[1];
memset(*value, 0, 1);
*value_size = 0;
cout<< "Read was issued on non-existent key" <<endl;
return 0;
}
return 0;
} else {
response_t *c_resp = NULL;
#ifdef DEBUG_FLAG
cout<< "MP protocol: Get request"<<endl;
#endif
request_t *c_req = new request_t;
c_req->type = READ;
c_req->protocol = MP;
c_req->tag.integer = 0;
c_req->tag.client_id = c->id;
c_req->key = new char[key_size+1];
memset(c_req->key, 0, key_size+1);
memcpy(c_req->key, key, key_size);
c_req->key_sz = key_size;
c_req->value_sz = 0;
promise<response_t*> pm = promise<response_t*>();
future <response_t*> fu = pm.get_future();
thread t1(send_message_to_one_server, ref(pm), client_list[c->id], c_req);
t1.detach();
c_resp = fu.get();
*value = new char[c_resp->value_sz+1];
memcpy(*value, c_resp->value, c_resp->value_sz);
(*value)[c_resp->value_sz] = '\0';
*value_size = c_resp->value_sz;
#ifdef DEBUG_FLAG
cout <<"Returning following value in MP GET operation :" <<endl;
cout<<" Value:"<<*value <<endl;
cout<<" Size :"<<*value_size<<endl;
#endif
if (c_resp->value_sz == 0) {
*value = new char[1];
memset(*value, 0, 1);
*value_size = 0;
cout<< "Read was issued on non-existent key" <<endl;
return 0;
}
return 0;
}
return -1;
}
int client_delete(struct Client* c)
{
/*Locking the client list before deleting it, may not be required but locking anyway for thread_safe*/
client_list_mutex.lock();
auto it = client_list.find(c->id);
if(it!=client_list.end()) {
int id = c->id;
#ifdef DEBUG_FLAG
cout<<"Number of clients before deletion" << client_list.size()<<endl;
cout<<"Deleting server connecitons"<<endl;
#endif
/* No need to free connection as it will be Freed in distructor of the object */
// for (auto it = (client_list[id])->conn->connections.begin(); it != (client_list[id])->conn->connections.end();it++ ) {
// cout<<"Deleteing server connection" <<endl;
// delete it->second;
// }
delete (client_list[id])->conn;
#ifdef DEBUG_FLAG
cout<<"Deleting server list"<<endl;
#endif
delete [] (client_list[id])->cl->servers;
#ifdef DEBUG_FLAG
cout<<"Deleting Client structure"<<endl;
#endif
delete (client_list[id])->cl;
client_list.erase(id);
#ifdef DEBUG_FLAG
cout<<"Number of clients after deletion" << client_list.size()<<endl;
#endif
client_list_mutex.unlock();
}
return 0;
}