{
public partial class Socket : IDisposable
{
- private bool islistening;
- private bool useoverlappedIO;
- private const int SOCKET_CLOSED = 10004;
+ const int SOCKET_CLOSED_CODE = 10004;
+ const string TIMEOUT_EXCEPTION_MSG = "A connection attempt failed because the connected party did not properly respond" +
+ "after a period of time, or established connection failed because connected host has failed to respond";
- private static readonly string timeout_exc_msg = "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond";
+ /*
+ * These two fields are looked up by name by the runtime, don't change
+ * their name without also updating the runtime code.
+ */
+ static int ipv4_supported = -1;
+ static int ipv6_supported = -1;
+
+ /* true if we called Close_internal */
+ bool is_closed;
+
+ bool is_listening;
+ bool use_overlapped_io;
+
+ int linger_timeout;
+
+ /* the field "safe_handle" is looked up by name by the runtime */
+ SafeSocketHandle safe_handle;
+
+ AddressFamily address_family;
+ SocketType socket_type;
+ ProtocolType protocol_type;
+
+ /*
+ * This EndPoint is used when creating new endpoints. Because
+ * there are many types of EndPoints possible,
+ * seed_endpoint.Create(addr) is used for creating new ones.
+ * As such, this value is set on Bind, SentTo, ReceiveFrom,
+ * Connect, etc.
+ */
+ internal EndPoint seed_endpoint = null;
+
+ internal Queue readQ = new Queue (2);
+ internal Queue writeQ = new Queue (2);
+
+ internal bool is_blocking = true;
+ internal bool is_bound;
+
+ /* When true, the socket was connected at the time of the last IO operation */
+ internal bool is_connected;
+
+ internal bool is_disposed;
+ internal bool connect_in_progress;
static void AddSockets (List<Socket> sockets, IList list, string name)
{
continue;
}
- if (mode == 1 && currentList == checkWrite && !sock.connected) {
+ if (mode == 1 && currentList == checkWrite && !sock.is_connected) {
if ((int) sock.GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error) == 0)
- sock.connected = true;
+ sock.is_connected = true;
}
// Remove non-signaled sockets before the current one
socket_type=type;
protocol_type=proto;
- socket=sock;
- connected=true;
+ safe_handle = sock;
+ is_connected = true;
}
private void SocketDefaults ()
public Socket (SocketInformation socketInformation)
{
var options = socketInformation.Options;
- islistening = (options & SocketInformationOptions.Listening) != 0;
- connected = (options & SocketInformationOptions.Connected) != 0;
- blocking = (options & SocketInformationOptions.NonBlocking) == 0;
- useoverlappedIO = (options & SocketInformationOptions.UseOnlyOverlappedIO) != 0;
+ is_listening = (options & SocketInformationOptions.Listening) != 0;
+ is_connected = (options & SocketInformationOptions.Connected) != 0;
+ is_blocking = (options & SocketInformationOptions.NonBlocking) == 0;
+ use_overlapped_io = (options & SocketInformationOptions.UseOnlyOverlappedIO) != 0;
var result = Mono.DataConverter.Unpack ("iiiil", socketInformation.ProtocolInformation, 0);
address_family = (AddressFamily) (int) result [0];
socket_type = (SocketType) (int) result [1];
protocol_type = (ProtocolType) (int) result [2];
- isbound = (ProtocolType) (int) result [3] != 0;
- socket = new SafeSocketHandle ((IntPtr) (long) result [4], true);
+ is_bound = (ProtocolType) (int) result [3] != 0;
+ safe_handle = new SafeSocketHandle ((IntPtr) (long) result [4], true);
SocketDefaults ();
}
#endif
public int Available {
get {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int ret, error;
- ret = Available_internal(socket, out error);
+ ret = Available_internal (safe_handle, out error);
if (error != 0)
throw new SocketException (error);
public bool DontFragment {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return(dontfragment);
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
public bool EnableBroadcast {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return((int)(GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Broadcast)) != 0);
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
public bool ExclusiveAddressUse {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return((int)(GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse)) != 0);
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
- if (isbound) {
+ if (is_bound) {
throw new InvalidOperationException ("Bind has already been called for this socket");
}
public bool IsBound {
get {
- return(isbound);
+ return(is_bound);
}
}
public LingerOption LingerState {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return((LingerOption)GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger));
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
public bool MulticastLoopback {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return(multicastloopback);
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
[MonoTODO ("This doesn't do anything on Mono yet")]
public bool UseOnlyOverlappedIO {
get {
- return(useoverlappedIO);
+ return use_overlapped_io;
}
set {
- useoverlappedIO = value;
+ use_overlapped_io = value;
}
}
public IntPtr Handle {
get {
- return(socket.DangerousGetHandle ());
+ return safe_handle.DangerousGetHandle ();
}
}
// Wish: support non-IP endpoints.
public EndPoint LocalEndPoint {
get {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
/*
SocketAddress sa;
int error;
- sa=LocalEndPoint_internal(socket, (int) address_family, out error);
+ sa = LocalEndPoint_internal (safe_handle, (int) address_family, out error);
if (error != 0)
throw new SocketException (error);
public int SendTimeout {
get {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
return (int)GetSocketOption(
SocketOptionName.SendTimeout);
}
set {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (value < -1)
public int ReceiveTimeout {
get {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
return (int)GetSocketOption(
SocketOptionName.ReceiveTimeout);
}
set {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (value < -1)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (!IsBound)
throw new InvalidOperationException ("You must call the Bind method before performing this operation.");
- if (!islistening)
+ if (!is_listening)
throw new InvalidOperationException ("You must call the Listen method before performing this operation.");
if (e.BufferList != null)
throw new ArgumentException ("Multiple buffers cannot be used with this method.");
}
public Socket Accept() {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error = 0;
- var sock = Accept_internal(socket, out error, blocking);
+ var sock = Accept_internal(safe_handle, out error, is_blocking);
if (error != 0) {
- if (closed)
- error = SOCKET_CLOSED;
+ if (is_closed)
+ error = SOCKET_CLOSED_CODE;
throw new SocketException(error);
}
internal void Accept (Socket acceptSocket)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error = 0;
- var sock = Accept_internal (socket, out error, blocking);
+ var sock = Accept_internal (safe_handle, out error, is_blocking);
if (error != 0) {
- if (closed)
- error = SOCKET_CLOSED;
+ if (is_closed)
+ error = SOCKET_CLOSED_CODE;
throw new SocketException (error);
}
acceptSocket.address_family = this.AddressFamily;
acceptSocket.socket_type = this.SocketType;
acceptSocket.protocol_type = this.ProtocolType;
- acceptSocket.socket = sock;
- acceptSocket.connected = true;
+ acceptSocket.safe_handle = sock;
+ acceptSocket.is_connected = true;
acceptSocket.seed_endpoint = this.seed_endpoint;
acceptSocket.Blocking = this.Blocking;
public IAsyncResult BeginAccept(AsyncCallback callback, object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!isbound || !islistening)
+ if (!is_bound || !is_listening)
throw new InvalidOperationException ();
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Accept);
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (receiveSize < 0)
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (receiveSize < 0)
throw new ArgumentOutOfRangeException ("receiveSize", "receiveSize is less than zero");
if (acceptSocket != null) {
- if (acceptSocket.disposed && acceptSocket.closed)
+ if (acceptSocket.is_disposed && acceptSocket.is_closed)
throw new ObjectDisposedException (acceptSocket.GetType ().ToString ());
if (acceptSocket.IsBound)
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (address == null)
if (port <= 0 || port > 65535)
throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
- if (islistening)
+ if (is_listening)
throw new InvalidOperationException ();
IPEndPoint iep = new IPEndPoint (address, port);
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (host == null)
if (port <= 0 || port > 65535)
throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
- if (islistening)
+ if (is_listening)
throw new InvalidOperationException ();
return BeginConnect (Dns.GetHostAddresses (host), port, callback, state);
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Disconnect);
AsyncCallback callback,
object state) {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffers == null)
ref EndPoint remote_end,
AsyncCallback callback,
object state) {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
SocketFlags socketFlags, ref EndPoint remoteEP,
AsyncCallback callback, object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public IAsyncResult BeginSend (byte[] buffer, int offset, int size, SocketFlags socket_flags,
AsyncCallback callback, object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
CheckRange (buffer, offset, size);
- if (!connected)
+ if (!is_connected)
throw new SocketException ((int)SocketError.NotConnected);
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Send);
AsyncCallback callback,
object state)
{
- if (!connected) {
+ if (!is_connected) {
errorCode = SocketError.NotConnected;
throw new SocketException ((int)errorCode);
}
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffers == null)
throw new ArgumentNullException ("buffers");
- if (!connected)
+ if (!is_connected)
throw new SocketException ((int)SocketError.NotConnected);
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.SendGeneric);
AsyncCallback callback,
object state)
{
- if (!connected) {
+ if (!is_connected) {
errorCode = SocketError.NotConnected;
throw new SocketException ((int)errorCode);
}
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!connected)
+ if (!is_connected)
throw new NotSupportedException ();
if (!File.Exists (fileName))
AsyncCallback callback,
object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!connected)
+ if (!is_connected)
throw new NotSupportedException ();
if (!File.Exists (fileName))
EndPoint remote_end,
AsyncCallback callback,
object state) {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
}
public void Bind(EndPoint local_end) {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (local_end == null)
int error;
- Bind_internal(socket, local_end.Serialize(), out error);
+ Bind_internal (safe_handle, local_end.Serialize(), out error);
if (error != 0)
throw new SocketException (error);
if (error == 0)
- isbound = true;
+ is_bound = true;
seed_endpoint = local_end;
}
public void Connect (IPAddress[] addresses, int port)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (addresses == null)
this.AddressFamily != AddressFamily.InterNetworkV6)
throw new NotSupportedException ("This method is only valid for addresses in the InterNetwork or InterNetworkV6 families");
- if (islistening)
+ if (is_listening)
throw new InvalidOperationException ();
/* FIXME: do non-blocking sockets Poll here? */
IPEndPoint iep = new IPEndPoint (address, port);
SocketAddress serial = iep.Serialize ();
- Connect_internal (socket, serial, out error);
+ Connect_internal (safe_handle, serial, out error);
if (error == 0) {
- connected = true;
- isbound = true;
+ is_connected = true;
+ is_bound = true;
seed_endpoint = iep;
return;
} else if (error != (int)SocketError.InProgress &&
continue;
}
- if (!blocking) {
+ if (!is_blocking) {
Poll (-1, SelectMode.SelectWrite);
error = (int)GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error);
if (error == 0) {
- connected = true;
- isbound = true;
+ is_connected = true;
+ is_bound = true;
seed_endpoint = iep;
return;
}
public bool DisconnectAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
e.curSocket = this;
*/
public void Disconnect (bool reuseSocket)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error = 0;
- Disconnect_internal (socket, reuseSocket, out error);
+ Disconnect_internal (safe_handle, reuseSocket, out error);
if (error != 0) {
if (error == 50) {
}
}
- connected = false;
+ is_connected = false;
if (reuseSocket) {
/* Do managed housekeeping here... */
{
var si = new SocketInformation ();
si.Options =
- (islistening ? SocketInformationOptions.Listening : 0) |
- (connected ? SocketInformationOptions.Connected : 0) |
- (blocking ? 0 : SocketInformationOptions.NonBlocking) |
- (useoverlappedIO ? SocketInformationOptions.UseOnlyOverlappedIO : 0);
+ (is_listening ? SocketInformationOptions.Listening : 0) |
+ (is_connected ? SocketInformationOptions.Connected : 0) |
+ (is_blocking ? 0 : SocketInformationOptions.NonBlocking) |
+ (use_overlapped_io ? SocketInformationOptions.UseOnlyOverlappedIO : 0);
- si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", (int)address_family, (int)socket_type, (int)protocol_type, isbound ? 1 : 0, (long)Handle);
- socket = null;
+ si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", (int)address_family, (int)socket_type, (int)protocol_type, is_bound ? 1 : 0, (long)Handle);
+ safe_handle = null;
return si;
}
public Socket EndAccept (out byte[] buffer, out int bytesTransferred, IAsyncResult asyncResult)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (asyncResult == null)
public void EndConnect (IAsyncResult result)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (result == null)
public void EndDisconnect (IAsyncResult asyncResult)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (asyncResult == null)
ref EndPoint endPoint,
out IPPacketInformation ipPacketInformation)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (asyncResult == null)
public void EndSendFile (IAsyncResult asyncResult)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (asyncResult == null)
public int EndSendTo (IAsyncResult result)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (result == null)
public void GetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, byte [] optionValue)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (optionValue == null)
int error;
- GetSocketOption_arr_internal (socket, optionLevel, optionName, ref optionValue,
+ GetSocketOption_arr_internal (safe_handle, optionLevel, optionName, ref optionValue,
out error);
if (error != 0)
throw new SocketException (error);
public byte [] GetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, int length)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
byte[] byte_val=new byte[length];
int error;
- GetSocketOption_arr_internal (socket, optionLevel, optionName, ref byte_val,
+ GetSocketOption_arr_internal (safe_handle, optionLevel, optionName, ref byte_val,
out error);
if (error != 0)
throw new SocketException (error);
public int IOControl (int ioctl_code, byte [] in_value, byte [] out_value)
{
- if (disposed)
+ if (is_disposed)
throw new ObjectDisposedException (GetType ().ToString ());
int error;
- int result = WSAIoctl (socket, ioctl_code, in_value, out_value,
+ int result = WSAIoctl (safe_handle, ioctl_code, in_value, out_value,
out error);
if (error != 0)
public void Listen (int backlog)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!isbound)
+ if (!is_bound)
throw new SocketException ((int)SocketError.InvalidArgument);
int error;
- Listen_internal(socket, backlog, out error);
+ Listen_internal(safe_handle, backlog, out error);
if (error != 0)
throw new SocketException (error);
- islistening = true;
+ is_listening = true;
}
public bool Poll (int time_us, SelectMode mode)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (mode != SelectMode.SelectRead &&
throw new NotSupportedException ("'mode' parameter is not valid.");
int error;
- bool result = Poll_internal (socket, mode, time_us, out error);
+ bool result = Poll_internal (safe_handle, mode, time_us, out error);
if (error != 0)
throw new SocketException (error);
- if (mode == SelectMode.SelectWrite && result && !connected) {
- /* Update the connected state; for
+ if (mode == SelectMode.SelectWrite && result && !is_connected) {
+ /* Update the is_connected state; for
* non-blocking Connect()s this is
* when we can find out that the
* connect succeeded.
*/
if ((int)GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Error) == 0) {
- connected = true;
+ is_connected = true;
}
}
public int Receive (byte [] buffer, SocketFlags flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
int ret = Receive_nochecks (buffer, 0, buffer.Length, flags, out error);
if (error != SocketError.Success) {
- if (error == SocketError.WouldBlock && blocking) // This might happen when ReceiveTimeout is set
- throw new SocketException ((int) error, timeout_exc_msg);
+ if (error == SocketError.WouldBlock && is_blocking) // This might happen when ReceiveTimeout is set
+ throw new SocketException ((int) error, TIMEOUT_EXCEPTION_MSG);
throw new SocketException ((int) error);
}
public int Receive (byte [] buffer, int size, SocketFlags flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
int ret = Receive_nochecks (buffer, 0, size, flags, out error);
if (error != SocketError.Success) {
- if (error == SocketError.WouldBlock && blocking) // This might happen when ReceiveTimeout is set
- throw new SocketException ((int) error, timeout_exc_msg);
+ if (error == SocketError.WouldBlock && is_blocking) // This might happen when ReceiveTimeout is set
+ throw new SocketException ((int) error, TIMEOUT_EXCEPTION_MSG);
throw new SocketException ((int) error);
}
public int Receive (byte [] buffer, int offset, int size, SocketFlags flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
int ret = Receive_nochecks (buffer, offset, size, flags, out error);
if (error != SocketError.Success) {
- if (error == SocketError.WouldBlock && blocking) // This might happen when ReceiveTimeout is set
- throw new SocketException ((int) error, timeout_exc_msg);
+ if (error == SocketError.WouldBlock && is_blocking) // This might happen when ReceiveTimeout is set
+ throw new SocketException ((int) error, TIMEOUT_EXCEPTION_MSG);
throw new SocketException ((int) error);
}
public int Receive (byte [] buffer, int offset, int size, SocketFlags flags, out SocketError error)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public bool ReceiveFromAsync (SocketAsyncEventArgs e)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
// We do not support recv into multiple buffers yet
public int ReceiveFrom (byte [] buffer, ref EndPoint remoteEP)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public int ReceiveFrom (byte [] buffer, SocketFlags flags, ref EndPoint remoteEP)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public int ReceiveFrom (byte [] buffer, int size, SocketFlags flags,
ref EndPoint remoteEP)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public int ReceiveFrom (byte [] buffer, int offset, int size, SocketFlags flags,
ref EndPoint remoteEP)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
ref EndPoint remote_end, bool throwOnError, out int error)
{
SocketAddress sockaddr = remote_end.Serialize();
- int cnt = RecvFrom_internal (socket, buf, offset, size, flags, ref sockaddr, out error);
+ int cnt = RecvFrom_internal (safe_handle, buf, offset, size, flags, ref sockaddr, out error);
SocketError err = (SocketError) error;
if (err != 0) {
if (err != SocketError.WouldBlock && err != SocketError.InProgress)
- connected = false;
- else if (err == SocketError.WouldBlock && blocking) { // This might happen when ReceiveTimeout is set
+ is_connected = false;
+ else if (err == SocketError.WouldBlock && is_blocking) { // This might happen when ReceiveTimeout is set
if (throwOnError)
- throw new SocketException ((int) SocketError.TimedOut, timeout_exc_msg);
+ throw new SocketException ((int) SocketError.TimedOut, TIMEOUT_EXCEPTION_MSG);
error = (int) SocketError.TimedOut;
return 0;
}
return 0;
}
- connected = true;
- isbound = true;
+ is_connected = true;
+ is_bound = true;
// If sockaddr is null then we're a connection
// oriented protocol and should ignore the
public bool ReceiveMessageFromAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
throw new NotImplementedException ();
ref EndPoint remoteEP,
out IPPacketInformation ipPacketInformation)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
throw new NotImplementedException ();
public int Send (byte [] buf)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buf == null)
public int Send (byte [] buf, SocketFlags flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buf == null)
public int Send (byte [] buf, int size, SocketFlags flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buf == null)
public int Send (byte [] buf, int offset, int size, SocketFlags flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buf == null)
public int Send (byte [] buf, int offset, int size, SocketFlags flags, out SocketError error)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buf == null)
public void SendFile (string fileName)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!connected)
+ if (!is_connected)
throw new NotSupportedException ();
- if (!blocking)
+ if (!is_blocking)
throw new InvalidOperationException ();
SendFile (fileName, null, null, 0);
public void SendFile (string fileName, byte[] preBuffer, byte[] postBuffer, TransmitFileOptions flags)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!connected)
+ if (!is_connected)
throw new NotSupportedException ();
- if (!blocking)
+ if (!is_blocking)
throw new InvalidOperationException ();
- if (!SendFile (socket, fileName, preBuffer, postBuffer, flags)) {
+ if (!SendFile (safe_handle, fileName, preBuffer, postBuffer, flags)) {
SocketException exc = new SocketException ();
if (exc.ErrorCode == 2 || exc.ErrorCode == 3)
throw new FileNotFoundException ();
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (e.BufferList != null)
throw new NotSupportedException ("Mono doesn't support using BufferList at this point.");
public int SendTo (byte [] buffer, EndPoint remote_end)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public int SendTo (byte [] buffer, SocketFlags flags, EndPoint remote_end)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public int SendTo (byte [] buffer, int size, SocketFlags flags, EndPoint remote_end)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
public int SendTo (byte [] buffer, int offset, int size, SocketFlags flags,
EndPoint remote_end)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffer == null)
int ret, error;
- ret = SendTo_internal (socket, buffer, offset, size, flags, sockaddr, out error);
+ ret = SendTo_internal (safe_handle, buffer, offset, size, flags, sockaddr, out error);
SocketError err = (SocketError) error;
if (err != 0) {
if (err != SocketError.WouldBlock && err != SocketError.InProgress)
- connected = false;
+ is_connected = false;
throw new SocketException (error);
}
- connected = true;
- isbound = true;
+ is_connected = true;
+ is_bound = true;
seed_endpoint = remote_end;
return ret;
public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, byte [] optionValue)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
// I'd throw an ArgumentNullException, but this is what MS does.
int error;
- SetSocketOption_internal (socket, optionLevel, optionName, null,
+ SetSocketOption_internal (safe_handle, optionLevel, optionName, null,
optionValue, 0, out error);
if (error != 0) {
public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, object optionValue)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
// NOTE: if a null is passed, the byte[] overload is used instead...
LingerOption linger = optionValue as LingerOption;
if (linger == null)
throw new ArgumentException ("A 'LingerOption' value must be specified.", "optionValue");
- SetSocketOption_internal (socket, optionLevel, optionName, linger, null, 0, out error);
+ SetSocketOption_internal (safe_handle, optionLevel, optionName, linger, null, 0, out error);
} else if (optionLevel == SocketOptionLevel.IP && (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)) {
MulticastOption multicast = optionValue as MulticastOption;
if (multicast == null)
throw new ArgumentException ("A 'MulticastOption' value must be specified.", "optionValue");
- SetSocketOption_internal (socket, optionLevel, optionName, multicast, null, 0, out error);
+ SetSocketOption_internal (safe_handle, optionLevel, optionName, multicast, null, 0, out error);
} else if (optionLevel == SocketOptionLevel.IPv6 && (optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership)) {
IPv6MulticastOption multicast = optionValue as IPv6MulticastOption;
if (multicast == null)
throw new ArgumentException ("A 'IPv6MulticastOption' value must be specified.", "optionValue");
- SetSocketOption_internal (socket, optionLevel, optionName, multicast, null, 0, out error);
+ SetSocketOption_internal (safe_handle, optionLevel, optionName, multicast, null, 0, out error);
} else {
throw new ArgumentException ("Invalid value specified.", "optionValue");
}
public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, bool optionValue)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error;
int int_val = (optionValue) ? 1 : 0;
- SetSocketOption_internal (socket, optionLevel, optionName, null, null, int_val, out error);
+ SetSocketOption_internal (safe_handle, optionLevel, optionName, null, null, int_val, out error);
if (error != 0) {
if (error == (int) SocketError.InvalidArgument)
throw new ArgumentException ();
public IntPtr buf;
}
- internal Queue readQ = new Queue (2);
- internal Queue writeQ = new Queue (2);
-
- /*
- * These two fields are looked up by name by the runtime, don't change
- * their name without also updating the runtime code.
- */
- private static int ipv4Supported = -1, ipv6Supported = -1;
- int linger_timeout;
-
static Socket ()
{
- // initialize ipv4Supported and ipv6Supported
+ // initialize ipv4_supported and ipv6_supported
CheckProtocolSupport ();
}
internal static void CheckProtocolSupport ()
{
- if(ipv4Supported == -1) {
+ if(ipv4_supported == -1) {
try {
Socket tmp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
tmp.Close();
- ipv4Supported = 1;
+ ipv4_supported = 1;
} catch {
- ipv4Supported = 0;
+ ipv4_supported = 0;
}
}
- if (ipv6Supported == -1) {
+ if (ipv6_supported == -1) {
// We need to put a try/catch around ConfigurationManager methods as will always throw an exception
// when run in a mono embedded application. This occurs as embedded applications do not have a setup
// for application config. The exception is not thrown when called from a normal .NET application.
SettingsSection config;
config = (SettingsSection) System.Configuration.ConfigurationManager.GetSection ("system.net/settings");
if (config != null)
- ipv6Supported = config.Ipv6.Enabled ? -1 : 0;
+ ipv6_supported = config.Ipv6.Enabled ? -1 : 0;
} catch {
- ipv6Supported = -1;
+ ipv6_supported = -1;
}
#else
try {
NetConfig config = System.Configuration.ConfigurationSettings.GetConfig("system.net/settings") as NetConfig;
if (config != null)
- ipv6Supported = config.ipv6Enabled ? -1 : 0;
+ ipv6_supported = config.ipv6Enabled ? -1 : 0;
} catch {
- ipv6Supported = -1;
+ ipv6_supported = -1;
}
#endif
#endif
- if (ipv6Supported != 0) {
+ if (ipv6_supported != 0) {
try {
Socket tmp = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
tmp.Close();
- ipv6Supported = 1;
+ ipv6_supported = 1;
} catch {
- ipv6Supported = 0;
+ ipv6_supported = 0;
}
}
}
public static bool SupportsIPv4 {
get {
CheckProtocolSupport();
- return ipv4Supported == 1;
+ return ipv4_supported == 1;
}
}
public static bool SupportsIPv6 {
get {
CheckProtocolSupport();
- return ipv6Supported == 1;
+ return ipv6_supported == 1;
}
}
#if NET_2_1
public static bool OSSupportsIPv4 {
get {
CheckProtocolSupport();
- return ipv4Supported == 1;
+ return ipv4_supported == 1;
}
}
#endif
public static bool OSSupportsIPv6 {
get {
CheckProtocolSupport();
- return ipv6Supported == 1;
+ return ipv6_supported == 1;
}
}
#else
}
#endif
- /* the field "socket" is looked up by name by the runtime */
- private SafeSocketHandle socket;
- private AddressFamily address_family;
- private SocketType socket_type;
- private ProtocolType protocol_type;
- internal bool blocking=true;
- internal bool isbound;
- /* When true, the socket was connected at the time of
- * the last IO operation
- */
- internal bool connected;
- /* true if we called Close_internal */
- private bool closed;
- internal bool disposed;
- internal bool connect_in_progress;
-
- /*
- * This EndPoint is used when creating new endpoints. Because
- * there are many types of EndPoints possible,
- * seed_endpoint.Create(addr) is used for creating new ones.
- * As such, this value is set on Bind, SentTo, ReceiveFrom,
- * Connect, etc.
- */
- internal EndPoint seed_endpoint = null;
-
// Creates a new system socket, returning the handle
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern IntPtr Socket_internal(AddressFamily family,
int error;
var handle = Socket_internal (addressFamily, socketType, protocolType, out error);
- socket = new SafeSocketHandle (handle, true);
+ safe_handle = new SafeSocketHandle (handle, true);
if (error != 0)
throw new SocketException (error);
public bool Blocking {
get {
- return(blocking);
+ return is_blocking;
}
set {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error;
- Blocking_internal (socket, value, out error);
+ Blocking_internal (safe_handle, value, out error);
if (error != 0)
throw new SocketException (error);
- blocking=value;
+ is_blocking = value;
}
}
public bool Connected {
- get { return connected; }
- internal set { connected = value; }
+ get { return is_connected; }
+ internal set { is_connected = value; }
}
public ProtocolType ProtocolType {
public bool NoDelay {
get {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
ThrowIfUpd ();
}
set {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
ThrowIfUpd ();
public int ReceiveBufferSize {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return((int)GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer));
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
if (value < 0) {
public int SendBufferSize {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return((int)GetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendBuffer));
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
if (value < 0) {
public short Ttl {
get {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
return(ttl_val);
}
set {
- if (disposed && closed) {
+ if (is_disposed && is_closed) {
throw new ObjectDisposedException (GetType ().ToString ());
}
if (value < 0) {
public EndPoint RemoteEndPoint {
get {
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
/*
* etc has not yet been called. MS returns null
* in this case.
*/
- if (!connected || seed_endpoint == null)
+ if (!is_connected || seed_endpoint == null)
return null;
SocketAddress sa;
int error;
- sa=RemoteEndPoint_internal(socket, (int) address_family, out error);
+ sa = RemoteEndPoint_internal (safe_handle, (int) address_family, out error);
if (error != 0)
throw new SocketException (error);
void Linger (IntPtr handle)
{
- if (!connected || linger_timeout <= 0)
+ if (!is_connected || linger_timeout <= 0)
return;
// We don't want to receive any more data
protected virtual void Dispose (bool disposing)
{
- if (disposed)
+ if (is_disposed)
return;
- disposed = true;
- bool was_connected = connected;
- connected = false;
+ is_disposed = true;
+ bool was_connected = is_connected;
+ is_connected = false;
- if (socket != null) {
- closed = true;
+ if (safe_handle != null) {
+ is_closed = true;
IntPtr x = Handle;
if (was_connected)
Linger (x);
- socket.Dispose ();
+ safe_handle.Dispose ();
}
}
{
SocketAddress serial = null;
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (remoteEP == null)
if (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any))
throw new SocketException ((int) SocketError.AddressNotAvailable);
- if (islistening)
+ if (is_listening)
throw new InvalidOperationException ();
serial = remoteEP.Serialize ();
int error = 0;
- Connect_internal (socket, serial, out error);
+ Connect_internal (safe_handle, serial, out error);
if (error == 0 || error == 10035)
seed_endpoint = remoteEP; // Keep the ep around for non-blocking sockets
if (error != 0) {
- if (closed)
- error = SOCKET_CLOSED;
+ if (is_closed)
+ error = SOCKET_CLOSED_CODE;
throw new SocketException (error);
}
if (socket_type == SocketType.Dgram && ep != null && (ep.Address.Equals (IPAddress.Any) || ep.Address.Equals (IPAddress.IPv6Any)))
- connected = false;
+ is_connected = false;
else
- connected = true;
- isbound = true;
+ is_connected = true;
+ is_bound = true;
}
public bool ReceiveAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
// LAME SPEC: the ArgumentException is never thrown, instead an NRE is
public bool SendAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (e.Buffer == null && e.BufferList == null)
throw new NullReferenceException ("Either e.Buffer or e.BufferList must be valid buffers.");
internal int Receive_nochecks (byte [] buf, int offset, int size, SocketFlags flags, out SocketError error)
{
int nativeError;
- int ret = Receive_internal (socket, buf, offset, size, flags, out nativeError);
+ int ret = Receive_internal (safe_handle, buf, offset, size, flags, out nativeError);
error = (SocketError) nativeError;
if (error != SocketError.Success && error != SocketError.WouldBlock && error != SocketError.InProgress) {
- connected = false;
- isbound = false;
+ is_connected = false;
+ is_bound = false;
} else {
- connected = true;
+ is_connected = true;
}
return ret;
int nativeError;
- int ret = Send_internal (socket, buf, offset, size, flags, out nativeError);
+ int ret = Send_internal (safe_handle, buf, offset, size, flags, out nativeError);
error = (SocketError)nativeError;
if (error != SocketError.Success && error != SocketError.WouldBlock && error != SocketError.InProgress) {
- connected = false;
- isbound = false;
+ is_connected = false;
+ is_bound = false;
} else {
- connected = true;
+ is_connected = true;
}
return ret;
public object GetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
object obj_val;
int error;
- GetSocketOption_obj_internal (socket, optionLevel, optionName, out obj_val,
+ GetSocketOption_obj_internal (safe_handle, optionLevel, optionName, out obj_val,
out error);
if (error != 0)
throw new SocketException (error);
public void Shutdown (SocketShutdown how)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (!connected)
+ if (!is_connected)
throw new SocketException (10057); // Not connected
int error;
- Shutdown_internal (socket, how, out error);
+ Shutdown_internal (safe_handle, how, out error);
if (error != 0)
throw new SocketException (error);
}
public void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
int error;
- SetSocketOption_internal (socket, optionLevel, optionName, null,
+ SetSocketOption_internal (safe_handle, optionLevel, optionName, null,
null, optionValue, out error);
if (error != 0)
public
IAsyncResult BeginConnect(EndPoint end_point, AsyncCallback callback, object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (end_point == null)
// Calling connect() again will reset the connection attempt and cause
// an error. Better to just close the socket and move on.
connect_in_progress = false;
- socket.Dispose ();
+ safe_handle.Dispose ();
var handle = Socket_internal (address_family, socket_type, protocol_type, out error);
- socket = new SafeSocketHandle (handle, true);
+ safe_handle = new SafeSocketHandle (handle, true);
if (error != 0)
throw new SocketException (error);
}
- bool blk = blocking;
+ bool blk = is_blocking;
if (blk)
Blocking = false;
SocketAddress serial = end_point.Serialize ();
- Connect_internal (socket, serial, out error);
+ Connect_internal (safe_handle, serial, out error);
if (blk)
Blocking = true;
if (error == 0) {
// succeeded synch
- connected = true;
- isbound = true;
+ is_connected = true;
+ is_bound = true;
req.Complete (true);
return req;
}
if (error != (int) SocketError.InProgress && error != (int) SocketError.WouldBlock) {
// error synch
- connected = false;
- isbound = false;
+ is_connected = false;
+ is_bound = false;
req.Complete (new SocketException (error), true);
return req;
}
// continue asynch
- connected = false;
- isbound = false;
+ is_connected = false;
+ is_bound = false;
connect_in_progress = true;
socket_pool_queue (SocketAsyncWorker.Dispatcher, req);
return req;
IAsyncResult BeginConnect (IPAddress[] addresses, int port, AsyncCallback callback, object state)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (addresses == null)
if (port <= 0 || port > 65535)
throw new ArgumentOutOfRangeException ("port", "Must be > 0 and < 65536");
- if (islistening)
+ if (is_listening)
throw new InvalidOperationException ();
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Connect);
req.Addresses = addresses;
req.Port = port;
- connected = false;
+ is_connected = false;
return BeginMConnect (req);
}
public bool ConnectAsync (SocketAsyncEventArgs e)
{
// NO check is made whether e != null in MS.NET (NRE is thrown in such case)
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
- if (islistening)
+ if (is_listening)
throw new InvalidOperationException ("You may not perform this operation after calling the Listen method.");
if (e.RemoteEndPoint == null)
throw new ArgumentNullException ("remoteEP");
public
int Receive (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffers == null ||
}
try {
- ret = Receive_internal (socket, bufarray,
+ ret = Receive_internal (safe_handle, bufarray,
socketFlags,
out nativeError);
} finally {
public
int Send (IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, out SocketError errorCode)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (buffers == null)
throw new ArgumentNullException ("buffers");
}
try {
- ret = Send_internal (socket, bufarray, socketFlags, out nativeError);
+ ret = Send_internal (safe_handle, bufarray, socketFlags, out nativeError);
} finally {
for(int i = 0; i < numsegments; i++) {
if (gch[i].IsAllocated) {
int bytesReceived = EndReceive (result, out error);
if (error != SocketError.Success) {
if (error != SocketError.WouldBlock && error != SocketError.InProgress)
- connected = false;
+ is_connected = false;
throw new SocketException ((int)error);
}
return bytesReceived;
public
int EndReceive (IAsyncResult asyncResult, out SocketError errorCode)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (asyncResult == null)
int bytesSent = EndSend (result, out error);
if (error != SocketError.Success) {
if (error != SocketError.WouldBlock && error != SocketError.InProgress)
- connected = false;
+ is_connected = false;
throw new SocketException ((int)error);
}
return bytesSent;
public
int EndSend (IAsyncResult asyncResult, out SocketError errorCode)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (asyncResult == null)
throw new ArgumentNullException ("asyncResult");
public
int EndReceiveFrom(IAsyncResult result, ref EndPoint end_point)
{
- if (disposed && closed)
+ if (is_disposed && is_closed)
throw new ObjectDisposedException (GetType ().ToString ());
if (result == null)