Created
July 22, 2019 15:30
-
-
Save surinoel/3cba3fab5b2b0b5af8f0dbe24405d289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int stream_send(int sock, void *buf, size_t buflen, int flag) | |
{ | |
int written = 0; | |
int ret; | |
while (written < buflen) { | |
ret = send(sock, (char *)buf + written, | |
buflen - written, flag); | |
if (ret == -1) { | |
return ret; | |
} | |
written += ret; | |
} | |
return 0; | |
} | |
int stream_recv(int sock, void *buf, size_t buflen, int flag) | |
{ | |
int written = 0; | |
int ret; | |
while (written < buflen) { | |
ret = recv(sock, (char *)buf + written, | |
buflen - written, flag); | |
if (ret == -1) { | |
return ret; | |
} | |
written += ret; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment