Modified recvAllNB() to return an empty string (instead of NULL) if there is nothing to read

master
Aadhavan Srinivasan 10 months ago
parent 06f44d385d
commit 54f7dbe7ee

@ -49,7 +49,8 @@ public:
/* Method to receive data sent to the 'other_socket' socket */
char* recvAll();
/* Non-blocking receive method - calls the method above after polling for data */
/* Non-blocking receive method - calls the method above after polling for data. Returns
an empty string if there is nothing to read. */
char* recvAllNB();
/* Returns socket identifier */

@ -81,7 +81,7 @@ This function also needs more testing for TCP. */
char* Sock::recvAll() {
int num_bytes_received = 0;
int total_bytes_received = 0;
char* buffer = (char *)malloc(100);
char* buffer = (char *)malloc(150);
bool has_been_read = false;
if (this->protocol == ES_UDP) {
@ -117,7 +117,8 @@ char* Sock::recvAll() {
return buffer;
}
/* Non-blocking recv call - Uses 'select' to poll for data from the FD. */
/* Non-blocking recv call - Uses 'select' to poll for data from the FD. Returns an empty string if there
is nothing to read. */
char* Sock::recvAllNB() {
struct timeval tv;
fd_set readfs;
@ -131,7 +132,7 @@ char* Sock::recvAllNB() {
if (FD_ISSET(this->sock_fd, &readfs)) {
return Sock::recvAll();
} else {
return NULL;
return (char *)"";
}
}

Loading…
Cancel
Save