I'm not sure, but i think this is what you're looking for:
Code:
int ReceiveUntil(char *buf, int bufsize, const char *until, int timeout)
{
int n = 0;
int ai;
char c;
if (until != NULL && timeout > 0)
{
alarm(timeout);
alarmed = 0;
ai = 0;
while (!alarmed)
{
if (read(fdrd, &c, 1) < 0)
{
if (errno == EINTR) continue;
if (errno == EAGAIN) continue;
syslog(LOG_INFO, "Unspecified error while waiting for incoming data.");
break;
}
n=strlen(buf);
if(n<bufsize)
sprintf(buf+n, "%c", c);
else
break;
// Uncomment the next line to see buffer contents
cout << buf ;
}
if (alarmed)
syslog(LOG_INFO, "Timeout while waiting for incoming data.");
unalarm();
}
return n;
}