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 NetworkStream.cs,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System/Net/Sockets NetworkStream.cs,1.6,1.7 Socket.cs,1.12,1.13 SocketOptionName.cs,1.2,1.3
Date: Thu, 03 Apr 2003 00:40:46 -0500

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

Modified Files:
        NetworkStream.cs Socket.cs SocketOptionName.cs 
Log Message:


Re-implement "NetworkStream" and "Socket".


Index: NetworkStream.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Sockets/NetworkStream.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** NetworkStream.cs    18 Nov 2002 18:58:03 -0000      1.6
--- NetworkStream.cs    3 Apr 2003 05:40:44 -0000       1.7
***************
*** 1,19 ****
  /*
!  * NetworkStream.cs - Implementation of the 
"System.Net.NetworkStreams.NetworkStream" class.
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
! *
!  * This program is free software, you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
!  * the Free Software Foundation, either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
!  * but WITHOUT ANY WARRANTY, without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
!  * along with this program, if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
--- 1,20 ----
  /*
!  * NetworkStream.cs - Implementation of the
!  *                    "System.Net.Sockets.NetworkStream" class.
   *
!  * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
!  *
!  * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
!  * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
!  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
!  * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
***************
*** 24,204 ****
  using System;
  using System.IO;
  
  public class NetworkStream : Stream
  {
!       private Socket mysocket;
!       private bool readaccess;
!       private bool writeaccess;
!       private bool ownsocket;
!       
        public NetworkStream(Socket socket)
!                       : this(socket, System.IO.FileAccess.ReadWrite, false)
                        {
!                               //Nothing to do
                        }
-       
        public NetworkStream(Socket socket, bool ownsSocket)
!                       : this(socket, System.IO.FileAccess.ReadWrite, 
ownsSocket)                                      
                        {
!                               //Nothing to do
                        }
-       
        public NetworkStream(Socket socket, FileAccess access)
                        : this(socket, access, false)
                        {
!                               //Nothing to do 
                        }
-                       
        public NetworkStream(Socket socket, FileAccess access, bool ownsSocket)
                        {
!                               if (socket == null) 
!                                       throw new 
ArgumentNullException("socket", S._("Arg_NotNull"));
!                               if (socket.Blocking == false)
!                                       throw new IOException(S._("IO_Socket"));
!                               if (socket.Connected == false)
!                                       throw new 
IOException(S._("IO_Socket"));                                
!                               if (socket.SocketType != SocketType.Stream)
!                                       throw new IOException(S._("IO_Socket"));
!                       
!                               mysocket = socket;
!                               ownsocket = ownsSocket;                         
        
!                               
!                               if (access == FileAccess.Read)
!                                       {
!                                               readaccess = true;
!                                               writeaccess = false;
!                                       }
!                               else if (access == FileAccess.Write)
!                                       {
!                                               readaccess = false;
!                                               writeaccess = true;
!                                       }
!                               else //Access == FileAccess.ReadWrite or 
another value
!                                       {
!                                               readaccess = true;
!                                               writeaccess = true;
!                                       }                                       
!                       }
!                       
!       [TODO]          
!       public override IAsyncResult BeginRead(byte[] buffer, int offset, int 
size, AsyncCallback callback, object state)
!                       {
!                               return null;
                        }
!       [TODO]  
!       public override IAsyncResult BeginWrite(byte[] buffer, int offset, int 
size, AsyncCallback callback, object state)
                        {
!                               return null;
                        }
!                       
!       public override void Close()
                        {
!                               if (ownsocket == true)
!                                       mysocket.Close();
!                               
!                       #if !ECMA_COMPAT
!                               Dispose(true);
!                       #endif
                        }
!       
! #if !ECMA_COMPAT
!       [TODO]
!       protected override void Dispose(bool disposing)
                        {
!                       
                        }
! #endif
!                       
!       [TODO]          
!       public override int EndRead(IAsyncResult asyncResult)           
                        {
!                               return 0;
                        }
-                       
-       [TODO]
        public override void EndWrite(IAsyncResult asyncResult)
                        {
!                       
                        }
!                       
!       [TODO]          
!       ~NetworkStream()
                        {
!                       
                        }
!                       
        public override void Flush()
                        {
!                               //This feature is reserved for future use
                        }
!                       
!       public override int Read(byte[] buffer, int offset, int size)
                        {
!                               if (mysocket == null)                   
!                                       throw new 
ObjectDisposedException(S._("Exception_Disposed"));                           
  
!                               if (buffer == null)
!                                       throw new 
ArgumentNullException("buffer", S._("Arg_NotNull"));                            
                      
!                                       
!                               if ((offset < 0) || (offset > buffer.Length))   
                
!                                       throw new ArgumentException("offset", 
S._("Arg_OutOfRange"));
!                               
!                               if ((size < 0) || (size > (buffer.Length - 
offset)))
!                                       throw new ArgumentException("offset", 
S._("Arg_OutOfRange"));
! 
!                               try
!                               {
!                                       return mysocket.Receive(buffer, offset, 
size, 
!                                                               
SocketFlags.None);
!                               }                                       
!                               catch(Exception e)
!                               {
!                                       throw new 
IOException(S._("IO_SocketRead"));            
!                               }
!                                                       
!                       }               
!       
        public override long Seek(long offset, SeekOrigin origin)
                        {
!                               throw new 
NotSupportedException(S._("NotSupp_DerivedStream"));
                        }
!       
!       public override void SetLength(long value)
                        {
!                               throw new 
NotSupportedException(S._("NotSupp_DerivedStream"));          
                        }
-                       
-       public override void Write(byte[] buffer, int offset, int size)
-                       {
-                               if (mysocket == null)
-                                       throw new 
ObjectDisposedException(S._("Exception_Disposed"));                             
                                      
- 
-                               if (buffer == null)
-                                       throw new 
ArgumentNullException("buffer", S._("Arg_NotNull"));
  
!                               if ((offset < 0) || (offset > buffer.Length))   
                
!                                       throw new ArgumentException("offset", 
S._("Arg_OutOfRange"));
!                               
!                               if ((size < 0) || (size > (buffer.Length - 
offset)))
!                                       throw new ArgumentException("offset", 
S._("Arg_OutOfRange"));                                   
! 
!                               try
                                {
!                                       mysocket.Send(buffer, offset, size, 
SocketFlags.None);
!                               }
!                               catch(Exception e)
!                               {                                       
!                                       throw new 
IOException(S._("IO_SocketWrite"));
                                }
!                       }               
!       
!       public override bool CanRead 
!                       { 
                                get
                                {
!                                       return readaccess;
                                }
                        }
!       
        public override bool CanSeek
                        {
--- 25,209 ----
  using System;
  using System.IO;
+ using System.Threading;
  
  public class NetworkStream : Stream
  {
!       // Internal state.
!       private Socket socket;
!       private FileAccess access;
!       private bool ownsSocket;
! 
!       // Constructors.
        public NetworkStream(Socket socket)
!                       : this(socket, FileAccess.ReadWrite, false)
                        {
!                               // Nothing to do here.
                        }
        public NetworkStream(Socket socket, bool ownsSocket)
!                       : this(socket, FileAccess.ReadWrite, ownsSocket)
                        {
!                               // Nothing to do here.
                        }
        public NetworkStream(Socket socket, FileAccess access)
                        : this(socket, access, false)
                        {
!                               // Nothing to do here.
                        }
        public NetworkStream(Socket socket, FileAccess access, bool ownsSocket)
                        {
!                               // Validate the parameters.
!                               if(socket == null)
!                               {
!                                       throw new 
ArgumentNullException("socket");
!                               }
!                               if(!(socket.Blocking))
!                               {
!                                       throw new 
IOException(S._("IO_SocketNotBlocking"));
!                               }
!                               if(!(socket.Connected))
!                               {
!                                       throw new 
IOException(S._("IO_SocketNotConnected"));
!                               }
!                               if(socket.SocketType != SocketType.Stream)
!                               {
!                                       throw new 
IOException(S._("IO_SocketIncorrectType"));
!                               }
! 
!                               // Initialize the internal state.
!                               this.socket = socket;
!                               this.access = access;
!                               this.ownsSocket = ownsSocket;
                        }
! 
!       // Destructor.
!       ~NetworkStream()
                        {
!                               Dispose(false);
                        }
! 
!       // Handle asynchronous operations by passing them back to the base 
class.
!       // Note: we deliberately don't use the "BeginReceive" and "BeginSend"
!       // methods on "Socket", because those methods will bypass the locking 
and
!       // integrity checks that "NetworkStream" imposes.
!       public override IAsyncResult BeginRead
!                               (byte[] buffer, int offset, int count,
!                                AsyncCallback callback, Object state)
                        {
!                               return base.BeginRead(buffer, offset, count, 
callback, state);
                        }
!       public override int EndRead(IAsyncResult asyncResult)
                        {
!                               return base.EndRead(asyncResult);
                        }
!       public override IAsyncResult BeginWrite
!                               (byte[] buffer, int offset, int count,
!                                AsyncCallback callback, Object state)
                        {
!                               return base.BeginWrite(buffer, offset, count, 
callback, state);
                        }
        public override void EndWrite(IAsyncResult asyncResult)
                        {
!                               base.EndWrite(asyncResult);
                        }
! 
!       // Close this stream.
!       public override void Close()
                        {
!                               Dispose(true);
                        }
! 
!       // Dispose of this stream.
! #if ECMA_COMPAT
!       protected virtual void Dispose(bool disposing)
! #else
!       protected override void Dispose(bool disposing)
! #endif
!                       {
!                               lock(this)
!                               {
!                                       if(socket != null)
!                                       {
!                                               if(ownsSocket)
!                                               {
!                                                       socket.Close();
!                                               }
!                                               socket = null;
!                                       }
!                               }
!                       }
! 
!       // Flush this stream.
        public override void Flush()
                        {
!                               // Nothing to do here.
                        }
! 
!       // Read data from this stream.
!       public override int Read(byte[] buffer, int offset, int count)
                        {
!                               lock(this)
!                               {
!                                       // Validate the stream state first.
!                                       if(socket == null)
!                                       {
!                                               throw new 
ObjectDisposedException
!                                                       
(S._("Exception_Disposed"));
!                                       }
!                                       else if((access & FileAccess.Read) == 0)
!                                       {
!                                               throw new NotSupportedException
!                                                       
(S._("IO_NotSupp_Read"));
!                                       }
  
!                                       // Read directly from the socket.
!                                       return socket.Receive
!                                               (buffer, offset, count, 
SocketFlags.None);
!                               }
!                       }
! 
!       // Seek to a new location in the stream.
        public override long Seek(long offset, SeekOrigin origin)
                        {
!                               throw new 
NotSupportedException(S._("IO_NotSupp_Seek"));
                        }
! 
!       // Set the length of this stream.
!       public override void SetLength(long length)
                        {
!                               throw new 
NotSupportedException(S._("IO_NotSupp_SetLength"));
                        }
  
!       // Write data to this stream.
!       public override void Write(byte[] buffer, int offset, int count)
!                       {
!                               lock(this)
                                {
!                                       // Validate the stream state first.
!                                       if(socket == null)
!                                       {
!                                               throw new 
ObjectDisposedException
!                                                       
(S._("Exception_Disposed"));
!                                       }
!                                       else if((access & FileAccess.Write) == 
0)
!                                       {
!                                               throw new NotSupportedException
!                                                       
(S._("IO_NotSupp_Write"));
!                                       }
! 
!                                       // Write directly to the socket.
!                                       socket.Send(buffer, offset, count, 
SocketFlags.None);
                                }
!                       }
! 
!       // Determine if we can read from this stream.
!       public override bool CanRead
!                       {
                                get
                                {
!                                       return ((access & FileAccess.Read) != 
0);
                                }
                        }
! 
!       // Determine if we can seek within this stream.
        public override bool CanSeek
                        {
***************
*** 208,255 ****
                                }
                        }
!       
        public override bool CanWrite
                        {
                                get
                                {
!                                       return writeaccess;
                                }
                        }
!       
        public virtual bool DataAvailable
                        {
                                get
                                {
!                                       if (mysocket == null)
!                                               throw new 
ObjectDisposedException(S._("Exception_Disposed"));                           
!                                       
!                                       if (mysocket.Available != 0)
!                                               return true;
!                                       else
!                                               return false;           
                                }
                        }
!                       
        public override long Length
                        {
                                get
                                {
!                                       throw new 
NotSupportedException(S._("NotSupp_DerivedStream"));                            
                      
                                }
                        }
!       
        public override long Position
                        {
                                get
                                {
!                                       throw new 
NotSupportedException(S._("NotSupp_DerivedStream"));
                                }
                                set
                                {
!                                       throw new 
NotSupportedException(S._("NotSupp_DerivedStream"));
!                               }                               
!                       }       
! }; // class NetworkStream
  
! }; // namespace System.Net.NetworkStreams
  
--- 213,269 ----
                                }
                        }
! 
!       // Determine if we can write to this stream.
        public override bool CanWrite
                        {
                                get
                                {
!                                       return ((access & FileAccess.Write) != 
0);
                                }
                        }
! 
!       // Determine if the underlying socket has data available.
        public virtual bool DataAvailable
                        {
                                get
                                {
!                                       lock(this)
!                                       {
!                                               if(socket == null)
!                                               {
!                                                       throw new 
ObjectDisposedException
!                                                               
(S._("Exception_Disposed"));
!                                               }
!                                               else
!                                               {
!                                                       return 
(socket.Available > 0);
!                                               }
!                                       }
                                }
                        }
! 
!       // Get the length of this stream.
        public override long Length
                        {
                                get
                                {
!                                       throw new 
NotSupportedException(S._("IO_NotSupp_Seek"));
                                }
                        }
! 
!       // Get or set the position within this stream.
        public override long Position
                        {
                                get
                                {
!                                       throw new 
NotSupportedException(S._("IO_NotSupp_Seek"));
                                }
                                set
                                {
!                                       throw new 
NotSupportedException(S._("IO_NotSupp_Seek"));
!                               }
!                       }
  
! }; // class NetworkStream
  
+ }; // namespace System.Net.Sockets

Index: Socket.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Sockets/Socket.cs,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** Socket.cs   18 Nov 2002 13:05:36 -0000      1.12
--- Socket.cs   3 Apr 2003 05:40:44 -0000       1.13
***************
*** 2,19 ****
   * Socket.cs - Implementation of the "System.Net.Sockets.Socket" class.
   *
!  * Copyright (C) 2002  Southern Storm Software, Pty Ltd.
   *
!  * This program is free software, you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
!  * the Free Software Foundation, either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
[...2553 lines suppressed...]
!                                               ("offset", 
S._("ArgRange_Array"));
!                               }
!                               else if(size < 0)
!                               {
!                                       throw new ArgumentOutOfRangeException
!                                               ("size", S._("ArgRange_Array"));
!                               }
!                               else if((buffer.Length - offset) < size)
!                               {
!                                       throw new 
ArgumentException(S._("Arg_InvalidArrayRange"));
                                }
                        }
***************
*** 799,803 ****
  
  }; // namespace System.Net.Sockets
- 
- 
- 
--- 1787,1788 ----

Index: SocketOptionName.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Net/Sockets/SocketOptionName.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** SocketOptionName.cs 2 Apr 2003 07:16:00 -0000       1.2
--- SocketOptionName.cs 3 Apr 2003 05:40:44 -0000       1.3
***************
*** 49,53 ****
        // Options for SocketOptionLevel.Udp.
        NoChecksum                              = 0x00000001,
!       ChecksumCoveragei               = 0x00000014,
  
        // Options for SocketOptionLevel.Socket.
--- 49,53 ----
        // Options for SocketOptionLevel.Udp.
        NoChecksum                              = 0x00000001,
!       ChecksumCoverage                = 0x00000014,
  
        // Options for SocketOptionLevel.Socket.





reply via email to

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