Skip to content

Commit

Permalink
update read write timeout value when timeout value is set
Browse files Browse the repository at this point in the history
  • Loading branch information
ElizabethOkerio committed Jun 12, 2020
1 parent 5464035 commit f7bd66b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 14 deletions.
34 changes: 30 additions & 4 deletions src/Microsoft.OData.Client/DataServiceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,11 @@ public class DataServiceContext
/// <summary>resolve typename from a type</summary>
private Func<string, Type> resolveType;

#if !PORTABLELIB // Timeout not available
/// <summary>time-out value in seconds, 0 for default</summary>
private int timeout;
#endif

/// <summary>read or write time-out value in seconds, 0 for default</summary>
private int readWriteTimeout;
/// <summary>whether to use post-tunneling for PUT/DELETE</summary>
private bool postTunneling;

Expand Down Expand Up @@ -480,7 +481,6 @@ public virtual Func<string, Type> ResolveType
set { this.resolveType = value; }
}

#if !PORTABLELIB // Timeout not available
/// <summary>Gets or sets the time-out option (in seconds) that is used for the underlying HTTP request to the data service.</summary>
/// <returns>An integer that indicates the time interval (in seconds) before time-out of a service request.</returns>
/// <remarks>
Expand All @@ -507,7 +507,33 @@ public virtual int Timeout
this.timeout = value;
}
}
#endif

/// <summary>Gets or sets the readwrite time-out option (in seconds) that is used for the underlying HTTP request to the data service.</summary>
/// <returns>An integer that indicates the time interval (in seconds) before readwritetime-out of a service request.</returns>
/// <remarks>
/// A value of 0 will use the default readwritetimeout of the underlying HTTP request.
/// This value must be set before executing any query or update operations against
/// the target data service for it to have effect on the on the request.
/// The value may be changed between requests to a data service and the new value
/// will be picked up by the next data service request.
/// </remarks>
public virtual int ReadWriteTimeout
{
get
{
return this.readWriteTimeout;
}

set
{
if (value < 0)
{
throw Error.ArgumentOutOfRange("ReadWriteTimeout");
}

this.readWriteTimeout = value;
}
}

/// <summary>Gets or sets a Boolean value that indicates whether to use post tunneling.</summary>
/// <returns>A Boolean value that indicates whether to use post tunneling.</returns>
Expand Down
11 changes: 9 additions & 2 deletions src/Microsoft.OData.Client/InternalODataRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public override ICredentials Credentials
set { throw new NotSupportedException(); }
}

#if !PORTABLELIB
/// <summary>
/// Gets or sets the timeout (in seconds) for this request.
/// </summary>
Expand All @@ -115,6 +114,15 @@ public override int Timeout
set { throw new NotSupportedException(); }
}

/// <summary>
/// Gets or sets the read and write timeout (in seconds) for this request.
/// </summary>
public override int ReadWriteTimeout
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}

/// <summary>
/// Gets or sets a value that indicates whether to send data in segments to the
/// Internet resource.
Expand All @@ -131,7 +139,6 @@ public override bool SendChunked
throw new NotImplementedException();
}
}
#endif

/// <summary>
/// internal headers dictionary
Expand Down
8 changes: 6 additions & 2 deletions src/Microsoft.OData.Client/ODataRequestMessageWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,16 @@ internal static ODataRequestMessageWrapper CreateRequestMessageWrapper(BuildingR
requestMessage.Credentials = requestInfo.Credentials;
}

#if !PORTABLELIB // Timeout not available
if (requestInfo.Timeout != 0)
{
requestMessage.Timeout = requestInfo.Timeout;

}

if (requestInfo.ReadWriteTimeout != 0)
{
requestMessage.ReadWriteTimeout = requestInfo.ReadWriteTimeout;
}
#endif

return new TopLevelRequestMessageWrapper(requestMessage, requestInfo, requestMessageArgs.Descriptor);
}
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.OData.Client/RequestInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,21 @@ internal System.Net.ICredentials Credentials
get { return this.Context.Credentials; }
}

#if !PORTABLELIB
/// <summary>
/// Get the timeout span in seconds to use for the underlying HTTP request to the data service.
/// </summary>
internal int Timeout
{
get { return this.Context.Timeout; }
}
#endif

/// <summary>
/// Get the read or write timeout span in seconds to use for the underlying HTTP request to the data service.
/// </summary>
internal int ReadWriteTimeout
{
get { return this.Context.ReadWriteTimeout; }
}

/// <summary>
/// Whether to use post-tunneling for PUT/DELETE.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ public abstract string Method
/// </summary>
public abstract ICredentials Credentials { get; set; }

#if !PORTABLELIB
/// <summary>
/// Gets or sets the timeout (in seconds) for this request.
/// </summary>
public abstract int Timeout { get; set; }
#endif

/// <summary>
/// Gets or sets the read and write timeout (in seconds) for this request.
/// </summary>
public abstract int ReadWriteTimeout { get; set; }

/// <summary>
/// Gets or sets a value that indicates whether to send data in segments to the
Expand Down
12 changes: 10 additions & 2 deletions src/Microsoft.OData.Client/Serialization/HttpWebRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ public override System.Net.ICredentials Credentials
set { this.httpRequest.Credentials = value; }
}

#if !PORTABLELIB
/// <summary>
/// Gets or sets the timeout (in seconds) for this request.
/// </summary>
Expand All @@ -187,6 +186,15 @@ public override int Timeout
set { this.httpRequest.Timeout = (int)Math.Min(Int32.MaxValue, new TimeSpan(0, 0, value).TotalMilliseconds); }
}

/// <summary>
/// Gets or sets the read and write timeout (in seconds) for this request.
/// </summary>
public override int ReadWriteTimeout
{
get { return this.httpRequest.ReadWriteTimeout; }
set { this.httpRequest.ReadWriteTimeout = (int)Math.Min(Int32.MaxValue, new TimeSpan(0, 0, value).TotalMilliseconds); }
}

/// <summary>
/// Gets or sets a value that indicates whether to send data in segments to the
/// Internet resource.
Expand All @@ -196,7 +204,7 @@ public override bool SendChunked
get { return this.httpRequest.SendChunked; }
set { this.httpRequest.SendChunked = value; }
}
#endif

#endregion

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ public override int Timeout
}
}

public override int ReadWriteTimeout
{
get
{
return (int)this.client.Timeout.TotalSeconds;
}
set
{
this.client.Timeout = new TimeSpan(0, 0, value);
}
}

/// <summary>
/// Gets or sets a value that indicates whether to send data in segments to the Internet resource.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public override int Timeout
throw new NotImplementedException();
}
}

public override int ReadWriteTimeout
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
}
}
#endif

public override string GetHeader(string headerName)
Expand Down

0 comments on commit f7bd66b

Please sign in to comment.