Merge pull request #223 from ddyner/SocketReceiveBufferSize
Add socket ReceiveBufferSize settings to public property
This commit is contained in:
commit
35b66da0ae
|
@ -6,6 +6,9 @@ using System;
|
||||||
|
|
||||||
namespace AsterNET.IO
|
namespace AsterNET.IO
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Socket connection to asterisk.
|
||||||
|
/// </summary>
|
||||||
public class SocketConnection
|
public class SocketConnection
|
||||||
{
|
{
|
||||||
private TcpClient tcpClient;
|
private TcpClient tcpClient;
|
||||||
|
@ -23,21 +26,29 @@ namespace AsterNET.IO
|
||||||
/// <param name="port">client port</param>
|
/// <param name="port">client port</param>
|
||||||
/// <param name="encoding">encoding</param>
|
/// <param name="encoding">encoding</param>
|
||||||
public SocketConnection(string host, int port, Encoding encoding)
|
public SocketConnection(string host, int port, Encoding encoding)
|
||||||
|
:this(new TcpClient(host, port), encoding)
|
||||||
{
|
{
|
||||||
initial = true;
|
|
||||||
this.encoding = encoding;
|
|
||||||
this.tcpClient = new TcpClient(host, port);
|
|
||||||
this.networkStream = this.tcpClient.GetStream();
|
|
||||||
this.reader = new StreamReader(this.networkStream, encoding);
|
|
||||||
this.writer = new BinaryWriter(this.networkStream, encoding);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Consructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="host">client host</param>
|
||||||
|
/// <param name="port">client port</param>
|
||||||
|
/// <param name="encoding">encoding</param>
|
||||||
|
/// <param name="receiveBufferSize">size of the receive buffer.</param>
|
||||||
|
public SocketConnection(string host, int port,int receiveBufferSize, Encoding encoding)
|
||||||
|
: this (new TcpClient(host, port) {ReceiveBufferSize = receiveBufferSize }, encoding)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor - SocketConnection(socket)
|
#region Constructor - SocketConnection(socket)
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor
|
/// Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="socket">TCP client from Listener</param>
|
/// <param name="tcpClient">TCP client from Listener</param>
|
||||||
/// <param name="encoding">encoding</param>
|
/// <param name="encoding">encoding</param>
|
||||||
internal SocketConnection(TcpClient tcpClient, Encoding encoding)
|
internal SocketConnection(TcpClient tcpClient, Encoding encoding)
|
||||||
{
|
{
|
||||||
|
|
|
@ -653,14 +653,14 @@ namespace AsterNET.Manager
|
||||||
/// <param name="username">the username to use for login</param>
|
/// <param name="username">the username to use for login</param>
|
||||||
/// <param name="password">the password to use for login</param>
|
/// <param name="password">the password to use for login</param>
|
||||||
/// <param name="socketEncoding">text encoding to asterisk input/output stream</param>
|
/// <param name="socketEncoding">text encoding to asterisk input/output stream</param>
|
||||||
public ManagerConnection(string hostname, int port, string username, string password, Encoding encoding)
|
public ManagerConnection(string hostname, int port, string username, string password, Encoding socketEncoding)
|
||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.socketEncoding = encoding;
|
this.socketEncoding = socketEncoding;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -855,15 +855,36 @@ namespace AsterNET.Manager
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SocketEncoding
|
#region Socket Settings
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Socket Encoding - default ASCII
|
/// Socket Encoding - default ASCII
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Attention!
|
||||||
|
/// <para>
|
||||||
|
/// The value of this property must be set before establishing a connection with the Asterisk.
|
||||||
|
/// Changing the property doesn't do anything while you are already connected.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
public Encoding SocketEncoding
|
public Encoding SocketEncoding
|
||||||
{
|
{
|
||||||
get { return socketEncoding; }
|
get { return socketEncoding; }
|
||||||
set { socketEncoding = value; }
|
set { socketEncoding = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Socket Receive Buffer Size
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// Attention!
|
||||||
|
/// <para>
|
||||||
|
/// The value of this property must be set before establishing a connection with the Asterisk.
|
||||||
|
/// Changing the property doesn't do anything while you are already connected.
|
||||||
|
/// </para>
|
||||||
|
/// </remarks>
|
||||||
|
public int SocketReceiveBufferSize { get; set;}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Version
|
#region Version
|
||||||
|
@ -1075,7 +1096,10 @@ namespace AsterNET.Manager
|
||||||
#endif
|
#endif
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mrSocket = new SocketConnection(hostname, port, socketEncoding);
|
if (SocketReceiveBufferSize>0)
|
||||||
|
mrSocket = new SocketConnection(hostname, port, SocketReceiveBufferSize, socketEncoding);
|
||||||
|
else
|
||||||
|
mrSocket = new SocketConnection(hostname, port, socketEncoding);
|
||||||
result = mrSocket.IsConnected;
|
result = mrSocket.IsConnected;
|
||||||
}
|
}
|
||||||
#if LOGGER
|
#if LOGGER
|
||||||
|
@ -1083,8 +1107,8 @@ namespace AsterNET.Manager
|
||||||
{
|
{
|
||||||
logger.Info("Connect - Exception : {0}", ex.Message);
|
logger.Info("Connect - Exception : {0}", ex.Message);
|
||||||
#else
|
#else
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue