dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System/Net/Sockets Socket.cs,1.15,1.1


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net/Sockets Socket.cs,1.15,1.16
Date: Tue, 27 May 2003 22:12:13 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System/Net/Sockets
In directory subversions:/tmp/cvs-serv20864/System/Net/Sockets

Modified Files:
        Socket.cs 
Log Message:


Modify the internalcall interface for sockets so that IPv4, IPv6,
and IrDA socket addresses will work.


Index: Socket.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Sockets/Socket.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** Socket.cs   15 May 2003 20:45:27 -0000      1.15
--- Socket.cs   28 May 2003 02:12:11 -0000      1.16
***************
*** 37,41 ****
        private bool blocking;
        private bool connected;
!       private IPEndPoint remoteEP;
  
        // Invalid socket handle.
--- 37,42 ----
        private bool blocking;
        private bool connected;
!       private EndPoint localEP;
!       private EndPoint remoteEP;
  
        // Invalid socket handle.
***************
*** 52,57 ****
                                        addressFamily = 
AddressFamily.InterNetwork;
                                }
!                               else if(addressFamily != 
AddressFamily.InterNetwork &&
!                                       addressFamily != 
AddressFamily.InterNetworkV6)
                                {
                                        throw new SocketException(Errno.EINVAL);
--- 53,58 ----
                                        addressFamily = 
AddressFamily.InterNetwork;
                                }
!                               else if(!SocketMethods.AddressFamilySupported
!                                                       ((int)addressFamily))
                                {
                                        throw new SocketException(Errno.EINVAL);
***************
*** 91,99 ****
                                this.blocking = true;
                                this.connected = false;
                                this.remoteEP = null;
  
                                // Attempt to create the socket.  This may bail 
out for
!                               // "addressFamily == InterNetworkV6" if ipv6 is 
not supported
!                               // by the underlying operating system.
                                if(!SocketMethods.Create((int)addressFamily, 
(int)socketType,
                                                                                
 (int)protocolType, out handle))
--- 92,104 ----
                                this.blocking = true;
                                this.connected = false;
+                               this.localEP = null;
                                this.remoteEP = null;
  
                                // Attempt to create the socket.  This may bail 
out for
!                               // some address families, even if 
"AddressFamilySupported"
!                               // returned true.  This can happen, for 
example, if the user
!                               // space definitions are available for IrDA, 
but the kernel
!                               // drivers are not.  "AddressFamilySupported" 
may not be
!                               // able to detect the kernel capabilities on 
all platforms.
                                if(!SocketMethods.Create((int)addressFamily, 
(int)socketType,
                                                                                
 (int)protocolType, out handle))
***************
*** 104,108 ****
        private Socket(AddressFamily addressFamily, SocketType socketType,
                                   ProtocolType protocolType, IntPtr handle, 
bool blocking,
!                                  IPEndPoint remoteEP)
                        {
                                // Set up for a new socket that has just been 
accepted.
--- 109,113 ----
        private Socket(AddressFamily addressFamily, SocketType socketType,
                                   ProtocolType protocolType, IntPtr handle, 
bool blocking,
!                                  EndPoint remoteEP)
                        {
                                // Set up for a new socket that has just been 
accepted.
***************
*** 113,116 ****
--- 118,122 ----
                                this.blocking = blocking;
                                this.connected = true;
+                               this.localEP = null;
                                this.remoteEP = remoteEP;
                        }
***************
*** 136,140 ****
                                IntPtr currentHandle;
                                IntPtr newHandle;
!                               IPEndPoint remoteEP;
  
                                // Get the socket handle, synchronized against 
"Close".
--- 142,146 ----
                                IntPtr currentHandle;
                                IntPtr newHandle;
!                               EndPoint remoteEP;
  
                                // Get the socket handle, synchronized against 
"Close".
***************
*** 150,159 ****
                                }
  
                                // Accept a new connection on the socket.  We 
do this outside
                                // of the lock's protection so that multiple 
threads can
                                // wait for incoming connections on the same 
socket.
-                               // TODO: ipv6 support
                                if(!SocketMethods.Accept
!                                         (currentHandle, out address, out 
port, out newHandle))
                                {
                                        throw new 
SocketException(SocketMethods.GetErrno());
--- 156,168 ----
                                }
  
+                               // Create the sockaddr buffer from the local 
end point.
+                               byte[] addrReturn = 
LocalEndPoint.Serialize().Array;
+                               Array.Clear(addrReturn, 0, addrReturn.Length);
+ 
                                // Accept a new connection on the socket.  We 
do this outside
                                // of the lock's protection so that multiple 
threads can
                                // wait for incoming connections on the same 
socket.
                                if(!SocketMethods.Accept
!                                         (currentHandle, addrReturn, out 
newHandle))
                                {
                                        throw new 
SocketException(SocketMethods.GetErrno());
***************
*** 161,169 ****
  
                                // Create the end-point object for the remote 
side.
!                               remoteEP = new IPEndPoint(address, port);
  
                                // Create and return a new socket object.
                                return new Socket(family, socketType, protocol,
!                                                                 handle, 
blocking, remoteEP);
                        }
  
--- 170,178 ----
  
                                // Create the end-point object for the remote 
side.
!                               remoteEP = LocalEndPoint.Create(new 
SocketAddress(addrReturn));
  
                                // Create and return a new socket object.
                                return new Socket(family, socketType, protocol,
!                                                                 newHandle, 
blocking, remoteEP);
                        }
  
***************
*** 405,414 ****
                        {
                                // Validate the parameters.
-                               // TODO: ipv6 support
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(!(remoteEP is IPEndPoint))
                                {
                                        throw new SocketException(Errno.EINVAL);
--- 414,422 ----
                        {
                                // Validate the parameters.
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(remoteEP.AddressFamily != family)
                                {
                                        throw new SocketException(Errno.EINVAL);
***************
*** 490,501 ****
                                // Validate the parameters.
                                ValidateBuffer(buffer, offset, size);
-                               // TODO: ipv6 support
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               if(!(remoteEP is IPEndPoint))
                                {
!                                       remoteEP = new IPEndPoint(0, 0);
                                }
  
--- 498,508 ----
                                // Validate the parameters.
                                ValidateBuffer(buffer, offset, size);
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(remoteEP.AddressFamily != family)
                                {
!                                       throw new SocketException(Errno.EINVAL);
                                }
  
***************
*** 577,586 ****
                                // Validate the parameters.
                                ValidateBuffer(buffer, offset, size);
-                               // TODO: ipv6 support
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(!(remoteEP is IPEndPoint))
                                {
                                        throw new SocketException(Errno.EINVAL);
--- 584,592 ----
                                // Validate the parameters.
                                ValidateBuffer(buffer, offset, size);
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(remoteEP.AddressFamily != family)
                                {
                                        throw new SocketException(Errno.EINVAL);
***************
*** 619,635 ****
        public void Bind(EndPoint localEP)
                        {
-                               IPEndPoint endPoint;
- 
                                // Validate the parameter.
-                               // TODO: ipv6 support
                                if(localEP == null)
                                {
                                        throw new 
ArgumentNullException("localEP");
                                }
!                               else if(!(localEP is IPEndPoint))
                                {
                                        throw new SocketException(Errno.EINVAL);
                                }
!                               endPoint = (IPEndPoint)localEP;
  
                                // Lock down the socket object while we do the 
bind.
--- 625,640 ----
        public void Bind(EndPoint localEP)
                        {
                                // Validate the parameter.
                                if(localEP == null)
                                {
                                        throw new 
ArgumentNullException("localEP");
                                }
!                               else if(localEP.AddressFamily != family)
                                {
                                        throw new SocketException(Errno.EINVAL);
                                }
! 
!                               // Convert the end point into a sockaddr buffer.
!                               byte[] addr = localEP.Serialize().Array;
  
                                // Lock down the socket object while we do the 
bind.
***************
*** 643,654 ****
                                        }
  
!                                       // Bind an address to the socket.
!                                       // TODO: ipv6 support
!                                       if(!SocketMethods.Bind
!                                                 (handle, (int)family,
!                                                  endPoint.Address.Address, 
endPoint.Port))
                                        {
                                                throw new 
SocketException(SocketMethods.GetErrno());
                                        }
                                }
                        }
--- 648,659 ----
                                        }
  
!                                       // Bind the address to the socket.
!                                       if(!SocketMethods.Bind(handle, addr))
                                        {
                                                throw new 
SocketException(SocketMethods.GetErrno());
                                        }
+ 
+                                       // Record the local end point for later.
+                                       this.localEP = localEP;
                                }
                        }
***************
*** 664,680 ****
        public void Connect(EndPoint remoteEP)
                        {
-                               IPEndPoint endPoint;
- 
                                // Validate the parameter.
-                               // TODO: ipv6 support
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(!(remoteEP is IPEndPoint))
                                {
                                        throw new SocketException(Errno.EINVAL);
                                }
!                               endPoint = (IPEndPoint)remoteEP;
  
                                // Lock down the socket object while we do the 
connect.
--- 669,684 ----
        public void Connect(EndPoint remoteEP)
                        {
                                // Validate the parameter.
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(remoteEP.AddressFamily != family)
                                {
                                        throw new SocketException(Errno.EINVAL);
                                }
! 
!                               // Convert the end point into a sockaddr buffer.
!                               byte[] addr = remoteEP.Serialize().Array;
  
                                // Lock down the socket object while we do the 
connect.
***************
*** 689,702 ****
  
                                        // Connect to the foreign location.
!                                       // TODO: ipv6 support
!                                       if(!SocketMethods.Connect
!                                                 (handle, (int)family,
!                                                  endPoint.Address.Address, 
endPoint.Port))
                                        {
                                                throw new 
SocketException(SocketMethods.GetErrno());
                                        }
                                        connected = true;
!                                       this.remoteEP = new IPEndPoint
!                                               (endPoint.Address.Address, 
endPoint.Port);
                                }
                        }
--- 693,702 ----
  
                                        // Connect to the foreign location.
!                                       if(!SocketMethods.Connect(handle, addr))
                                        {
                                                throw new 
SocketException(SocketMethods.GetErrno());
                                        }
                                        connected = true;
!                                       this.remoteEP = remoteEP;
                                }
                        }
***************
*** 836,840 ****
                                        {
                                                // Get the contents of the 
multicast membership set.
!                                               long group, mcint;
                                                lock(this)
                                                {
--- 836,841 ----
                                        {
                                                // Get the contents of the 
multicast membership set.
!                                               byte[] group;
!                                               byte[] mcint;
                                                lock(this)
                                                {
***************
*** 844,850 ****
                                                                        
(S._("Exception_Disposed"));
                                                        }
                                                        
if(!SocketMethods.GetMulticastOption
!                                                                       
(handle, (int)optionName,
!                                                                        out 
group, out mcint))
                                                        {
                                                                throw new 
SocketException
--- 845,853 ----
                                                                        
(S._("Exception_Disposed"));
                                                        }
+                                                       group = new byte [32];
+                                                       mcint = new byte [32];
                                                        
if(!SocketMethods.GetMulticastOption
!                                                                       
(handle, (int)family, (int)optionName,
!                                                                        group, 
mcint))
                                                        {
                                                                throw new 
SocketException
***************
*** 852,856 ****
                                                        }
                                                        return new 
MulticastOption
!                                                               (new 
IPAddress(group), new IPAddress(mcint));
                                                }
                                        }
--- 855,860 ----
                                                        }
                                                        return new 
MulticastOption
!                                                               ((new 
SocketAddress(group)).IPAddress,
!                                                                (new 
SocketAddress(mcint)).IPAddress);
                                                }
                                        }
***************
*** 869,873 ****
                                                                  int 
optionLength)
                        {
!                               // This version is not portable - do not use.
                                throw new 
SecurityException(S._("Arg_SocketOption"));
                        }
--- 873,902 ----
                                                                  int 
optionLength)
                        {
!                               // Check for the IrDA device discovery option.
!                               if(optionLevel == (SocketOptionLevel)255 &&
!                                  optionName == (SocketOptionName)16)
!                               {
!                                       lock(this)
!                                       {
!                                               if(handle == InvalidHandle)
!                                               {
!                                                       throw new 
ObjectDisposedException
!                                                               
(S._("Exception_Disposed"));
!                                               }
!                                               else if(family != 
AddressFamily.Irda)
!                                               {
!                                                       throw new 
SocketException(Errno.EINVAL);
!                                               }
!                                               byte[] data = new byte 
[optionLength];
!                                               
if(!SocketMethods.DiscoverIrDADevices(handle, data))
!                                               {
!                                                       throw new 
SocketException
!                                                               
(SocketMethods.GetErrno());
!                                               }
!                                               return data;
!                                       }
!                               }
! 
!                               // Everything else is non-portable - do not use.
                                throw new 
SecurityException(S._("Arg_SocketOption"));
                        }
***************
*** 1017,1022 ****
                        {
                                int result;
!                               long address;
!                               int port;
  
                                // Validate the arguments.
--- 1046,1050 ----
                        {
                                int result;
!                               byte[] addrReturn;
  
                                // Validate the arguments.
***************
*** 1026,1029 ****
--- 1054,1065 ----
                                        throw new 
ArgumentNullException("remoteEP");
                                }
+                               else if(remoteEP.AddressFamily != family)
+                               {
+                                       throw new SocketException(Errno.EINVAL);
+                               }
+ 
+                               // Create a sockaddr buffer to write the 
address into.
+                               addrReturn = remoteEP.Serialize().Array;
+                               Array.Clear(addrReturn, 0, addrReturn.Length);
  
                                // Perform the receive operation.
***************
*** 1035,1042 ****
                                                        
(S._("Exception_Disposed"));
                                        }
-                                       // TODO: ipv6 support
                                        result = SocketMethods.ReceiveFrom
!                                               (handle, buffer, offset, size, 
(int)socketFlags,
!                                                out address, out port);
                                        if(result < 0)
                                        {
--- 1071,1077 ----
                                                        
(S._("Exception_Disposed"));
                                        }
                                        result = SocketMethods.ReceiveFrom
!                                               (handle, buffer, offset, size,
!                                                (int)socketFlags, addrReturn);
                                        if(result < 0)
                                        {
***************
*** 1045,1061 ****
                                        else
                                        {
!                                               if(socketType == 
SocketType.Dgram)
!                                               {
!                                                       if(!(remoteEP is 
IPEndPoint))
!                                                       {
!                                                               remoteEP = new 
IPEndPoint(address, port);
!                                                       }
!                                                       else
!                                                       {
!                                                               
((IPEndPoint)remoteEP).Address =
!                                                                       new 
IPAddress(address);
!                                                               
((IPEndPoint)remoteEP).Port = port;
!                                                       }
!                                               }
                                                return result;
                                        }
--- 1080,1085 ----
                                        else
                                        {
!                                               remoteEP = remoteEP.Create
!                                                       (new 
SocketAddress(addrReturn));
                                                return result;
                                        }
***************
*** 1344,1361 ****
                        {
                                int result;
!                               IPEndPoint endPoint;
  
                                // Validate the arguments.
                                ValidateBuffer(buffer, offset, size);
-                               // TODO: ipv6 support
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(!(remoteEP is IPEndPoint))
                                {
                                        throw new SocketException(Errno.EINVAL);
                                }
!                               endPoint = (IPEndPoint)remoteEP;
  
                                // Perform the send operation.
--- 1368,1386 ----
                        {
                                int result;
!                               byte[] addr;
  
                                // Validate the arguments.
                                ValidateBuffer(buffer, offset, size);
                                if(remoteEP == null)
                                {
                                        throw new 
ArgumentNullException("remoteEP");
                                }
!                               else if(remoteEP.AddressFamily != family)
                                {
                                        throw new SocketException(Errno.EINVAL);
                                }
! 
!                               // Convert the end point into a sockaddr buffer.
!                               addr = remoteEP.Serialize().Array;
  
                                // Perform the send operation.
***************
*** 1367,1374 ****
                                                        
(S._("Exception_Disposed"));
                                        }
-                                       // TODO: ipv6 support
                                        result = SocketMethods.SendTo
!                                               (handle, buffer, offset, size, 
(int)socketFlags,
!                                                endPoint.Address.Address, 
endPoint.Port);
                                        if(result < 0)
                                        {
--- 1392,1397 ----
                                                        
(S._("Exception_Disposed"));
                                        }
                                        result = SocketMethods.SendTo
!                                               (handle, buffer, offset, size, 
(int)socketFlags, addr);
                                        if(result < 0)
                                        {
***************
*** 1560,1563 ****
--- 1583,1592 ----
                                                MulticastOption multicast =
                                                        
(MulticastOption)optionValue;
+                                               byte[] group =
+                                                       (new 
IPEndPoint(multicast.Group, 0))
+                                                               
.Serialize().Array;
+                                               byte[] mcint =
+                                                       (new 
IPEndPoint(multicast.LocalAddress, 0))
+                                                               
.Serialize().Array;
                                                lock(this)
                                                {
***************
*** 1568,1574 ****
                                                        }
                                                        
if(!SocketMethods.SetMulticastOption
!                                                                       
(handle, (int)optionName,
!                                                                        
multicast.Group.Address,
!                                                                        
multicast.LocalAddress.Address))
                                                        {
                                                                throw new 
SocketException
--- 1597,1602 ----
                                                        }
                                                        
if(!SocketMethods.SetMulticastOption
!                                                                       
(handle, (int)family, (int)optionName,
!                                                                        group, 
mcint))
                                                        {
                                                                throw new 
SocketException
***************
*** 1701,1706 ****
                                get
                                {
!                                       long address;
!                                       int port;
                                        lock(this)
                                        {
--- 1729,1734 ----
                                get
                                {
!                                       byte[] addrReturn;
!                                       EndPoint ep;
                                        lock(this)
                                        {
***************
*** 1710,1724 ****
                                                                
(S._("Exception_Disposed"));
                                                }
!                                               // TODO: ipv6 support
!                                               if(!SocketMethods.GetSockName
!                                                               (handle, out 
address, out port))
                                                {
!                                                       throw new 
SocketException
!                                                               
(SocketMethods.GetErrno());
                                                }
!                                               else
                                                {
!                                                       return new 
IPEndPoint(address, port);
                                                }
                                        }
                                }
--- 1738,1778 ----
                                                                
(S._("Exception_Disposed"));
                                                }
!                                               if(localEP != null)
                                                {
!                                                       return localEP;
                                                }
! 
!                                               // Get a sockaddr buffer of the 
right size.
!                                               ep = remoteEP;
!                                               if(ep == null)
!                                               {
!                                                       // We don't have a 
remote end-point to guess
!                                                       // the size from, so 
check for known families.
!                                                       if(family == 
AddressFamily.InterNetwork)
!                                                       {
!                                                               ep = new 
IPEndPoint(IPAddress.Any, 0);
!                                                       }
!                                                       else if(family == 
AddressFamily.InterNetworkV6)
!                                                       {
!                                                               ep = new 
IPEndPoint(IPAddress.IPv6Any, 0);
!                                                       }
!                                                       else
!                                                       {
!                                                               throw new 
SocketException(Errno.EINVAL);
!                                                       }
!                                               }
!                                               addrReturn = 
ep.Serialize().Array;
!                                               Array.Clear(addrReturn, 0, 
addrReturn.Length);
! 
!                                               // Get the name of the socket.
!                                               
if(!SocketMethods.GetSockName(handle, addrReturn))
                                                {
!                                                       throw new 
SocketException
!                                                               
(SocketMethods.GetErrno());
                                                }
+ 
+                                               // Create a new end-point 
object using addrReturn.
+                                               localEP = ep.Create(new 
SocketAddress(addrReturn));
+                                               return localEP;
                                        }
                                }
***************
*** 1752,1756 ****
                                                        throw new 
SocketException(Errno.ENOTCONN);
                                                }
!                                               return new 
IPEndPoint(remoteEP.Address, remoteEP.Port);
                                        }
                                }
--- 1806,1810 ----
                                                        throw new 
SocketException(Errno.ENOTCONN);
                                                }
!                                               return remoteEP;
                                        }
                                }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]