public SendRequest ( IMessage msg, ITransportHeaders headers, Stream contentStream ) : void | ||
msg | IMessage | |
headers | ITransportHeaders | |
contentStream | Stream | |
return | void |
private TcpClientSocketHandler SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream) { long position = 0L; bool flag = true; bool canSeek = requestStream.CanSeek; if (canSeek) { position = requestStream.Position; } TcpClientSocketHandler socket = null; string machinePortAndSid = this._machineAndPort + (this._channel.IsSecured ? ("/" + this.GetSid()) : null); if (this.authSet && !this._channel.IsSecured) { throw new RemotingException(CoreChannel.GetResourceString("Remoting_Tcp_AuthenticationConfigClient")); } bool openNew = (this._channel.IsSecured && (this._securityUserName != null)) && (this._connectionGroupName == null); try { socket = (TcpClientSocketHandler)this.ClientSocketCache.GetSocket(machinePortAndSid, openNew); socket.SendRequest(msg, requestHeaders, requestStream); } catch (SocketException) { for (int i = 0; ((i < this._retryCount) && canSeek) && flag; i++) { try { requestStream.Position = position; socket = (TcpClientSocketHandler)this.ClientSocketCache.GetSocket(machinePortAndSid, openNew); socket.SendRequest(msg, requestHeaders, requestStream); flag = false; } catch (SocketException) { } } if (flag) { throw; } } requestStream.Close(); return(socket); }
} // Next private TcpClientSocketHandler SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream) { // If the stream is seekable, we can retry once on a failure to write. long initialPosition = 0; bool bCanSeek = requestStream.CanSeek; if (bCanSeek) { initialPosition = requestStream.Position; } TcpClientSocketHandler clientSocket = null; try { clientSocket = (TcpClientSocketHandler)ClientSocketCache.GetSocket(_machineAndPort); clientSocket.SendRequest(msg, requestHeaders, requestStream); } catch (SocketException) { // retry sending if possible if (bCanSeek) { // reset position... requestStream.Position = initialPosition; // ...and try again. clientSocket = (TcpClientSocketHandler) ClientSocketCache.GetSocket(_machineAndPort); clientSocket.SendRequest(msg, requestHeaders, requestStream); } } requestStream.Close(); return(clientSocket); } // SendRequestWithRetry
} // Next private TcpClientSocketHandler SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream) { // If the stream is seekable, we can retry once on a failure to write. long initialPosition = 0; bool sendException = true; bool bCanSeek = requestStream.CanSeek; if (bCanSeek) { initialPosition = requestStream.Position; } TcpClientSocketHandler clientSocket = null; // Add the sid string only if the channel is secure. String machinePortAndSid = _machineAndPort + (_channel.IsSecured ? "/" + GetSid() : null); // The authentication config entries are only valid if secure is true if (authSet && !_channel.IsSecured) { throw new RemotingException(CoreChannel.GetResourceString( "Remoting_Tcp_AuthenticationConfigClient")); } // If explicitUserName is set but connectionGroupName isnt we will need to authenticate on each call bool openNewAlways = (_channel.IsSecured) && (_securityUserName != null) && (_connectionGroupName == null); try { clientSocket = (TcpClientSocketHandler)ClientSocketCache.GetSocket(machinePortAndSid, openNewAlways); clientSocket.SendRequest(msg, requestHeaders, requestStream); } catch (SocketException) { // Retry sending if socketexception occured, stream is seekable, retrycount times for (int count = 0; (count < _retryCount) && (bCanSeek && sendException); count++) { // retry sending if possible try { // reset position... requestStream.Position = initialPosition; // ...and try again. clientSocket = (TcpClientSocketHandler) ClientSocketCache.GetSocket(machinePortAndSid, openNewAlways); clientSocket.SendRequest(msg, requestHeaders, requestStream); sendException = false; } catch (SocketException) { } } if (sendException) { throw; } } requestStream.Close(); return(clientSocket); } // SendRequestWithRetry