int closeAndDestroyMessageQueue(MessageQueue* messageQueue) { if (closeMessageQueue(messageQueue) == -1) return -1; if (destroyMessageQueue(messageQueue) == -1) return -1; return 0; }
int main(int argc, char *argv[]){ //Variables struct timeval startThread, endThread, startCipher, endCipher; //connectServer(argc, argv); char key[] = {"pAatOAgJqpdy7CECQbRojYLqy11O2W38nJm+Sfcz94QrNAH3EXhKFxx4t0FsjfiadGDlHkdLMG8jvgjG5jlNI72gkODO9IroRk+vy151xeBQoout9ZQ6wZktuqibySxKxGy7g0RcgfW6D7vnpV9bNfsxtOZDirJOhgQWErOq+GKYze25B9g0gheVEumbBpgz376VwJoHPZcFRVQw6lOc/EAaozgS1Uwh1/Zs1ThagZC4EP85ATVPfFJ45xNUAD1LsLqGjSOc1Y7MBU7EINwXDrDJIeKeyn+txKu0EoJ9QAgZyXqK4gOeUyZ1br1NMZ222Cgx+Q5unZA6qq8zUrHsi024wldyLJL0uqHpbHn6k3IrNrNcw45BLKBbsHf4JICaPIr825XeQbOw4tjk+VrNUS9eSCeErUIF7iNxryaW2H67EXKds2R7pGMh+JlogxUUMbJ5THV5HcV2rSPLugeCWDW8MACwW2Q3d6E2t1/v4recq3IohzX4rBoDTz4Px91wCajdgPdJpVwP82Cyv210fqI4KBZidEgtqEzJbbh7fQvGogS4IMtD7IkXPhcctk2QgBMXYYN1BebHuaP9PxREPCi1hwa87mBD2lF2YXGzyVSuRPL8GXYOOWS2m5HxerxAMZ4lIQC3FB2J4R+iVGhCXs5S6XihWadbfa2XyM5hF56O3kZNFG0UITbd0/cClVtfA7PDNEgg2pZNjVoNvwuR+/85b0YhDnlX6xawNBdO6xBUuRSs5oHvmd2aTTphlxlnjAlXnfgW9Oo0ACq5YbDgo+npCkcE4xEyO19Pf92YORUbbk4j+RJHcCuDqC0cdNDN5HGSTWvJn2KbzPpdg3UAcrLc7jd4usrTuiJ7QVu6uXT6FOl2h7hMGEy/1kol4v5KChHq6iQ5/jkQV2049c4kN03BLceIXkyXs+y5hyVlmx/QBNYa3etsAiw58yMVyojsB0AWgVnUkT00IY3nw2UIgaj5ENZtcZz/yhRNJOwDQwG4d0n2IHZYmwgD47wXW20g1o3avaThsshBMiI6dMmcogpb2R8gtCkuGvkjwIkCedcR/8cjGAA+wcVaOU9EndKUqT56uB4hcSQ96N63n1w07D1h6AK/CuELXE5wNtgPzQkgi83r+6qrY/rFeeO0dZAUUlR01Pyw15oGw7nmRBMBR2lak1Cjsi84I9K4JyW4t/LEuIvc122FB7YNCg9mRbTVMnUi3vWWcvVNur6/WQBtQllSdQ9Moo/mfYHA0TIyf9DBWBHtaJoWP7KvVfAgvjYyMU90ijiLDrASY8580Q1g3j6LioLEaXijfGst3Rp+c7K2gTk+V1KBZEEphGXQgFrJClZwoz/zohtn53xEooCME2cDEVaDvBf2B9Wch1BaOFJIcJdJ8JrheUM3l6eUBuUtoy5XNHb9oJsWfZ+azAOBU3mOEcXw7ZxoCNack1M/6atZOYkNUO9/zSnN/moVrYfqs+hcdUUJkZ4zk3tKdRVmFpohfW2dDF5+GhPZxlLDkogfSkQYZ5De6gNkwUi8qI3T0IaHjKs8tYOJU3+hlMSLSfUTwKn4JEx+V7FUiAUP0xI1Cxh5ySRQQoJqOA9eNj85"}; int messageCipher = 1; int rc = createMessageQueue("cipher", messageCipher); gettimeofday(&startThread, NULL); gettimeofday(&startCipher, NULL); if(rc != 0){ printf("Problem creating message queue"); return 1; } FILE *fp; fp = fopen("teste.txt", "r"); // Starts thread cipher side /** threadParameters dataThread; dataThread.fileName = "cipher"; dataThread.fileOut = "cipher.txt"; dataThread.eof = 0; int type = 3; createThread(&dataThread, type); **/ //Message struct message msg; char plaintext; RC4 params; int result, countTable = 0, count = 0; rc4Initializer(¶ms, key); while( ( plaintext = fgetc(fp) ) != EOF ){ rc4CipherAlgorithm(¶ms, plaintext); } msg.eof = 1; writeMessageToQueue(msg, count); fclose(fp); gettimeofday(&endCipher, NULL); //printf("Waiting thread ends\n"); //do{ // usleep(100); //}while(dataThread.eof == 0); destroyMessageQueue(); gettimeofday(&endThread, NULL); int threadx_ms = startThread.tv_sec*1000 + startThread.tv_usec/1000; int thready_ms = endThread.tv_sec*1000 + endThread.tv_usec/1000; int diffThread = thready_ms - threadx_ms; int cipherx_ms = startCipher.tv_sec*1000 + startCipher.tv_usec/1000; int ciphery_ms = endCipher.tv_sec*1000 + endCipher.tv_usec/1000; int diffCipher = ciphery_ms - cipherx_ms; printf("Execution with thread: %d\n",diffThread); printf("Execution without thread: %d\n", diffCipher); }