Example #1
0
bool SendClientData::Call(bool status)
/////////////////////////////////////////////////////////////////////////////
// Call sending data to the client after an event occurs
/////////////////////////////////////////////////////////////////////////////
{
    debug("SendClientData:Call count=%ld buf.count=%lld\n", count, buf.count);

    // If no longer mounted, then exit
    if (Mnt->State != MOUNTED) 
        return Error("Mountpoint disappeared\n");
    
    // Keep writing until we are caught up or we can't write any more
    ssize_t size, actual;
    while (count < buf.count) {

         // If we are too far behind, then quit
         if (count+TooFarBehind < buf.count)
             return Error("Client is falling behind\n");

        // Write as much data as we can, up to end of buffer
        size_t start = count % buf.BufSize;
        size = min<size_t>(buf.count-count, buf.BufSize-start);
        if (conn->Write(buf.Buffer+start, size, actual) != OK)
            return Error("Problems writing to client\n");

        // update the number of bytes sent to client
        if (actual != -1)
            count += actual;

    // End "keep writing until ... we can't write any more"
        if (actual != size)
            break;
    }


    // CASE: we have sent all the data to client. Wait for more.
    if (count == buf.count)
        return WaitForBuf();
    
    // CASE: the client connection is closed.  Terminate the session.
    else if (actual == -1)
        return Error("Client has closed connection\n");

    // CASE: client is busy. Send more when we can.
    else 
        return WaitForWrite(conn.get(), 10000);
}
Example #2
0
bool Writer::Call(bool status)
{
	// Problems encountered, probably timed out
	if (status != OK)
		return Switch(callback, Error("Writer: timed out\n"));

	// If we got bad write, let the callback know.
	ssize_t actual;
	if (conn->Write(buf, size, actual) != OK || actual == -1)
		return Switch(callback, Error("Writer: can't write\n"));

	// Make note of the new data
	buf += actual; size -= actual;

	// Write more data if need be
	if (size > 0)
		return WaitForWrite(conn.get(), timeout);

	// We are done. Invoke the callback
	return Switch(callback, OK);
}
Example #3
0
bool FSocketRaw::WaitForReadWrite( int WaitTime )
{
	return WaitForRead( WaitTime ) || WaitForWrite(WaitTime);
}