-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFS.c
More file actions
817 lines (662 loc) · 21.5 KB
/
FS.c
File metadata and controls
817 lines (662 loc) · 21.5 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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
//File System
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <ftw.h>
#include "libs/helper.h"
#include "libs/data.h"
#define SIZE 128
#define REPLY_SIZE 512
/*The program implementing the File Server (FS) should be invoked using the command:
./FS [-q FSport] [-n ASIP] [-p ASport] [-v],
where:
FSport is the well-known TCP port where the FS server accepts requests.
This is an optional argument and, if omitted, assumes the value 59000+GN,
where GN is the number of the group.
ASIP this is the IP address of the machine where the authentication
server (AS) runs. This is an optional argument. If this argument is omitted, the
AS should be running on the same machine.
ASport this is the well-known TCP port where the AS server accepts
requests. This is an optional argument. If omitted, it assumes the value
58000+GN, where GN is the group number.*/
/*---------------------------------------------
Structs
-----------------------------------------------*/
/*---------------------------------------------
Global variables
-----------------------------------------------*/
//Comands and their replies
char listCommand[] = "LST";
char listReply[] = "RLS";
char retrieveCommand[] = "RTV";
char retrieveReply[] = "RRT";
char uploadCommand[] = "UPL";
char uploadReply[] = "RUP";
char deleteCommand[] = "DEL";
char deleteReply[] = "RDL";
char removeCommand[] = "REM";
char removeReply[] = "RRM";
char okReply[] = "OK";
char errorReply[] = "ERR";
char errorNotOKReply[] = "NOK";
char errorInvalidTIDReply[] = "INV";
char errorEOFReply[] = "EOF";
//Control variables
int verboseMode = 0;
int maxAmountFiles = 15;
//Other global variables
Sock* clientConnectionsSocket;
Map* myMap;
char* fsport;
char* asip;
char* asport;
/*---------------------------------------------
Methods
-----------------------------------------------*/
char* getReplyForCommand(char command[]) {
if(isCommand(listCommand, command)) {
return listReply;
}
else if(isCommand(retrieveCommand, command)) {
return retrieveReply;
}
else if(isCommand(uploadCommand, command)) {
return uploadReply;
}
else if(isCommand(deleteCommand, command)) {
return deleteReply;
}
else if(isCommand(removeCommand, command)) {
return removeReply;
}
else {
return errorReply;
}
}
char getCharForCommand(char command[]) {
if(isCommand(listCommand, command)) {
return 'L';
}
else if(isCommand(retrieveCommand, command)) {
return 'R';
}
else if(isCommand(uploadCommand, command)) {
return 'U';
}
else if(isCommand(deleteCommand, command)) {
return 'D';
}
else if(isCommand(removeCommand, command)) {
return 'X';
}
else {
return '\0';
}
}
/**
* Replies to the given reply socket the replyCommand followed by the reply and a '\n' at the end.
* If replySize = -1, the reply size is calculated via strlen(). If the reply is suposed to
* contain arbitrairy data, then its size must be specified in replySize
*/
void reply(char replyCommand[], char reply[], Sock* replySocket, int replySize) {
int i = 0, j = 0;
int replyLength = replySize == -1 ? strlen(reply) : replySize;
char actualReply[COMMAND_LENGTH + 10 + replyLength];
//Copying the reply command to the actual reply
for(; i < COMMAND_LENGTH; i++) {
actualReply[i] = replyCommand[i];
}
actualReply[i] = ' ';
i++;
//Copying the rest of the reply to the actual reply
for(; j < replyLength; j++) {
actualReply[i] = reply[j];
i++;
}
actualReply[i] = '\n';
actualReply[i + 1] = '\0';
if(sendMessage(replySocket, actualReply, i + 1) == -1) {
//Error
printf("Unable to reply: ");
}
else {
//printf("Replying: ");
}
/*for(j = 0; j <= i; j++) {
printf("%c", actualReply[j]);
}*/
}
/**
* Vallidates the given UID and TID, by sending a message to the AS.
* Returns true if it's valid and false otherwise
*/
int validate(char* UID, char* TID, char* args, char* commandBeggining) {
Sock* asSocket = newUDPClient(asip, asport);
if(asSocket == NULL) {
printf("Unable to created Socket to communicate with the AS\n");
return 0;
}
char buffer[32];
char replyBuffer[SIZE];
char treatedReplyBuffers[5][32];
//Deleting trash from the treatedReplyBuffers
for(int i = 0; i < 5; i++) {
for(int j = 0; j < 32; j++) {
treatedReplyBuffers[i][j] = '\0';
}
}
sprintf(buffer, "VLD %s %s\n", UID, TID);
if(sendMessage(asSocket, buffer, strlen(buffer)) == -1) {
printf("Unable to send message to the AS: %s\n", buffer);
closeSocket(asSocket);
return 0;
}
int replySize = receiveMessageUDPWithTimeout(asSocket, replyBuffer, SIZE, 1);
for (int i = 0; i < 5 && replySize < 0; i++) {
printf("Retransmiting\n");
sendMessage(asSocket, buffer, strlen(buffer));
replySize = receiveMessageUDPWithTimeout(asSocket, replyBuffer, SIZE, 1);
}
if (replySize < 0) {
printf("Failed to receive message from AS\n");
closeSocket(asSocket);
return 0;
}
//Deleting the '\n'
replyBuffer[replySize - 1] = '\0';
if(verboseMode) {
printf("Received message from AS: %s\nIP: %s, Port: %s\n", replyBuffer, asip, asport);
}
sscanf(replyBuffer, "%s %s %s %s %s", treatedReplyBuffers[0], treatedReplyBuffers[1], treatedReplyBuffers[2], treatedReplyBuffers[3], treatedReplyBuffers[4]);
closeSocket(asSocket);
//Reply format: CNF UID TID Fop [Fname]
if(strcmp(treatedReplyBuffers[0], "CNF") != 0) {
//The reply command is wrong or it's an ERR
return 0;
}
else if(strcmp(treatedReplyBuffers[1], UID) != 0) {
//UID different than the one received
return 0;
}
else if(strcmp(treatedReplyBuffers[2], TID) != 0) {
//TID different than the one received
return 0;
}
else if(treatedReplyBuffers[3][0] != getCharForCommand(commandBeggining)) {
//The operation letter received from the AS is different than the command that wants to be executed
return 0;
}
if(treatedReplyBuffers[4][0] != '\0') {
//AS replied with a File name. As such, it will be checked if it matches with the Fname in args
char fname[FNAME_LENGTH + 1];
//Copying the Fname in args
for(int i = 0; i < FNAME_LENGTH; i++) {
if(args[i] == '\n' || args[i] == '\0' || args[i] == ' ') {
fname[i] = '\0';
break;
}
else {
fname[i] = args[i];
}
}
return strcmp(fname, treatedReplyBuffers[4]) == 0;
}
return 1;
}
int dirExists(char UID[]) {
char directoryPath[SIZE];
sprintf(directoryPath, "%s/%s", pathname, UID);
DIR* dir = opendir(directoryPath);
if (dir) {
/* Directory exists. */
closedir(dir);
return 1;
} else if (errno == ENOENT) {
/* Directory does not exist. */
return 0;
} else {
/* opendir() failed for some other reason. */
return 0;
}
}
void checkDirExists_IfNotCreate(char UID[]) {
char directoryPath[SIZE];
sprintf(directoryPath, "%s/%s", pathname, UID);
if(!dirExists(UID)) {
mkdir(directoryPath, 0777);
}
}
//Dealing with commands
void list(char* args, Sock* replySocket, char UID[]) {
DIR *directory;
struct dirent *dir;
char buffer[REPLY_SIZE];
char* bufferPointer = buffer;
char replyBuffer[REPLY_SIZE];
char filePath[REPLY_SIZE];
int amountFiles = 0;
struct stat fileStats;
char directoryName[SIZE];
sprintf(directoryName, "%s/%s", pathname, UID);
directory = opendir(directoryName);
buffer[0] = '\0';
if(directory != NULL) {
while((dir = readdir(directory)) != NULL) {
//Getting the file path
sprintf(filePath, "%s/%s/%s", pathname, UID, dir->d_name);
if(strcmp(dir->d_name, "..") == 0 || strcmp(dir->d_name, ".") == 0) {
continue;
}
//Getting the file statistics
if(stat(filePath, &fileStats)) {
//Something bad happened
reply(listReply, errorReply, replySocket, -1);
return;
}
//Adding the file name and its size to the buffer
bufferPointer += sprintf(bufferPointer, " %s %ld", dir->d_name, fileStats.st_size);
amountFiles++;
}
closedir(directory);
bufferPointer[0] = '\0';
if(amountFiles == 0) {
//There are no files
reply(listReply, errorEOFReply, replySocket, -1);
}
else {
sprintf(replyBuffer, "%d%s", amountFiles, buffer);
reply(listReply, replyBuffer, replySocket, -1);
}
}
else {
printf("Trying to open %s\n", directoryName);
reply(listReply, errorReply, replySocket, -1);
}
}
void retrieve(char* args, Sock* replySocket, char UID[]) {
char fileName[FNAME_LENGTH + 1];
char filePath[SIZE];
int i, j;
struct stat fileStats;
int fileSize;
int sizeRead;
int replySize;
char fileSizeStr[20];
int fileSizeStrSize;
char ok[] = "OK ";
int bytesLeft;
int totalBytes;
char *buffer, *replyBuffer;
if(!dirExists(UID)) {
reply(retrieveReply, errorNotOKReply, replySocket, -1);
return;
}
//Getting the file name from args
for(i = 0; i < FNAME_LENGTH; i++) {
if(args[i] == '\n') {
break;
}
else if(args[i] == '\0') {
//Args were parsed wrongly. Args should end with a \n
reply(retrieveReply, errorReply, replySocket, -1);
return;
}
else {
fileName[i] = args[i];
}
}
fileName[i] = '\0';
sprintf(filePath, "%s/%s/%s", pathname, UID, fileName);
FILE* file = fopen(filePath, "rb");
if(file == NULL) {
if(errno == ENOENT) {
//File does not exist
reply(retrieveReply, errorEOFReply, replySocket, -1);
return;
}
else {
reply(retrieveReply, errorReply, replySocket, -1);
return;
}
}
stat(filePath, &fileStats);
fileSize = fileStats.st_size;
sprintf(fileSizeStr, "%d", fileSize);
fileSizeStrSize = strlen(fileSizeStr);
replySize = fileSize + 4 + 3 + fileSizeStrSize + 6;
/*File size + 4 chars for "RRT "", + 3 chars for "OK " + size of the number as a string + 3 chars for " ", another for '\n'
and '\0', and 3 more for safety*/
buffer = (char*) malloc(sizeof(char) * (fileSize + 1));
replyBuffer = (char*) malloc(sizeof(char) * (replySize + 1));
sizeRead = fread(buffer, sizeof(char), fileSize, file);
for(i = 0; i < COMMAND_LENGTH; i++) {
replyBuffer[i] = retrieveReply[i];
}
replyBuffer[i] = ' ';
i++;
//Copying "OK " to the reply buffer
for(j = 0; j < 3; j++) {
replyBuffer[i] = ok[j];
i++;
}
//Copying the file size to the reply buffer
for(j = 0; j < fileSizeStrSize; j++) {
replyBuffer[i] = fileSizeStr[j];
i++;
}
replyBuffer[i] = ' ';
i++;
//Copying the file data to the rest of the buffer
for(j = 0; j < sizeRead; j++) {
replyBuffer[i] = buffer[j];
i++;
}
fclose(file);
replyBuffer[i] = '\n';
i++;
replyBuffer[i] = '\0';
i++;
bytesLeft = i;
totalBytes = i;
//Sending everything in a single batch (receiver is prepared to receive small batches due to TCP division)
if(sendMessage(replySocket, replyBuffer, i) == -1) {
printf("Unable to send message containing file data\n");
}
}
void upload(char* args, Sock* replySocket, char UID[]) {
char fileName[FNAME_LENGTH + 1];
int fileSize;
char filePath[SIZE];
DIR *directory;
struct dirent *dir;
int amountFiles = 0;
FILE* file;
char directoryName[SIZE];
char buffer[REPLY_SIZE];
int readingSize;
sprintf(directoryName, "%s/%s", pathname, UID);
if(sscanf(args, "%s %d\n", fileName, &fileSize) != 2) {
//Something went wrong
reply(uploadReply, errorReply, replySocket, -1);
return;
}
//Getting the file path
sprintf(filePath, "%s/%s/%s", pathname, UID, fileName);
checkDirExists_IfNotCreate(UID);
directory = opendir(directoryName);
//Counting the amount of files that exist
if(directory != NULL) {
while((dir = readdir(directory)) != NULL) {
if(strcmp(dir->d_name, "..") == 0 || strcmp(dir->d_name, ".") == 0) {
continue;
}
amountFiles++;
}
closedir(directory);
}
if(amountFiles >= maxAmountFiles) {
//User has reached the maximum amount of files
reply(uploadReply, "FULL", replySocket, -1);
return;
}
if(access(filePath, F_OK) == 0) {
//File already exists
reply(uploadReply, "DUP", replySocket, -1);
return;
}
file = fopen(filePath, "w");
//Reading batches of data from the socket
while(fileSize > 0) {
if(fileSize > REPLY_SIZE) {
readingSize = REPLY_SIZE;
}
else {
readingSize = fileSize;
}
if(receiveMessage(replySocket, buffer, readingSize) == -1) {
printf("Unable to receive data\n");
fclose(file);
return;
}
fileSize -= readingSize;
fwrite(buffer, sizeof(char), readingSize, file);
}
fclose(file);
reply(uploadReply, okReply, replySocket, -1);
}
void deleteC(char* args, Sock* replySocket, char UID[]) {
char fileName[FNAME_LENGTH + 1];
char filePath[SIZE];
int fileNameSize;
strcpy(fileName, args);
fileNameSize = strlen(fileName);
if(fileName[fileNameSize - 1] != '\n') {
//The args do not end with a '\n'
reply(deleteReply, errorReply, replySocket, -1);
}
fileName[fileNameSize - 1] = '\0'; //Replacing the \n with \0
if(!dirExists(UID)) {
reply(deleteReply, errorNotOKReply, replySocket, -1);
return;
}
sprintf(filePath, "%s/%s/%s", pathname, UID, fileName);
//Opening the file to check if it exists
FILE* file = fopen(filePath, "rb");
if(file == NULL) {
if(errno == ENOENT) {
//File does not exist
reply(deleteReply, errorEOFReply, replySocket, -1);
return;
}
else {
reply(deleteReply, errorReply, replySocket, -1);
return;
}
}
fclose(file);
remove(filePath);
reply(deleteReply, okReply, replySocket, -1);
}
void removeC(char* args, Sock* replySocket, char UID[]) {
DIR *directory;
struct dirent *dir;
char filePath[REPLY_SIZE];
char directoryPath[SIZE];
sprintf(directoryPath, "%s/%s", pathname, UID);
directory = opendir(directoryPath);
//Iterating over all files to remove them
if(directory != NULL) {
while((dir = readdir(directory)) != NULL) {
//Getting the file path
sprintf(filePath, "%s/%s", directoryPath, dir->d_name);
if(strcmp(dir->d_name, "..") == 0 || strcmp(dir->d_name, ".") == 0) {
continue;
}
remove(filePath);
}
closedir(directory);
rmdir(directoryPath);
}
else {
reply(removeReply, errorNotOKReply, replySocket, -1);
return;
}
reply(removeReply, okReply, replySocket, -1);
}
//--------Dealing with commands-------
void *newClientDealingThread(void* arg) {
Sock* tcpUserSocket = (Sock*) arg;
char buffer[SIZE];
char* args = buffer;
char UID[UID_LENGTH + 1], TID[TID_LENGTH + 1];
int i;
char* replyFirstWord;
int accumulatedBytes = 0;
//Reading the command
accumulatedBytes += receiveMessageUntilChar(tcpUserSocket, buffer, COMMAND_LENGTH + 1, ' ');
if(isCommand(uploadCommand, buffer)) {
//The upload command must be read differently due to the arbitrary size of Data
accumulatedBytes += receiveMessageUntilChar(tcpUserSocket, buffer + accumulatedBytes, UID_LENGTH + 1, ' ');
accumulatedBytes += receiveMessageUntilChar(tcpUserSocket, buffer + accumulatedBytes, TID_LENGTH + 1, ' ');
accumulatedBytes += receiveMessageUntilChar(tcpUserSocket, buffer + accumulatedBytes, FNAME_LENGTH + 1, ' ');
accumulatedBytes += receiveMessageUntilChar(tcpUserSocket, buffer + accumulatedBytes, SIZE, ' '); //Reading Fsize
buffer[accumulatedBytes] = '\n';
accumulatedBytes++;
}
else {
//Reading a normal command with a slightly known size
accumulatedBytes += receiveMessageUntilChar(tcpUserSocket, buffer + accumulatedBytes, SIZE, '\n');
}
if(accumulatedBytes < 0) {
//Something went wrong
printf("Unable to receive message from a user\n");
closeSocket(tcpUserSocket);
return NULL;
}
buffer[accumulatedBytes] = '\0';
if (verboseMode) {
char *ip = getHostIp(tcpUserSocket);
char *port = getHostPort(tcpUserSocket);
printf("Received from User: %sIP: %s, Port: %s\n", buffer, ip, port);
free(ip);
free(port);
}
if(pointToArgs(&args)) {
//The command has args
for(i = 0; i < UID_LENGTH; i++) {
UID[i] = args[i];
}
UID[i] = '\0';
//Making args point to the next arg
if(pointToArgs(&args)) {
for(i = 0; i < TID_LENGTH; i++) {
TID[i] = args[i];
}
TID[i] = '\0';
//Making args point to the next arg. It's no longer relevant if there are more args or not
pointToArgs(&args);
if(validate(UID, TID, args, buffer)) {
if(isCommand(listCommand, buffer)) {
list(args, tcpUserSocket, UID);
}
else if(isCommand(retrieveCommand, buffer)) {
retrieve(args, tcpUserSocket, UID);
}
else if(isCommand(uploadCommand, buffer)) {
upload(args, tcpUserSocket, UID);
}
else if(isCommand(deleteCommand, buffer)) {
deleteC(args, tcpUserSocket, UID);
}
else if(isCommand(removeCommand, buffer)) {
removeC(args, tcpUserSocket, UID);
}
else {
if(verboseMode) {
printf("Received unknown command from \n");
}
}
}
else {
//UID TID Invalid
reply(getReplyForCommand(buffer), errorInvalidTIDReply, tcpUserSocket, -1);
}
}
else {
//args does not contain any more args
reply(getReplyForCommand(buffer), errorReply, tcpUserSocket, -1);
}
}
else {
//There are no more args
reply(getReplyForCommand(buffer), errorReply, tcpUserSocket, -1);
}
closeSocket(tcpUserSocket);
}
//-------------Other methods---------
void end() {
//Deleting the map
delete(myMap);
closeSocket(clientConnectionsSocket);
}
/*---------------------------------------------
Main
-----------------------------------------------*/
int main(int argc, char *argv[]) {
Sock* socket;
pthread_t threadID;
//Reading the input into a Map
myMap = newMap();
//Reading everything
for (int i = 1; i < argc; i++) {
if(strcmp(argv[i], "-v") == 0) {
verboseMode = 1;
continue;
}
put(myMap, argv[i], argv[i+1]);
i++;
}
//Checking the input in the map
fsport = get(myMap, "-q");
asip = get(myMap, "-n");
asport = get(myMap, "-p");
if(fsport == NULL) {
//Setting default fsport
fsport = FS_PORT;
}
else {
if(atoi(fsport) == 0) {
//The given port is not a number
fprintf(stderr, "Given FSport is not a number: %s", fsport);
return 0;
}
}
if(asip == NULL) {
//Setting default asip
asip = "localhost";
}
if(asport == NULL) {
//Setting default asport
asport = AS_PORT;
}
else {
if(atoi(asport) == 0) {
//The given port is not a number
fprintf(stderr, "Given ASport is not a number: %s", asport);
return 0;
}
}
//Creating a Directory for the file system, if it doesn't exist
mkdir(pathname, 0777);
//Creating socket that listens for new connections
clientConnectionsSocket = newTCPServer(fsport);
if(clientConnectionsSocket == NULL) {
printf("Unable to create socket that receives connections\n");
return 1;
}
//Tests
/*
list("", NULL, "1");
upload("Fich_Test3 10 abc\0de\tfgh\n", NULL, "1");
retrieve("Fich_Test3\n", NULL, "1");
deleteC("Fich_Test3\n", NULL, "1");
removeC("", NULL, "1");
*/
//Listening for connections
while(TRUE) {
//Waiting for a client connection
socket = acquire(clientConnectionsSocket);
if(socket == NULL) {
printf("Unable to create Socket to deal with a client\n");
continue;
}
pthread_create(&threadID, (pthread_attr_t *) NULL, &newClientDealingThread, (void*) socket);
}
end();
return 0;
}