本文整理汇总了C#中HttpConnection.Close方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConnection.Close方法的具体用法?C# HttpConnection.Close怎么用?C# HttpConnection.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpConnection
的用法示例。
在下文中一共展示了HttpConnection.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResponse
/// <summary>
/// Connects to the server specified by the endpoint, sends the request and waits for a response.
/// </summary>
/// <param name="ep">The address:port of the server</param>
/// <param name="request">The request to send</param>
/// <param name="exception">Any exception that is throw or encountered during the request/response session with the server</param>
/// <param name="verbose">A flag that indicates the connection's verbosity level, true for more messages</param>
/// <returns></returns>
public static HttpResponse GetResponse(
IPEndPoint ep,
HttpRequest request,
out Exception exception,
bool verbose,
EventHandler<HttpMessageProgressEventArgs> onSendProgress,
EventHandler<HttpMessageProgressEventArgs> onRecvProgress,
object stateObject)
{
#region Params Validation
if (ep == null)
throw new ArgumentNullException("ep");
if (request == null)
throw new ArgumentNullException("request");
exception = null;
#endregion
// define a connection for this request/response session
HttpConnection connection = null;
try
{
// create a connection to the remote end point
connection = new HttpConnection(ep, false, verbose, HttpOptions.SendTimeout, HttpOptions.RecvTimeout);
// return a response from the server
return HttpRequest.GetResponse(connection, request, out exception, onSendProgress, onRecvProgress, stateObject);
}
catch (ThreadAbortException)
{
}
catch(Exception ex)
{
//Debug.WriteLine(ex);
exception = ex;
}
finally
{
// always try and close the connect up afterwards
if (connection != null)
connection.Close();
}
return null;
}
示例2: processAccepted
private static void processAccepted (Socket socket, EndPointListener listener)
{
HttpConnection conn = null;
try {
conn = new HttpConnection (socket, listener);
lock (listener._unregisteredSync)
listener._unregistered[conn] = conn;
conn.BeginReadRequest ();
}
catch {
if (conn != null) {
conn.Close (true);
return;
}
socket.Close ();
}
}
示例3: onAccept
private static void onAccept (object sender, EventArgs e)
{
var args = (SocketAsyncEventArgs) e;
var listener = (EndPointListener) args.UserToken;
Socket accepted = null;
if (args.SocketError == SocketError.Success) {
accepted = args.AcceptSocket;
args.AcceptSocket = null;
}
try {
listener._socket.AcceptAsync (args);
}
catch {
if (accepted != null)
accepted.Close ();
return;
}
if (accepted == null)
return;
HttpConnection conn = null;
try {
conn = new HttpConnection (accepted, listener);
lock (((ICollection) listener._unregistered).SyncRoot)
listener._unregistered [conn] = conn;
conn.BeginReadRequest ();
}
catch {
if (conn != null) {
conn.Close (true);
return;
}
accepted.Close ();
}
}