public void DatagramRecvHandler(ref SelectControl control, Socket sock, Buf safeBuffer) { int bytesReceived = sock.ReceiveFrom(safeBuffer.array, ref from); if (bytesReceived <= 0) { if (bytesReceived < 0) { throw new InvalidOperationException(String.Format("ReceiveFrom on UDP socket returned {0}", bytesReceived)); } return; // TODO: how to handle neg } String clientString = "?"; try { clientString = from.ToString(); } catch (Exception) { } UInt32 parametersOffset; RpcMessage callMessage = new RpcMessage(safeBuffer.array, 0, (uint)bytesReceived, out parametersOffset); if (callMessage.messageType != RpcMessageType.Call) { throw new InvalidOperationException(String.Format("Received an Rpc reply from '{0}' but only expecting Rpc calls", clientString)); } if (!ProgramHeaderSupported(callMessage.call.programHeader)) { new RpcMessage(callMessage.transmissionID, new RpcReply(RpcVerifier.None, RpcAcceptStatus.ProgramUnavailable)).SendUdp(from, sock, safeBuffer, null); return; } ISerializer replyParameters; RpcReply reply = Call(clientString, callMessage.call, safeBuffer.array, parametersOffset, (uint)bytesReceived, out replyParameters); if (reply != null) { new RpcMessage(callMessage.transmissionID, reply).SendUdp(from, sock, safeBuffer, replyParameters); } }
public T CallBlockingTcp <T>(UInt32 procedureNumber, ISerializer requestSerializer, IInstanceSerializer <T> responseSerializer, Buf buffer) { UInt32 transmissionID = nextTransactionID++; RpcMessage callMessage = new RpcMessage(transmissionID, new RpcCall(programHeader, procedureNumber, credentials, verifier)); callMessage.SendTcp(socket, buffer, requestSerializer); UInt32 contentOffset, contentOffsetLimit; RpcMessage replyMessage = new RpcMessage(socket, buffer, out contentOffset, out contentOffsetLimit); if (replyMessage.messageType != RpcMessageType.Reply) { throw new InvalidOperationException(String.Format("Received an Rpc call from '{0}' but expected an rpc reply", socket.RemoteEndPoint)); } if (replyMessage.transmissionID != transmissionID) { throw new InvalidOperationException(String.Format("Expected reply with transmission id {0} but got {1}", transmissionID, replyMessage.transmissionID)); } RpcReply reply = replyMessage.reply; RpcCallFailedException.VerifySuccessfulReply(callMessage.call, reply); T instance; UInt32 offset = responseSerializer.Deserialize(buffer.array, contentOffset, contentOffsetLimit, out instance); if (offset != contentOffsetLimit) { StringBuilder dataBuidler = new StringBuilder(); throw new InvalidOperationException(String.Format("Deserialization of rpc message '{0}' as the following '{1}' resulted in an offset of {2}, but the record had {3} bytes", DataStringBuilder.DataString(reply, dataBuidler), DataStringBuilder.DataString(responseSerializer, instance, dataBuidler), offset, contentOffsetLimit)); } return(instance); }
public void HandleTcpRecord(String clientString, Socket socket, Byte[] record, UInt32 recordOffset, UInt32 recordOffsetLimit) { UInt32 parametersOffset; RpcMessage callMessage = new RpcMessage(record, recordOffset, recordOffsetLimit, out parametersOffset); if (callMessage.messageType != RpcMessageType.Call) { throw new InvalidOperationException(String.Format("Received an Rpc reply from '{0}' but only expecting Rpc calls", clientString)); } if (!ProgramHeaderSupported(callMessage.call.programHeader)) { new RpcMessage(callMessage.transmissionID, new RpcReply(RpcVerifier.None, RpcAcceptStatus.ProgramUnavailable)).SendTcp(socket, sendBuffer, null); } ISerializer replyParameters; RpcReply reply = Call(clientString, callMessage.call, record, parametersOffset, recordOffsetLimit, out replyParameters); if (reply != null) { new RpcMessage(callMessage.transmissionID, reply).SendTcp(socket, sendBuffer, replyParameters); } }
private static String CheckForFailureInReply(RpcCall call, RpcReply reply) { if (reply.status != RpcReplyStatus.Accepted) { return(DataStringBuilder.DataString(reply.rejectedReply, new StringBuilder())); } RpcAcceptedReply acceptedReply = reply.acceptedReply; if (acceptedReply.status == RpcAcceptStatus.Success) { return(null); } if (acceptedReply.status == RpcAcceptStatus.ProgramMismatch) { return(String.Format("ProgramMismatch: {0}", DataStringBuilder.DataString(acceptedReply.mismatchInfo, new StringBuilder()))); } else { return(acceptedReply.status.ToString()); } }
public RpcCallFailedException(RpcCall call, RpcReply reply) : this(call, FailureReason(call, reply)) { }