我想知道为什么普通TCP套接字中的写函数通常需要花费很多时间而不是SSL_write函数剂量(我假设SSL_write需要很长时间,因为数据在传输时会被加密,并且会在另一个对等端解密。 以下是我测量时间的方法:
1- TCP功能:
char ack[17] ;
read(sock, ack , 17); // I will not start sending untill I get a message of ready from the other peer
printf("%s\n " , ack);
timeval beginingTime, endingTime;
double elapsedTime;
gettimeofday(&beginingTime, NULL);
TCP_Sending(sock , size); // here is the call to the sending function , it is pretty the same as ssl function however we use write function to write in the socket
gettimeofday(&endingTime, NULL);
// compute and print the elapsed time in millisec
elapsedTime = (endingTime.tv_sec - beginingTime.tv_sec) * 1000.0; // sec to ms
elapsedTime += (endingTime.tv_usec - beginingTime.tv_usec) / 1000.0; // us to ms
printf("========= TCP Sending %.4f ms =================\n", elapsedTime);
2- SSL / TCP(除非使用SSL_read和SSL_write
,否则在TCP中通常是相同的char ack[17] ;
SSL_read(ssl, ack , 17);
printf("%s\n " , ack);
timeval beginingTime, endingTime;
double elapsedTime;
gettimeofday(&beginingTime, NULL);
SSL_Sending(ssl , size) ; // here is the function for sending data , it is the same as TCP however SSL_write is used instead of read write as in TCP .
gettimeofday(&endingTime, NULL);
// compute and print the elapsed time in millisec
elapsedTime = (beginingTime.tv_sec - endingTime.tv_sec) * 1000.0; // sec to ms
elapsedTime += (endingTime.tv_usec - beginingTime.tv_usec) / 1000.0; // us to ms
printf("========= SSL Sending %.4f ms =================\n", elapsedTime);
SSL中使用的加密是AES,我应该考虑哪些因素,并且有更好的方法来测量这两个函数。
谢谢你提前。