Question: What do these 2 functions do? Please go into detail, thank you int writeSock(int sock, char* buf, size_t len) { ssize_t byteswrote = 0; ssize_t
What do these 2 functions do? Please go into detail, thank you
int writeSock(int sock, char* buf, size_t len) { ssize_t byteswrote = 0; ssize_t ret = 0;
while (byteswrote < len) { ret = send(sock, buf + byteswrote, len - byteswrote, 0);
if (ret < 0) { return -1; }
if (ret == 0) { break; }
byteswrote += ret; }
return byteswrote; }
int readSock(int sock, char* buf, size_t len) { ssize_t ret = 0; ssize_t bytesread = 0;
while (bytesread < len) { ret = recv(sock, buf + bytesread, len - bytesread, 0);
if (ret == 0) { break; }
if (ret < 0) { return -1; }
bytesread += ret; }
return bytesread; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
