Dynamic Arrays and recv()
Hello everyone. I'm trying to write a socket class for fun and I'm just wondering what the best solution to my problem would be...
Basically I'm trying to write the socket classes Read() function, but i want the user to be able to specify how many bytes to read (which will be parsed the recv()'s len parameter). So, to make it efficient, I want to dynamically allocate memory for an array the same size as the user specifies to read.
The problem is (I'm assuming) since its dynamically allocated (therefore the memory is allocated at run-time) I cannot compile it because the compiler says "Undeclared Identifier", etc.
Here's my code snippet:
Thank you for any help you can provide :)
char * Socket::Read(int sockfd, int len)
// Default read and buffer length/size if
// user does not specify read amount.
int bufSize = 2048;
char * buf = new char[len+1];
char * buf = new char[bufSize];
recv(this->sockfd, buf, bufSize, 0);
recv(this->sockfd, buf, len, 0);
recv(sockfd, buf, bufSize, 0);
recv(sockfd, buf, len, 0);