Because of specifications requirement, I'm not allowed to use recv() or similar functions to read from socket's fd. I was wondering how I would remake that function using read()?
I've attempted creating it with the following code
int recvFromFd(int connectionFd, char *buf, int size)
{
char c;
int i = 0;
for (read(connectionFd, &c, 1); i < size; i++)
{
buf[i] = c;
if (c == '\n' || read(connectionFd, &c, 1) == EOF)
break;
}
return i;
}
This code works to an extent, but often when when the sender send one message after another, the function read both of those message at the same time to the same buffer (appends).