public void HandleEdgeSend(Edge from, ICopyable p) {
TcpEdge sender = (TcpEdge) from;
try {
bool flushed = true;
lock( sender ) {
//Try to fill up the buffer:
sender.WriteToBuffer(p);
//Okay, we loaded the whole packet into the TcpEdge's buffer
//now it is time to try to flush the buffer:
flushed = sender.Flush();
}
if( !flushed ) {
/*
* We should remember to try again when the socket is
* writable
*/
ActionQueue.Enqueue(new SendWaitAction(sender.Socket));
}
}
catch(EdgeException ex) {
if( false == ex.IsTransient ) {
//Go ahead and forget about this socket.
RequestClose(from);
ActionQueue.Enqueue(new CloseAction(sender, null));
}
//Rethrow the exception
throw;
}
catch(Exception x) {
//Assume any other error is transient:
throw new EdgeException(true, String.Format("Could not send on: {0}", from), x);
}
}
}