rename all jvm-only files to jvm.cs
authorAndrew Skiba <andrews@mono-cvs.ximian.com>
Wed, 8 Nov 2006 15:45:46 +0000 (15:45 -0000)
committerAndrew Skiba <andrews@mono-cvs.ximian.com>
Wed, 8 Nov 2006 15:45:46 +0000 (15:45 -0000)
svn path=/trunk/mcs/; revision=67540

18 files changed:
1  2 
mcs/class/System/System.Diagnostics/Debugger.jvm.cs
mcs/class/System/System.Diagnostics/StackFrame.jvm.cs
mcs/class/System/System.Diagnostics/StackTrace.jvm.cs
mcs/class/System/System.Net.Sockets/GHSocket.cs
mcs/class/System/System.Net.Sockets/GHSocket.jvm.cs
mcs/class/System/System.Net.Sockets/GHSocketFactory.cs
mcs/class/System/System.Net.Sockets/GHSocketFactory.jvm.cs
mcs/class/System/System.Net.Sockets/GHStreamSocket.cs
mcs/class/System/System.Net.Sockets/GHStreamSocket.jvm.cs
mcs/class/System/System.Net.Sockets/GHStreamSocketSSL.cs
mcs/class/System/System.Net.Sockets/GHStreamSocketSSL.jvm.cs
mcs/class/System/System.Net/HttpProvider.cs
mcs/class/System/System.Net/HttpProvider.jvm.cs
mcs/class/System/System.Net/HttpStateCache.cs
mcs/class/System/System.Net/HttpStateCache.jvm.cs
mcs/class/System/System.Net/VMWHttpProvider.cs
mcs/class/System/System.Net/VMWHttpProvider.jvm.cs
mcs/class/System/System20.vmwcsproj

index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..d2e2440c55262f83ca83cd688a93dfccb8a31217
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,94 @@@
++//\r\r
++// System.Diagnostics.Debugger.cs\r\r
++//\r\r
++// Author:\r\r
++//    John R. Hicks (angryjohn69@nc.rr.com)\r\r
++//\r\r
++// (C) 2001\r\r
++//\r\r
++using System;\r\r
++\r\r
++namespace System.Diagnostics\r\r
++{\r\r
++      /// <summary>\r\r
++      /// Enables communication with a debugger.\r\r
++      /// </summary>\r\r
++      [MonoTODO]\r\r
++      public sealed class Debugger\r\r
++      {\r\r
++              private static bool isAttached;\r\r
++              \r\r
++              /// <summary>\r\r
++              /// Represents the default category of a message with a constant.\r\r
++              /// </summary>\r\r
++              public static readonly string DefaultCategory = "";\r\r
++              \r\r
++              /// <summary>\r\r
++              /// Returns a Boolean indicating whether a debugger is attached to a process.\r\r
++              /// </summary>\r\r
++              /// <value>\r\r
++              /// true if debugger is attached; otherwise, false.\r\r
++              /// </value>\r\r
++              public static bool IsAttached\r\r
++              {\r\r
++                      get\r\r
++                      {\r\r
++                              return isAttached;\r\r
++                      }\r\r
++              }\r\r
++              \r\r
++              /// <summary>\r\r
++              /// Causes a breakpoint to be signaled to an attached debugger.\r\r
++              /// </summary>\r\r
++              [MonoTODO]\r\r
++              public static void Break()\r\r
++              {\r\r
++                      throw new NotImplementedException();\r\r
++              }\r\r
++              \r\r
++              /// <summary>\r\r
++              /// Checks to see if logging is enabled by an attached debugger.\r\r
++              /// </summary>\r\r
++              [MonoTODO]\r\r
++              public static bool IsLogging()\r\r
++              {\r\r
++                      // Return false. DefaultTraceListener invokes this method, so throwing\r\r
++                      // a NotImplementedException wouldn't be appropriate.\r\r
++      return false;\r\r
++\r\r
++              }\r\r
++              \r\r
++              /// <summary>\r\r
++              /// Launches and attaches a debugger to the process.\r\r
++              /// </summary>\r\r
++              [MonoTODO]\r\r
++              public static bool Launch()\r\r
++              {\r\r
++                      throw new NotImplementedException();\r\r
++              }\r\r
++              \r\r
++              /// <summary>\r\r
++              /// Posts a message for the attached debugger.\r\r
++              /// </summary>\r\r
++              /// <param name="level">\r\r
++              /// A description of the importance of this message\r\r
++              /// </param>\r\r
++              /// <param name="category">\r\r
++              /// A string describing the category of this message.\r\r
++              /// </param>\r\r
++              /// <param name="message">\r\r
++              /// A string representing the message to show.\r\r
++              /// </param>\r\r
++              [MonoTODO]\r\r
++              public static void Log(int level, string category, string message)\r\r
++              {\r\r
++                      // Do nothing. DefaultTraceListener invokes this method, so throwing\r\r
++                      // a NotImplementedException wouldn't be appropriate.\r\r
++              }\r\r
++              \r\r
++              public Debugger()\r\r
++              {\r\r
++                      isAttached = false;\r\r
++              }\r\r
++      }\r\r
++}\r\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..f752a68c6f1635ce6420818070eccc5b3f10360e
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,347 @@@
++//\r
++// System.Diagnostics.StackFrame.cs\r
++//\r
++// Author:\r
++//      Alexander Klyubin (klyubin@aqris.com)\r
++//      Dietmar Maurer (dietmar@ximian.com)\r
++//\r
++// (C) 2001\r
++//\r
++\r
++using System;\r
++using System.Reflection;\r
++using System.Runtime.CompilerServices;\r
++\r
++namespace System.Diagnostics {\r
++        /// <summary>\r
++        ///   Stack frame.\r
++        /// </summary>\r
++\r
++      [Serializable]\r
++        public class StackFrame {\r
++                /// <value>\r
++                ///   Constant returned when the native or IL offset is unknown.\r
++                /// </value>\r
++                public const int OFFSET_UNKNOWN = -1;\r
++                \r
++                /// <value>\r
++                ///   Offset from the start of the IL code for the method\r
++                ///   being executed.\r
++                /// </value>\r
++                private int ilOffset = OFFSET_UNKNOWN;\r
++                \r
++                /// <value>\r
++                ///   Offset from the start of the native code for the method\r
++                ///   being executed.\r
++                /// </value>\r
++                private int nativeOffset = OFFSET_UNKNOWN;\r
++\r
++                /// <value>\r
++                ///   Method associated with this stack frame.\r
++                /// </value>\r
++                private MethodBase methodBase;\r
++                \r
++                /// <value>\r
++                ///   File name.\r
++                /// </value>\r
++                private string fileName;\r
++                \r
++                /// <value>\r
++                ///   Line number.\r
++                /// </value>\r
++                private int lineNumber;\r
++                \r
++                /// <value>\r
++                ///   Column number.\r
++                /// </value>\r
++                private int columnNumber;\r
++#if TARGET_JVM\r
++              static bool get_frame_info (int skip, bool needFileInfo, out MethodBase method,\r
++                      out int iloffset, out int native_offset,\r
++                      out string file, out int line, out int column)\r
++              {\r
++                      native_offset = 0;\r
++                      line = 0;\r
++                      column = 0;\r
++                      file = "";\r
++                      iloffset = 0;\r
++                      method = null;\r
++                      return false;\r
++              }\r
++#else\r
++              [MethodImplAttribute(MethodImplOptions.InternalCall)]\r
++              extern static bool get_frame_info (int skip, bool needFileInfo, out MethodBase method,\r
++                                                 out int iloffset, out int native_offset,\r
++                                                 out string file, out int line, out int column);\r
++#endif\r
++              /// <summary>\r
++                ///   Initializes a new StackFrame object corresponding to the\r
++                ///   active stack frame.\r
++                /// </summary>\r
++                public StackFrame() \r
++                              {\r
++                      get_frame_info (2, false, out methodBase, out ilOffset,\r
++                                      out nativeOffset, out fileName, out lineNumber,\r
++                                      out columnNumber);                      \r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Initializes a new StackFrame object corresponding to the\r
++                ///   active stack frame.\r
++                /// </summary>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackFrame(bool needFileInfo) : this() {\r
++                      get_frame_info (2, needFileInfo, out methodBase, out ilOffset,\r
++                                      out nativeOffset, out fileName, out lineNumber,\r
++                                      out columnNumber);                      \r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Initializes a new StackFrame object corresponding to the\r
++                ///   active stack frame.\r
++                /// </summary>\r
++                /// <param name="skipFrames">\r
++                ///   The number of frames up the stack to skip.\r
++                /// </param>\r
++                public StackFrame(int skipFrames) {\r
++                      get_frame_info (skipFrames + 2, false, out methodBase, out ilOffset,\r
++                                      out nativeOffset, out fileName, out lineNumber,\r
++                                      out columnNumber);                      \r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Initializes a new StackFrame object corresponding to the\r
++                ///   active stack frame.\r
++                /// </summary>\r
++                /// <param name="skipFrames">\r
++                ///   The number of frames up the stack to skip.\r
++                /// </param>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackFrame(int skipFrames, bool needFileInfo) {\r
++                      get_frame_info (skipFrames + 2, needFileInfo, out methodBase, out ilOffset,\r
++                                      out nativeOffset, out fileName, out lineNumber,\r
++                                      out columnNumber);\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Constructs a fake stack frame that just contains the\r
++                ///   given file name and line number. Use this constructor\r
++                ///   when you do not want to use the debugger's line mapping\r
++                ///   logic.\r
++                /// </summary>\r
++                /// <param name="fileName">\r
++                ///   The given file name.\r
++                /// </param>\r
++                /// <param name="lineNumber">\r
++                ///   The line number in the specified file.\r
++                /// </param>\r
++                              // LAMESPEC: According to the MSDN docs, this creates a\r
++                              // fake stack frame. But MS fills out the frame info as well\r
++                public StackFrame(string fileName, int lineNumber) {\r
++                                      get_frame_info (2, false, out methodBase, out ilOffset,\r
++                                                                      out nativeOffset, out fileName, out lineNumber,\r
++                                                                      out columnNumber);\r
++                                      this.fileName = fileName;\r
++                                      this.lineNumber = lineNumber;\r
++                                      this.columnNumber = 0;\r
++                              }\r
++                \r
++                /// <summary>\r
++                ///   Constructs a fake stack frame that just contains the\r
++                ///   given file name and line number. Use this constructor\r
++                ///   when you do not want to use the debugger's line mapping\r
++                ///   logic.\r
++                /// </summary>\r
++                /// <param name="fileName">\r
++                ///   The given file name.\r
++                /// </param>\r
++                /// <param name="lineNumber">\r
++                ///   The line number in the specified file.\r
++                /// </param>\r
++                /// <param name="colNumber">\r
++                ///   The column number in the specified file.\r
++                /// </param>\r
++                              // LAMESPEC: According to the MSDN docs, this creates a\r
++                              // fake stack frame. But MS fills out the frame info as well\r
++                public StackFrame(string fileName,\r
++                                  int lineNumber,\r
++                                  int colNumber) {\r
++                                      get_frame_info (2, false, out methodBase, out ilOffset,\r
++                                                                      out nativeOffset, out fileName, out lineNumber,\r
++                                                                      out columnNumber);\r
++                                      this.fileName = fileName;\r
++                                      this.lineNumber = lineNumber;\r
++                                      this.columnNumber = colNumber;\r
++                }\r
++                                  \r
++                              \r
++                /// <summary>\r
++                ///   Gets the line number in the file containing the code\r
++                ///   being executed. This information is typically extracted\r
++                ///   from the debugging symbols for the executable.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   The file line number or zero if it cannot be determined.\r
++                /// </returns>\r
++                public virtual int GetFileLineNumber()\r
++                {\r
++                        return lineNumber;\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Gets the column number in the file containing the code\r
++                ///   being executed. This information is typically extracted\r
++                ///   from the debugging symbols for the executable.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   The file column number or zero if it cannot be determined.\r
++                /// </returns>\r
++                public virtual int GetFileColumnNumber()\r
++                {\r
++                        return columnNumber;\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Gets the file name containing the code being executed.\r
++                ///   This information is typically extracted from the\r
++                ///   debugging symbols for the executable.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   The file name or null if it cannot be determined.\r
++                /// </returns> \r
++                public virtual string GetFileName()\r
++                {\r
++                        return fileName;\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Gets the offset from the start of the IL code for the\r
++                ///   method being executed. This offset may be approximate\r
++                ///   depending on whether the JIT compiler is generating\r
++                ///   debugging code or not.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   The offset from the start of the IL code for the method\r
++                ///   being executed.\r
++                /// </returns>\r
++                public virtual int GetILOffset()\r
++                {\r
++                        return ilOffset;\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Gets the method in which the frame is executing.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   The method the frame is executing in.\r
++                /// </returns>\r
++                public virtual MethodBase GetMethod()\r
++                {\r
++                        return methodBase;\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Gets the offset from the start of the native\r
++                ///   (JIT-compiled) code for the method being executed.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   The offset from the start of the native (JIT-compiled)\r
++                ///   code or the method being executed.\r
++                /// </returns>\r
++                public virtual int GetNativeOffset()\r
++                {\r
++                        return nativeOffset;                        \r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Builds a readable representation of the stack frame.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   A readable representation of the stack frame.\r
++                /// </returns>\r
++                public override string ToString() {\r
++                        string methodNameString =\r
++                                (GetMethod() == null)\r
++                                        ? "<unknown method>"\r
++                                          : GetMethod().Name;\r
++                        string offsetString =\r
++                                (GetILOffset() == OFFSET_UNKNOWN)\r
++                                        ? "<unknown offset>"\r
++                                          : "offset " + GetILOffset();\r
++                        string fileNameString =\r
++                                (GetFileName() == null)\r
++                                        ? "<filename unknown>" : GetFileName();\r
++                        return methodNameString + " at " + offsetString\r
++                                + " in file:line:column " + fileNameString\r
++                                + ":" + GetFileLineNumber()\r
++                                + ":" + GetFileColumnNumber();\r
++                }\r
++                \r
++                public override bool Equals(Object obj) {\r
++                        if ((obj == null) || (!(obj is StackFrame))) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        StackFrame rhs = (StackFrame) obj;\r
++                        \r
++                        if (!ObjectsEqual(GetMethod(), rhs.GetMethod())) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        if (!ObjectsEqual(GetFileName(), rhs.GetFileName())) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        if (GetFileLineNumber() != rhs.GetFileLineNumber()) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        if (GetFileColumnNumber() != rhs.GetFileColumnNumber()) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        if (GetILOffset() != rhs.GetILOffset()) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        if (GetNativeOffset() != rhs.GetNativeOffset()) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        return true;\r
++                        \r
++                }\r
++                \r
++                public override int GetHashCode() {\r
++                        return GetFileLineNumber();\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Checks whether two objects are equal.\r
++                ///   The objects are assumed equal if and only if either\r
++                ///   both of the references are <code>null</code> or they\r
++                ///   equal via <code>Equals</code> method.\r
++                /// </summary>\r
++                /// <param name="obj1">\r
++                ///   First object.\r
++                /// </param>\r
++                /// <param name="obj2">\r
++                ///   Second object.\r
++                /// </param>\r
++                /// <returns>\r
++                ///   <code>true</code> if the two objects are equal,\r
++                ///   </code>false</code> otherwise.\r
++                /// </returns>\r
++                private static bool ObjectsEqual(Object obj1, Object obj2) {\r
++                        if (obj1 == null) {\r
++                                return (obj2 == null);\r
++                        } else {\r
++                                return obj1.Equals(obj2);\r
++                        }\r
++                }\r
++         }\r
++}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..191e38a2cef6d4031983bb7ea2eaf96b05b4cf83
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,287 @@@
++//\r
++// System.Diagnostics.StackTrace.cs\r
++//\r
++// Author:\r
++//      Alexander Klyubin (klyubin@aqris.com)\r
++//      Dietmar Maurer (dietmar@ximian.com)\r
++//\r
++// (C) 2001\r
++//\r
++\r
++using System;\r
++using System.Reflection;\r
++using System.Threading;\r
++using System.Runtime.CompilerServices;\r
++using System.Collections;\r
++\r
++namespace System.Diagnostics {\r
++        /// <summary>\r
++        ///   Stack trace.\r
++        ///   TODO: more information.\r
++        /// </summary>\r
++        [Serializable]\r
++      public class StackTrace {\r
++                /// <value>\r
++                ///   Uses a constant to define the number of methods that are\r
++                ///   to be omitted from the stack trace.\r
++                /// </value>\r
++                public const int METHODS_TO_SKIP = 0;\r
++                \r
++                /// <value>\r
++                ///   Frames. First frame is the last stack frame pushed.\r
++                /// </value>\r
++                private StackFrame[] frames;\r
++\r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class.\r
++                /// </summary>\r
++              [MonoTODO]\r
++                public StackTrace() {\r
++                      init_frames (METHODS_TO_SKIP, false);\r
++              }\r
++                \r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class.\r
++                /// </summary>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackTrace(bool needFileInfo) {\r
++                      init_frames (METHODS_TO_SKIP, needFileInfo);\r
++              }\r
++\r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class\r
++                ///   from the current location, in a caller's frame.\r
++                /// </summary>\r
++                /// <param name="skipFrames">\r
++                ///   The number of frames up the stack to start the trace\r
++                ///   from.\r
++                /// </param>\r
++                public StackTrace(int skipFrames) {\r
++                      init_frames (skipFrames, false);\r
++              }\r
++\r
++              /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class\r
++                ///   from the current location, in a caller's frame.\r
++                /// </summary>\r
++                /// <param name="skipFrames">\r
++                ///   The number of frames up the stack to start the trace\r
++                ///   from.\r
++                /// </param>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackTrace(int skipFrames, bool needFileInfo) {\r
++                      init_frames (skipFrames, needFileInfo);\r
++              }\r
++\r
++              void init_frames (int skipFrames, bool needFileInfo)\r
++              {\r
++                      StackFrame sf;\r
++                      ArrayList al = new ArrayList ();\r
++\r
++                      skipFrames += 2;\r
++                      \r
++                      while ((sf = new StackFrame (skipFrames, needFileInfo)) != null &&\r
++                             sf.GetMethod () != null) {\r
++                              \r
++                              al.Add (sf);\r
++                              skipFrames++;\r
++                      };\r
++\r
++                        frames = (StackFrame [])al.ToArray (typeof (StackFrame));\r
++              }\r
++#if TARGET_JVM\r
++              static StackFrame [] get_trace (Exception e, int skipFrames, bool needFileInfo)\r
++              {\r
++                      return null;\r
++              }\r
++#else\r
++              [MethodImplAttribute(MethodImplOptions.InternalCall)]\r
++              extern static StackFrame [] get_trace (Exception e, int skipFrames, bool needFileInfo);\r
++#endif\r
++              /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class.\r
++                /// </summary>\r
++                /// <param name="e">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackTrace(Exception e) \r
++                              {\r
++                        frames = get_trace (e, METHODS_TO_SKIP, false);\r
++                }\r
++                                \r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class,\r
++                ///   using the provided exception object. The resulting stack\r
++                ///   trace describes the stack at the time of the exception.\r
++                /// </summary>\r
++                /// <param name="e">\r
++                ///   TODO:\r
++                /// </param>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackTrace(Exception e, bool needFileInfo) {\r
++                        frames = get_trace (e, METHODS_TO_SKIP, needFileInfo);\r
++              }\r
++                \r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class,\r
++                ///   using the provided exception object. The resulting stack\r
++                ///   trace describes the stack at the time of the exception.\r
++                /// </summary>\r
++                /// <param name="e">\r
++                ///   Exception.\r
++                /// </param>\r
++                /// <param name="skipFrames">\r
++                ///   The number of frames up the stack to start the trace\r
++                ///   from.\r
++                /// </param>\r
++                public StackTrace(Exception e, int skipFrames) {\r
++                        frames = get_trace (e, skipFrames, false);\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class,\r
++                ///   using the provided exception object. The resulting stack\r
++                ///   trace describes the stack at the time of the exception.\r
++                /// </summary>\r
++                /// <param name="e">\r
++                ///   Exception.\r
++                /// </param>\r
++                /// <param name="skipFrames">\r
++                ///   The number of frames up the stack to start the trace\r
++                ///   from.\r
++                /// </param>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++                public StackTrace(Exception e, int skipFrames, bool needFileInfo) {\r
++                        frames = get_trace (e, skipFrames, needFileInfo);\r
++              }\r
++                              \r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class\r
++                ///   containing a single frame.\r
++                /// </summary>\r
++                /// <param name="frame">\r
++                ///   The frame that the StackTrace object should contain.\r
++                /// </param>\r
++                public StackTrace(StackFrame frame) {\r
++                        this.frames = new StackFrame[1];\r
++                        this.frames[0] = frame;\r
++                }\r
++                               \r
++                /// <summary>\r
++                ///   Initializes a new instance of the StackTrace class.\r
++                /// </summary>\r
++                /// <param name="targetThread">\r
++                ///   TODO:\r
++                /// </param>\r
++                /// <param name="needFileInfo">\r
++                ///   TODO:\r
++                /// </param>\r
++              [MonoTODO]\r
++                public StackTrace(Thread targetThread, bool needFileInfo) {\r
++                        throw new NotImplementedException();\r
++                }\r
++               \r
++                /// <summary>\r
++                ///   Holds the number of frames in the stack trace.\r
++                /// </summary>\r
++                public virtual int FrameCount {\r
++                        get {\r
++                                return (frames == null) ? 0 : frames.Length;\r
++                        }\r
++                }             \r
++                              \r
++                /// <summary>\r
++                ///   Gets the specified stack frame.\r
++                /// </summary>\r
++                /// <param name="index">\r
++                ///   The index of the stack frame requested.\r
++                /// </param>\r
++                /// <returns>\r
++                ///   The specified stack frame. Returns <code>null</code> if\r
++                ///   frame with specified index does not exist in this stack\r
++                ///   trace.\r
++                /// </returns>\r
++                /// <remarks>\r
++                ///   Stack frames are numbered starting at zero, which is the\r
++                ///   last stack frame pushed.\r
++                /// </remarks>\r
++                public virtual StackFrame GetFrame(int index) {\r
++                        if ((index < 0) || (index >= FrameCount)) {\r
++                                return null;\r
++                        }\r
++                        \r
++                        return frames[index];\r
++                }              \r
++                \r
++                /// <summary>\r
++                ///   Builds a readable representation of the stack trace.\r
++                /// </summary>\r
++                /// <returns>\r
++                ///   A readable representation of the stack trace.\r
++                /// </returns>\r
++                public override string ToString() {\r
++                        string result = "";\r
++                        for (int i = 0; i < FrameCount; i++) {\r
++                                StackFrame frame = GetFrame(i);\r
++                                result += "\n\tat " + FrameToString(frame);\r
++                        }\r
++                        \r
++                        return result;\r
++                }\r
++                \r
++                public override bool Equals(Object obj) {\r
++                        if ((obj == null) || (!(obj is StackTrace))) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        StackTrace rhs = (StackTrace) obj;\r
++                        \r
++                        if (FrameCount != rhs.FrameCount) {\r
++                                return false;\r
++                        }\r
++                        \r
++                        for (int i = 0; i < FrameCount; i++) {\r
++                                if (!GetFrame(i).Equals(rhs.GetFrame(i))) {\r
++                                        return false;\r
++                                }\r
++                        }\r
++                        \r
++                        return true;\r
++                }\r
++                \r
++                public override int GetHashCode() {\r
++                        return FrameCount;\r
++                }\r
++                \r
++                /// <summary>\r
++                ///   Converts single stack frame to string to be used in\r
++                ///   ToString method.\r
++                /// </summary>\r
++                /// <param name="frame">\r
++                ///   Frame to convert.\r
++                /// </param>\r
++                /// <returns>\r
++                ///   A readable representation of stack frame for using\r
++                ///   ToString.\r
++                /// </returns>\r
++                private static String FrameToString(StackFrame frame) {\r
++                      MethodBase method = frame.GetMethod();\r
++                        if (method != null) {\r
++                                // Method information available\r
++                                return  method.DeclaringType.FullName\r
++                                        + "." + method.Name + "()";\r
++                        } else {\r
++                                // Method information not available\r
++                                return "<unknown method>";\r
++                        }\r
++                }\r
++        }\r
++}\r
diff --cc mcs/class/System/System.Net.Sockets/GHSocket.cs
index 616cac1f3c8197fa82390a80624e0190bb2dd8be,616cac1f3c8197fa82390a80624e0190bb2dd8be..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,63 -1,63 +1,0 @@@
--using System;\r
--using System.Net;\r
--\r
--namespace System.Net.Sockets\r
--{\r
--      /// <summary>\r
--      /// Summary description for GHSocket.\r
--      /// </summary>\r
--      internal interface GHSocket\r
--      {\r
--              int Available_internal(out int error);\r
--\r
--              void Blocking_internal(bool block, out int error);\r
--\r
--              EndPoint LocalEndPoint_internal(out int error);\r
--\r
--              EndPoint RemoteEndPoint_internal(out int error);\r
--\r
--              GHSocket Accept_internal(out int error);\r
--\r
--              void Bind_internal(EndPoint sa, out int error);\r
--\r
--              void Close_internal(out int error);\r
--\r
--              void Connect_internal(EndPoint sa, out int error);\r
--\r
--              void GetSocketOption_obj_internal(SocketOptionLevel level, SocketOptionName name, \r
--                                                                                                 out object obj_val, out int error);\r
--              \r
--              void GetSocketOption_arr_internal(SocketOptionLevel level, SocketOptionName name, \r
--                                                                                                 ref byte[] byte_val, out int error);\r
--\r
--              int WSAIoctl (int ioctl_code, byte [] input, byte [] output, out int error);\r
--\r
--              void Listen_internal(int backlog, out int error);\r
--\r
--              bool Poll_internal (SelectMode mode, int timeout, Socket source, out int error);\r
--\r
--              int Receive_internal(byte[] buffer,     int offset,     int count, SocketFlags flags,\r
--                                                                        out int error);\r
--\r
--              int RecvFrom_internal(byte[] buffer, int offset, int count,     SocketFlags flags,\r
--                                                 ref SocketAddress sockaddr, out int error);\r
--\r
--              int Send_internal(byte[] buf, int offset,       int count, SocketFlags flags,\r
--                                                                 out int error);\r
--\r
--              int SendTo_internal(byte[] buffer, int offset, int count,\r
--                                               SocketFlags flags,     SocketAddress sa, out int error);\r
--\r
--              void SetSocketOption_internal (SocketOptionLevel level,\r
--                                                                                              SocketOptionName name, object obj_val,\r
--                                                                                              byte [] byte_val, int int_val, out int error);\r
--\r
--              void Shutdown_internal(SocketShutdown how, out int error);\r
--\r
--              void RegisterSelector(java.nio.channels.Selector selector, int mode, Socket source, out int error);\r
--\r
--              bool CheckConnectionFinished();\r
--\r
--              GHSocket ChangeToSSL(EndPoint remote_end);\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..616cac1f3c8197fa82390a80624e0190bb2dd8be
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,63 @@@
++using System;\r
++using System.Net;\r
++\r
++namespace System.Net.Sockets\r
++{\r
++      /// <summary>\r
++      /// Summary description for GHSocket.\r
++      /// </summary>\r
++      internal interface GHSocket\r
++      {\r
++              int Available_internal(out int error);\r
++\r
++              void Blocking_internal(bool block, out int error);\r
++\r
++              EndPoint LocalEndPoint_internal(out int error);\r
++\r
++              EndPoint RemoteEndPoint_internal(out int error);\r
++\r
++              GHSocket Accept_internal(out int error);\r
++\r
++              void Bind_internal(EndPoint sa, out int error);\r
++\r
++              void Close_internal(out int error);\r
++\r
++              void Connect_internal(EndPoint sa, out int error);\r
++\r
++              void GetSocketOption_obj_internal(SocketOptionLevel level, SocketOptionName name, \r
++                                                                                                 out object obj_val, out int error);\r
++              \r
++              void GetSocketOption_arr_internal(SocketOptionLevel level, SocketOptionName name, \r
++                                                                                                 ref byte[] byte_val, out int error);\r
++\r
++              int WSAIoctl (int ioctl_code, byte [] input, byte [] output, out int error);\r
++\r
++              void Listen_internal(int backlog, out int error);\r
++\r
++              bool Poll_internal (SelectMode mode, int timeout, Socket source, out int error);\r
++\r
++              int Receive_internal(byte[] buffer,     int offset,     int count, SocketFlags flags,\r
++                                                                        out int error);\r
++\r
++              int RecvFrom_internal(byte[] buffer, int offset, int count,     SocketFlags flags,\r
++                                                 ref SocketAddress sockaddr, out int error);\r
++\r
++              int Send_internal(byte[] buf, int offset,       int count, SocketFlags flags,\r
++                                                                 out int error);\r
++\r
++              int SendTo_internal(byte[] buffer, int offset, int count,\r
++                                               SocketFlags flags,     SocketAddress sa, out int error);\r
++\r
++              void SetSocketOption_internal (SocketOptionLevel level,\r
++                                                                                              SocketOptionName name, object obj_val,\r
++                                                                                              byte [] byte_val, int int_val, out int error);\r
++\r
++              void Shutdown_internal(SocketShutdown how, out int error);\r
++\r
++              void RegisterSelector(java.nio.channels.Selector selector, int mode, Socket source, out int error);\r
++\r
++              bool CheckConnectionFinished();\r
++\r
++              GHSocket ChangeToSSL(EndPoint remote_end);\r
++      }\r
++}\r
diff --cc mcs/class/System/System.Net.Sockets/GHSocketFactory.cs
index b3ed216b8d7854df9c1ebfae73ea30b808b10ebb,b3ed216b8d7854df9c1ebfae73ea30b808b10ebb..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,198 -1,198 +1,0 @@@
--using System;\r
--using System.Net;\r
--\r
--namespace System.Net.Sockets\r
--{\r
--      /// <summary>\r
--      /// Summary description for GHSocketFactory.\r
--      /// </summary>\r
--      public class GHSocketFactory\r
--      {\r
--              internal static GHSocket Socket_internal(AddressFamily family,\r
--                                                                                               SocketType type,\r
--                                                                                               ProtocolType proto,\r
--                                                                                               out int error)\r
--              {\r
--                      if ( family == AddressFamily.InterNetwork &&\r
--                              //(family == AddressFamily.InterNetwork || family == AddressFamily.InterNetworkV6) &&\r
--                              (type == SocketType.Stream || type == SocketType.Unknown) &&\r
--                              (proto == ProtocolType.Tcp || proto == ProtocolType.Unknown || proto == ProtocolType.Unspecified) )\r
--                      {\r
--                              error = 0;\r
--                              return new GHStreamSocket();\r
--                      }\r
--\r
--                      error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
--                      return null;\r
--              }\r
--\r
--              internal static void Select_internal (ref Socket [] sockets, int microSeconds, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      java.nio.channels.Selector selector = java.nio.channels.Selector.open();\r
--\r
--                      int mode = 0;\r
--                      int count = sockets.Length;\r
--                      for (int i = 0; i < count; i++) \r
--                      {\r
--                              if (sockets [i] == null) \r
--                              { // separator\r
--                                      mode++;\r
--                                      continue;\r
--                              }\r
--\r
--                              GHSocket sock = sockets [i].GHHandle;\r
--                              if (sock == null)\r
--                              {\r
--                                      throw new ArgumentNullException ("GHSocket handle is null");\r
--                              }\r
--\r
--                              sock.RegisterSelector(selector, mode, sockets [i], out error);\r
--                              if (error != 0)\r
--                              {\r
--                                      error = 0;\r
--                                      sockets = null;\r
--                                      CloseSelector(selector);\r
--                                      return;\r
--                              }\r
--                      }\r
--                      \r
--                      sockets = null;\r
--\r
--                      long timeOutMillis = 1;\r
--                      if (microSeconds < 0)\r
--                      {\r
--                              timeOutMillis = 0;\r
--                      } \r
--                      else if (microSeconds > 999)\r
--                      {\r
--                              timeOutMillis = (long)(microSeconds / 1000);\r
--                      }\r
--\r
--                      int readyCount = 0;\r
--                      try\r
--                      {\r
--                              readyCount = selector.select(timeOutMillis);\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Select_internal selector.select - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (readyCount > 0)\r
--                      {\r
--                              try\r
--                              {\r
--                                      sockets = new Socket[readyCount+2];\r
--                                      Socket[] writeList = new Socket[readyCount];\r
--                                      Socket[] errorList = new Socket[readyCount];\r
--\r
--                                      int readListCount = 0;\r
--                                      int writeListCount = 0;\r
--                                      int errorListCount = 0;\r
--\r
--                                      java.util.Set readyKeys = selector.selectedKeys();\r
--                                      java.util.Iterator it = readyKeys.iterator();\r
--\r
--                                      while (it.hasNext()) \r
--                                      {\r
--                                              java.nio.channels.SelectionKey key = (java.nio.channels.SelectionKey)it.next();\r
--                \r
--                                              if (key.isAcceptable() || key.isReadable()) \r
--                                              {\r
--                                                      sockets[readListCount] = (Socket)key.attachment();\r
--                                                      readListCount++;\r
--                                              }\r
--                                              if (key.isWritable()) \r
--                                              {\r
--                                                      writeList[writeListCount] = (Socket)key.attachment();\r
--                                                      writeListCount++;\r
--                                              }\r
--                                              if (key.isConnectable()) \r
--                                              {\r
--                                                      Socket source = (Socket)key.attachment();\r
--                                                      if (source.GHHandle.CheckConnectionFinished())\r
--                                                      {\r
--                                                              writeList[writeListCount] = source;\r
--                                                              writeListCount++;\r
--                                                      }\r
--                                                      else\r
--                                                      {\r
--                                                              errorList[errorListCount] = source;\r
--                                                              errorListCount++;\r
--                                                      }\r
--                                              }\r
--                                      }\r
--\r
--                                      sockets[readListCount] = null;\r
--                                      readListCount++;\r
--                                      for (int i = 0; i < writeListCount; i++, readListCount++)\r
--                                      {\r
--                                              sockets[readListCount] = writeList[i];\r
--                                      }\r
--                                      sockets[readListCount] = null;\r
--                                      readListCount++;\r
--                                      for (int i = 0; i < errorListCount; i++, readListCount++)\r
--                                      {\r
--                                              sockets[readListCount] = errorList[i];\r
--                                      }\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during Select_internal iterate selected keys - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                      }\r
--\r
--                      CloseSelector(selector);\r
--              }\r
--\r
--              internal static void CloseSelector (java.nio.channels.Selector selector)\r
--              {\r
--                      java.util.Set keys = selector.keys();\r
--                      java.util.Iterator it = keys.iterator();\r
--\r
--                      try\r
--                      {\r
--                              selector.close();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during CloseSelector selector.close - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      while (it.hasNext()) \r
--                      {\r
--                              java.nio.channels.SelectionKey key = (java.nio.channels.SelectionKey)it.next();\r
--                              Socket source = (Socket)key.attachment();\r
--                              try\r
--                              {\r
--                                      if (source.Blocking)\r
--                                      {\r
--                                              /*\r
--                                                      A channel must be placed into non-blocking mode before being registered \r
--                                                      with a selector, and may not be returned to blocking mode until it has been \r
--                                                      deregistered. So, I need set the channel back to the blocking mode, if it was\r
--                                                      in blocking mode before select operation\r
--                                              */\r
--                                              source.Blocking = true;\r
--                                      }\r
--                              }\r
--                              catch (Exception be)\r
--                              {\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during CloseSelector source.Blocking - {0}: {1}\n{2}", be.GetType(), be.Message, be.StackTrace);\r
--#endif\r
--                              }\r
--                      }\r
--              }\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b3ed216b8d7854df9c1ebfae73ea30b808b10ebb
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,198 @@@
++using System;\r
++using System.Net;\r
++\r
++namespace System.Net.Sockets\r
++{\r
++      /// <summary>\r
++      /// Summary description for GHSocketFactory.\r
++      /// </summary>\r
++      public class GHSocketFactory\r
++      {\r
++              internal static GHSocket Socket_internal(AddressFamily family,\r
++                                                                                               SocketType type,\r
++                                                                                               ProtocolType proto,\r
++                                                                                               out int error)\r
++              {\r
++                      if ( family == AddressFamily.InterNetwork &&\r
++                              //(family == AddressFamily.InterNetwork || family == AddressFamily.InterNetworkV6) &&\r
++                              (type == SocketType.Stream || type == SocketType.Unknown) &&\r
++                              (proto == ProtocolType.Tcp || proto == ProtocolType.Unknown || proto == ProtocolType.Unspecified) )\r
++                      {\r
++                              error = 0;\r
++                              return new GHStreamSocket();\r
++                      }\r
++\r
++                      error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
++                      return null;\r
++              }\r
++\r
++              internal static void Select_internal (ref Socket [] sockets, int microSeconds, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      java.nio.channels.Selector selector = java.nio.channels.Selector.open();\r
++\r
++                      int mode = 0;\r
++                      int count = sockets.Length;\r
++                      for (int i = 0; i < count; i++) \r
++                      {\r
++                              if (sockets [i] == null) \r
++                              { // separator\r
++                                      mode++;\r
++                                      continue;\r
++                              }\r
++\r
++                              GHSocket sock = sockets [i].GHHandle;\r
++                              if (sock == null)\r
++                              {\r
++                                      throw new ArgumentNullException ("GHSocket handle is null");\r
++                              }\r
++\r
++                              sock.RegisterSelector(selector, mode, sockets [i], out error);\r
++                              if (error != 0)\r
++                              {\r
++                                      error = 0;\r
++                                      sockets = null;\r
++                                      CloseSelector(selector);\r
++                                      return;\r
++                              }\r
++                      }\r
++                      \r
++                      sockets = null;\r
++\r
++                      long timeOutMillis = 1;\r
++                      if (microSeconds < 0)\r
++                      {\r
++                              timeOutMillis = 0;\r
++                      } \r
++                      else if (microSeconds > 999)\r
++                      {\r
++                              timeOutMillis = (long)(microSeconds / 1000);\r
++                      }\r
++\r
++                      int readyCount = 0;\r
++                      try\r
++                      {\r
++                              readyCount = selector.select(timeOutMillis);\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Select_internal selector.select - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (readyCount > 0)\r
++                      {\r
++                              try\r
++                              {\r
++                                      sockets = new Socket[readyCount+2];\r
++                                      Socket[] writeList = new Socket[readyCount];\r
++                                      Socket[] errorList = new Socket[readyCount];\r
++\r
++                                      int readListCount = 0;\r
++                                      int writeListCount = 0;\r
++                                      int errorListCount = 0;\r
++\r
++                                      java.util.Set readyKeys = selector.selectedKeys();\r
++                                      java.util.Iterator it = readyKeys.iterator();\r
++\r
++                                      while (it.hasNext()) \r
++                                      {\r
++                                              java.nio.channels.SelectionKey key = (java.nio.channels.SelectionKey)it.next();\r
++                \r
++                                              if (key.isAcceptable() || key.isReadable()) \r
++                                              {\r
++                                                      sockets[readListCount] = (Socket)key.attachment();\r
++                                                      readListCount++;\r
++                                              }\r
++                                              if (key.isWritable()) \r
++                                              {\r
++                                                      writeList[writeListCount] = (Socket)key.attachment();\r
++                                                      writeListCount++;\r
++                                              }\r
++                                              if (key.isConnectable()) \r
++                                              {\r
++                                                      Socket source = (Socket)key.attachment();\r
++                                                      if (source.GHHandle.CheckConnectionFinished())\r
++                                                      {\r
++                                                              writeList[writeListCount] = source;\r
++                                                              writeListCount++;\r
++                                                      }\r
++                                                      else\r
++                                                      {\r
++                                                              errorList[errorListCount] = source;\r
++                                                              errorListCount++;\r
++                                                      }\r
++                                              }\r
++                                      }\r
++\r
++                                      sockets[readListCount] = null;\r
++                                      readListCount++;\r
++                                      for (int i = 0; i < writeListCount; i++, readListCount++)\r
++                                      {\r
++                                              sockets[readListCount] = writeList[i];\r
++                                      }\r
++                                      sockets[readListCount] = null;\r
++                                      readListCount++;\r
++                                      for (int i = 0; i < errorListCount; i++, readListCount++)\r
++                                      {\r
++                                              sockets[readListCount] = errorList[i];\r
++                                      }\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during Select_internal iterate selected keys - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                      }\r
++\r
++                      CloseSelector(selector);\r
++              }\r
++\r
++              internal static void CloseSelector (java.nio.channels.Selector selector)\r
++              {\r
++                      java.util.Set keys = selector.keys();\r
++                      java.util.Iterator it = keys.iterator();\r
++\r
++                      try\r
++                      {\r
++                              selector.close();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during CloseSelector selector.close - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      while (it.hasNext()) \r
++                      {\r
++                              java.nio.channels.SelectionKey key = (java.nio.channels.SelectionKey)it.next();\r
++                              Socket source = (Socket)key.attachment();\r
++                              try\r
++                              {\r
++                                      if (source.Blocking)\r
++                                      {\r
++                                              /*\r
++                                                      A channel must be placed into non-blocking mode before being registered \r
++                                                      with a selector, and may not be returned to blocking mode until it has been \r
++                                                      deregistered. So, I need set the channel back to the blocking mode, if it was\r
++                                                      in blocking mode before select operation\r
++                                              */\r
++                                              source.Blocking = true;\r
++                                      }\r
++                              }\r
++                              catch (Exception be)\r
++                              {\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during CloseSelector source.Blocking - {0}: {1}\n{2}", be.GetType(), be.Message, be.StackTrace);\r
++#endif\r
++                              }\r
++                      }\r
++              }\r
++      }\r
++}\r
diff --cc mcs/class/System/System.Net.Sockets/GHStreamSocket.cs
index 035de50bf66278b354bc4a62b06b5f112e33be01,035de50bf66278b354bc4a62b06b5f112e33be01..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,1269 -1,1269 +1,0 @@@
--using System;\r
--using System.Net;\r
--using javax.net;\r
--using javax.net.ssl;\r
--using java.security;\r
--\r
--namespace System.Net.Sockets\r
--{\r
--      /// <summary>\r
--      /// Summary description for GHStreamSocket.\r
--      /// </summary>\r
--      internal class GHStreamSocket : GHSocket\r
--      {\r
--              java.net.ServerSocket jServerSocket;\r
--              java.net.Socket jSocket;\r
--              java.nio.channels.ServerSocketChannel jServerSocketChannel;\r
--              java.nio.channels.SocketChannel jSocketChannel;\r
--\r
--              // This field I need because a bug in the java.nio.channels.SocketAdapter, which \r
--              // returns local port 0 if the socket is not connected (even if the socket is bound)\r
--              // so I need temporary use regular socket (not channel socket) to bind it to the \r
--              // local address and use this address in the LocalPoint property and to create the \r
--              // actual client/server channel sockets\r
--              // The bug #5076965 (SocketChannel does not report local address after binding to a wildcard )\r
--              // See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5076965\r
--              java.net.InetSocketAddress jTempLocalSocketAddress;\r
--\r
--              public GHStreamSocket()\r
--              {\r
--                      jSocketChannel = java.nio.channels.SocketChannel.open();\r
--                      jSocket = jSocketChannel.socket();\r
--              }\r
--\r
--              public GHStreamSocket(java.nio.channels.SocketChannel socketChannel)\r
--              {\r
--                      jSocketChannel = socketChannel;\r
--                      jSocket = jSocketChannel.socket();\r
--              }\r
--\r
--              public override int GetHashCode ()\r
--              {\r
--                      if (jSocket == null && jServerSocket == null)\r
--                              return -1;\r
--\r
--                      if (jServerSocket != null) {\r
--                              return jServerSocket.ToString ().GetHashCode ();\r
--                      }\r
--\r
--                      return jSocket.ToString ().GetHashCode ();\r
--              }\r
--\r
--              public int Available_internal(out int error)\r
--              {\r
--                      error = 0;\r
--                      int r = 0;\r
--\r
--                      if (jSocket == null || !jSocket.isConnected())\r
--                      {\r
--                              return r;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              r = jSocket.getInputStream().available();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
--                              r = 0;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Available_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      return r;\r
--              }\r
--\r
--              public void Blocking_internal(bool block, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (jSocket == null && jServerSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              if (jServerSocket != null)\r
--                              {\r
--                                      jServerSocketChannel.configureBlocking(block);\r
--                              }\r
--                              else\r
--                              {\r
--                                      jSocketChannel.configureBlocking(block);\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Blocking_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public EndPoint LocalEndPoint_internal(out int error)\r
--              {\r
--                      error = 0;\r
--                      java.net.InetSocketAddress localAddr = null;\r
--\r
--                      try\r
--                      {\r
--                              if (jTempLocalSocketAddress != null)\r
--                              {\r
--                                      localAddr = jTempLocalSocketAddress;\r
--                              }\r
--                              else if (jServerSocket != null)\r
--                              {\r
--                                      localAddr = (java.net.InetSocketAddress)jServerSocket.getLocalSocketAddress();\r
--                              }\r
--                              else\r
--                              {\r
--                                      localAddr = (java.net.InetSocketAddress)jSocket.getLocalSocketAddress();\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              localAddr = null;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during LocalEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (localAddr == null || localAddr.getAddress() == null || localAddr.getPort() < 0)\r
--                      {\r
--                return null;\r
--                      }\r
--\r
--                      IPHostEntry lipa = Dns.Resolve(localAddr.getHostName());\r
--                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], localAddr.getPort());\r
--                      return ret;\r
--              }\r
--\r
--              public EndPoint RemoteEndPoint_internal(out int error)\r
--              {\r
--                      error = 0;\r
--                      java.net.InetSocketAddress remoteAddr = null;\r
--\r
--                      if (jSocket == null || !jSocket.isBound())\r
--                      {\r
--                              return null;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              remoteAddr = (java.net.InetSocketAddress)jSocket.getRemoteSocketAddress();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              remoteAddr = null;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during RemoteEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (remoteAddr == null || remoteAddr.getAddress() == null || remoteAddr.getPort() <= 0)\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return null;\r
--                      }\r
--\r
--                      IPHostEntry lipa = Dns.Resolve(remoteAddr.getHostName());\r
--                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], remoteAddr.getPort());\r
--                      return ret;\r
--              }\r
--\r
--              public GHSocket Accept_internal(out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (jServerSocket == null)\r
--                      {\r
--                              throw new InvalidOperationException("You must call Bind and Listen before calling Accept.");\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              /*\r
--                                      If this channel is in non-blocking mode then this method will immediately \r
--                                      return null if there are no pending connections. \r
--                                      Otherwise it will block indefinitely until a new connection is \r
--                                      available or an I/O error occurs.                                \r
--                              */\r
--                              java.nio.channels.SocketChannel acceptedSocket = jServerSocketChannel.accept();\r
--                              if (acceptedSocket == null) \r
--                              {\r
--                                      error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
--#if DEBUG\r
--                                      Console.WriteLine("The Accept_internal is in non-blocking mode and no pending connections are available");\r
--#endif\r
--                                      return null;\r
--                              }\r
--\r
--                              return new GHStreamSocket(acceptedSocket);\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10061; //WSAECONNREFUSED (Connection refused)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Accept_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      return null;\r
--              }\r
--\r
--              public void Bind_internal(EndPoint sa, out int error)\r
--              {\r
--                      error = 0;\r
--                      IPEndPoint addr = sa as IPEndPoint;\r
--                      if (addr == null)\r
--                      {\r
--                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket == null || jSocket.isBound() || jSocket.isConnected() || jSocketChannel.isConnectionPending())\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              // This code I need because a bug in the java.nio.channels.SocketAdapter, which \r
--                              // returns local port 0 if the socket is not connected (even if the socket is bound)\r
--                              // so I need temporary use regular socket (not channel socket) to bind it to the \r
--                              // local address and use this address in the LocalPoint property and to create the \r
--                              // actual client/server channel sockets\r
--                              // The bug #5076965 (SocketChannel does not report local address after binding to a wildcard )\r
--                              // See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5076965\r
--                              java.net.Socket jTempSocket = new java.net.Socket();\r
--                              jTempSocket.bind(new java.net.InetSocketAddress(java.net.InetAddress.getByName(addr.Address.ToString()),\r
--                                                                                              addr.Port));\r
--                              jTempLocalSocketAddress = (java.net.InetSocketAddress)jTempSocket.getLocalSocketAddress();\r
--                              jTempSocket.close();\r
--                              jSocket.bind(jTempLocalSocketAddress);\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10048; //WSAEADDRINUSE (Address already in use)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Bind_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public void Close_internal(out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (jServerSocket != null)\r
--                      {\r
--                              try\r
--                              {\r
--                                      jServerSocket.close();\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during Close_internal jServerSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                              try\r
--                              {\r
--                                      jServerSocketChannel.close();\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during Close_internal jServerSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                              jServerSocket = null;\r
--                              jServerSocketChannel = null;\r
--                      }\r
--                      else if (jSocket != null)\r
--                      {\r
--                              try\r
--                              {\r
--                                      jSocket.close();\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during Close_internal jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                              try\r
--                              {\r
--                                      jSocketChannel.close();\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during Close_internal jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                              jSocket = null;\r
--                              jSocketChannel = null;\r
--                      }\r
--              }\r
--\r
--              public void Connect_internal(EndPoint sa, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      IPEndPoint addr = sa as IPEndPoint;\r
--                      if (addr == null)\r
--                      {\r
--                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket.isConnected() || jSocketChannel.isConnectionPending())\r
--                      {\r
--                              error = 10056; //WSAEISCONN (Socket is already connected)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              /*\r
--                               If this channel is in non-blocking mode then an invocation of this method\r
--                               initiates a non-blocking connection operation. If the connection is \r
--                               established immediately, as can happen with a local connection, then this \r
--                               method returns true. Otherwise this method returns false.  \r
--                 If this channel is in blocking mode then an invocation of this method \r
--                               will block until the connection is established or an I/O error occurs. \r
--                               */\r
--                              bool status = jSocketChannel.connect(new java.net.InetSocketAddress(\r
--                                      java.net.InetAddress.getByName(addr.Address.ToString()), \r
--                                      addr.Port));\r
--                              if (!status)\r
--                              {\r
--                                      error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
--                              }\r
--                      }\r
--                      catch (java.nio.channels.AlreadyConnectedException ae)\r
--                      {                               \r
--                              error = 10056; //WSAEISCONN (Socket is already connected)\r
--                      }\r
--                      catch (java.nio.channels.ConnectionPendingException cpe)\r
--                      {                               \r
--                              error = 10036; //WSAEINPROGRESS (Operation now in progress)\r
--                      }\r
--                      catch (java.nio.channels.UnresolvedAddressException uae)\r
--                      {                               \r
--                              error = 10039; //WSAEDESTADDRREQ (Destination address required)\r
--                      }\r
--                      catch (java.nio.channels.UnsupportedAddressTypeException uate)\r
--                      {                               \r
--                              error = 10041; //WSAEPROTOTYPE (Protocol wrong type for socket)\r
--                      }\r
--                      catch (Exception e)\r
--                      {                               \r
--                              error = 10061; //WSAECONNREFUSED (Connection refused)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Connect_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public void Listen_internal(int backlog, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (jSocket == null || !jSocket.isBound())\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket.isConnected() || jSocketChannel.isConnectionPending())\r
--                      {\r
--                              error = 10056; //WSAEISCONN (Socket is already connected)\r
--                              return;\r
--                      }\r
--\r
--                      bool blockMode = jSocketChannel.isBlocking();\r
--                      bool reuseAddr = jSocket.getReuseAddress();\r
--\r
--                      try\r
--                      {\r
--                              jSocket.close();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Listen_internal close old jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              jSocketChannel.close();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Listen_internal close old jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      jSocket = null;\r
--                      jSocketChannel = null;\r
--\r
--                      try\r
--                      {\r
--                              jServerSocketChannel = java.nio.channels.ServerSocketChannel.open();\r
--                              jServerSocket = jServerSocketChannel.socket();\r
--                              jServerSocket.bind(jTempLocalSocketAddress, backlog);\r
--                              jServerSocketChannel.configureBlocking(blockMode);\r
--                              jServerSocket.setReuseAddress(reuseAddr);\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10048; //WSAEADDRINUSE (Address already in use)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Listen_internal create server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public bool Poll_internal (SelectMode mode, int timeout, Socket source, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (mode == SelectMode.SelectError && !jSocketChannel.isConnectionPending())\r
--                      {\r
--                              return false;\r
--                      }\r
--\r
--                      java.nio.channels.Selector selector = java.nio.channels.Selector.open();\r
--                      RegisterSelector(selector, ((mode == SelectMode.SelectRead)?0:1), source, out error);\r
--\r
--                      if (error != 0)\r
--                      {\r
--                              error = 0;\r
--                              GHSocketFactory.CloseSelector(selector);\r
--                              return (mode == SelectMode.SelectError);\r
--                      }\r
--\r
--                      bool retVal = false;\r
--\r
--                      long timeOutMillis = 1;\r
--                      if (timeout < 0)\r
--                      {\r
--                              timeOutMillis = 0;\r
--                      } \r
--                      else if (timeout > 999)\r
--                      {\r
--                              timeOutMillis = (long)(timeout / 1000);\r
--                      }\r
--\r
--                      int readyCount = 0;\r
--                      try\r
--                      {\r
--                              readyCount = selector.select(timeOutMillis);\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Poll_internal selector.select - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (readyCount > 0)\r
--                      {\r
--                              if (jSocket != null && jSocketChannel.isConnectionPending())\r
--                              {\r
--                                      bool status = false;\r
--                                      try\r
--                                      {\r
--                                              status = jSocketChannel.finishConnect();\r
--                                      }\r
--                                      catch (Exception e)\r
--                                      {\r
--#if DEBUG\r
--                                              Console.WriteLine("Caught exception during Poll_internal, finishConnect - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                                      }\r
--                                      if (status)\r
--                                      {\r
--                                              retVal =  (mode != SelectMode.SelectError);\r
--                                      }\r
--                                      else \r
--                                      {\r
--                                              retVal =  (mode == SelectMode.SelectError);\r
--                                      }\r
--                              }\r
--                              else\r
--                              {\r
--                                      retVal =  true;\r
--                              }\r
--                      }\r
--\r
--                      GHSocketFactory.CloseSelector(selector);\r
--\r
--                      return retVal;\r
--              }\r
--\r
--              public void RegisterSelector(java.nio.channels.Selector selector, int mode, Socket source, out int error)\r
--              {\r
--                      error = 0;\r
--                      if (jServerSocket != null)\r
--                      {\r
--                              // only accept operation, which included to the read list, is allowed for server sockets\r
--                              if (mode != 0)\r
--                              {\r
--//                                    error = 10038; //WSAENOTSOCK (Socket operation on nonsocket)\r
--#if DEBUG\r
--                                      Console.WriteLine("RegisterSelector, invalid mode {0} for the server socket", mode);\r
--#endif\r
--                                      return;\r
--                              }\r
--\r
--                              try\r
--                              {\r
--                                      if (jServerSocketChannel.isBlocking())\r
--                                      {\r
--                                              /*\r
--                                                      A channel must be placed into non-blocking mode before being registered \r
--                                                      with a selector, and may not be returned to blocking mode until it has been \r
--                                                      deregistered. \r
--                                              */\r
--                                              jServerSocketChannel.configureBlocking(false);\r
--                                      }\r
--\r
--                                      jServerSocketChannel.register(selector, java.nio.channels.SelectionKey.OP_ACCEPT, source);\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during RegisterSelector, register server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                      }\r
--                      else\r
--                      {\r
--                              try\r
--                              {\r
--                                      int ops = java.nio.channels.SelectionKey.OP_READ;\r
--                                      if (mode > 0)\r
--                                      {\r
--                                              if (jSocketChannel.isConnectionPending())\r
--                                              {\r
--                                                      ops = java.nio.channels.SelectionKey.OP_CONNECT;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      ops = java.nio.channels.SelectionKey.OP_WRITE;\r
--                                              }\r
--                                      }\r
--                                      \r
--                                      if (jSocketChannel.isBlocking())\r
--                                      {\r
--                                              /*\r
--                                                      A channel must be placed into non-blocking mode before being registered \r
--                                                      with a selector, and may not be returned to blocking mode until it has been \r
--                                                      deregistered. \r
--                                              */\r
--                                              jSocketChannel.configureBlocking(false);\r
--                                      }\r
--\r
--                                      jSocketChannel.register(selector, ops, source);\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during RegisterSelector, register client socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                      }\r
--              }\r
--\r
--              public bool CheckConnectionFinished()\r
--              {\r
--                      bool status = true;\r
--                      if (jSocket != null && jSocketChannel.isConnectionPending())\r
--                      {\r
--                              try\r
--                              {\r
--                                      status = jSocketChannel.finishConnect();\r
--                              }\r
--                              catch (Exception e)\r
--                              {\r
--                                      status = false;\r
--#if DEBUG\r
--                                      Console.WriteLine("Caught exception during Poll_internal, finishConnect - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                              }\r
--                      }\r
--\r
--                      return status;\r
--              }\r
--\r
--              public int Receive_internal(byte[] buffer,      int offset,     int count, SocketFlags flags,\r
--                      out int error)\r
--              {\r
--                      error = 0;\r
--                      int ret = 0;\r
--\r
--                      if (jSocket == null)\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return ret;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              if (jSocketChannel.isConnectionPending())\r
--                              {\r
--                                      bool status = jSocketChannel.finishConnect();\r
--                                      if (!status)\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                              Console.WriteLine("Receive_internal, jSocketChannel.finishConnect return false");\r
--#endif\r
--                                              return 0;\r
--                                      }\r
--                              }\r
--                              else if (!jSocketChannel.isConnected())\r
--                              {\r
--                                      error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                                      return ret;\r
--                              }\r
--\r
--                              java.nio.ByteBuffer readBuff = java.nio.ByteBuffer.wrap(vmw.common.TypeUtils.ToSByteArray(buffer), offset, count);\r
--                              ret = jSocketChannel.read(readBuff);\r
--                              if (ret < 0) ret = 0;\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
--                              ret = 0;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Receive_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (ret == 0 && !jSocketChannel.isBlocking())\r
--                      {\r
--                              error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
--                      }\r
--                      return ret;\r
--              }\r
--\r
--              public int RecvFrom_internal(byte[] buffer, int offset, int count,      SocketFlags flags,\r
--                      ref SocketAddress sockaddr, out int error)\r
--              {\r
--                      return Receive_internal(buffer, offset, count, flags, out error);\r
--              }\r
--\r
--              public int Send_internal(byte[] buf, int offset, int count, SocketFlags flags,\r
--                      out int error)\r
--              {\r
--                      error = 0;\r
--                      int ret = 0;\r
--\r
--                      if (jSocket == null)\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return ret;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              if (jSocketChannel.isConnectionPending())\r
--                              {\r
--                                      bool status = jSocketChannel.finishConnect();\r
--                                      if (!status)\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                                              Console.WriteLine("Send_internal, jSocketChannel.finishConnect return false");\r
--#endif\r
--                                              return 0;\r
--                                      }\r
--                              }\r
--                              else if (!jSocketChannel.isConnected())\r
--                              {\r
--                                      error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                                      return ret;\r
--                              }\r
--\r
--                              java.nio.ByteBuffer writeBuff = java.nio.ByteBuffer.wrap(vmw.common.TypeUtils.ToSByteArray(buf), offset, count);\r
--                              ret = jSocketChannel.write(writeBuff);\r
--                              if (ret < 0) ret = 0;\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
--                              ret = 0;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Send_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (ret == 0 && !jSocketChannel.isBlocking())\r
--                      {\r
--                              error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
--                      }\r
--                      return ret;\r
--              }\r
--\r
--              public int SendTo_internal(byte[] buffer, int offset, int count,\r
--                      SocketFlags flags,      SocketAddress sa, out int error)\r
--              {\r
--                      return Send_internal(buffer, offset, count, flags, out error);\r
--              }\r
--\r
--              public void SetSocketOption_internal (SocketOptionLevel level,\r
--                      SocketOptionName name, object obj_val,\r
--                      byte [] byte_val, int int_val, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (byte_val != null)\r
--                      {\r
--                              error = -1;\r
--                              throw new NotImplementedException();\r
--                      }\r
--\r
--                      if (jSocket == null && jServerSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      switch (level)\r
--                      {\r
--                              case SocketOptionLevel.IPv6:\r
--                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      return;\r
--                              case SocketOptionLevel.IP:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                              case SocketOptionLevel.Udp:\r
--                                      if (name == SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      }\r
--                                      else\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                      }\r
--                                      return;\r
--                              case SocketOptionLevel.Tcp:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              bool bval = false;\r
--                              int ival = 0;\r
--                              switch (name)\r
--                              {\r
--                                      case SocketOptionName.DontLinger:\r
--                                              jSocket.setSoLinger(false, 0);\r
--                                              break;\r
--                                      case SocketOptionName.Linger:\r
--                                              LingerOption lval = obj_val as LingerOption;\r
--                                              if (lval != null)\r
--                                              {\r
--                                                      jSocket.setSoLinger(lval.Enabled, lval.LingerTime);\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.KeepAlive:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setKeepAlive(bval);\r
--                                              break;\r
--                                      case SocketOptionName.NoDelay:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setTcpNoDelay(bval);\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveBuffer:\r
--                                              ival = int_val;\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      ival = (int) obj_val;\r
--                                              }\r
--                                              if (jServerSocket != null)\r
--                                              {\r
--                                                      jServerSocket.setReceiveBufferSize(ival);\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      jSocket.setReceiveBufferSize(ival);\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveTimeout:\r
--                                              ival = int_val;\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      ival = (int) obj_val;\r
--                                              }\r
--                                              if (jServerSocket != null)\r
--                                              {\r
--                                                      jServerSocket.setSoTimeout(ival);\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      jSocket.setSoTimeout(ival);\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.ReuseAddress:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              if (jServerSocket != null)\r
--                                              {\r
--                                                      jServerSocket.setReuseAddress(bval);\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      jSocket.setReuseAddress(bval);\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.SendBuffer:\r
--                                              ival = int_val;\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      ival = (int) obj_val;\r
--                                              }\r
--                                              jSocket.setSendBufferSize(ival);\r
--                                              break;\r
--                                      case SocketOptionName.OutOfBandInline:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setOOBInline(bval);\r
--                                              break;\r
--                                      default:\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              break;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              obj_val = null;\r
--                      }\r
--              }\r
--\r
--              public void GetSocketOption_obj_internal(SocketOptionLevel level, SocketOptionName name, \r
--                      out object obj_val, out int error)\r
--              {\r
--                      obj_val = null;\r
--                      error = 0;\r
--\r
--                      if (jSocket == null && jServerSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      switch (level)\r
--                      {\r
--                              case SocketOptionLevel.IPv6:\r
--                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      return;\r
--                              case SocketOptionLevel.IP:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                              case SocketOptionLevel.Udp:\r
--                                      if (name == SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      }\r
--                                      else\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                      }\r
--                                      return;\r
--                              case SocketOptionLevel.Tcp:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              bool bval = false;\r
--                              int ival = 0;\r
--                              switch (name)\r
--                              {\r
--                                      case SocketOptionName.DontLinger:\r
--                                              ival = jSocket.getSoLinger();\r
--                                              if (ival == -1)\r
--                                              {\r
--                                                      obj_val = 1;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      obj_val = 0;\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.Linger:\r
--                                              ival = jSocket.getSoLinger();\r
--                                              if (ival == -1)\r
--                                              {\r
--                                                      ival = 0;\r
--                                              }\r
--                                              LingerOption ret = new LingerOption((ival != 0), ival);\r
--                                              obj_val = ret;\r
--                                              break;\r
--                                      case SocketOptionName.KeepAlive:\r
--                                              bval = jSocket.getKeepAlive();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      case SocketOptionName.NoDelay:\r
--                                              bval = jSocket.getTcpNoDelay();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveBuffer:\r
--                                              if (jServerSocket != null)\r
--                                              {\r
--                                                      ival = jServerSocket.getReceiveBufferSize();\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      ival = jSocket.getReceiveBufferSize();\r
--                                              }\r
--                                              obj_val = ival;\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveTimeout:\r
--                                              if (jServerSocket != null)\r
--                                              {\r
--                                                      ival = jServerSocket.getSoTimeout();\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      ival = jSocket.getSoTimeout();\r
--                                              }\r
--                                              obj_val = ival;\r
--                                              break;\r
--                                      case SocketOptionName.ReuseAddress:\r
--                                              if (jServerSocket != null)\r
--                                              {\r
--                                                      bval = jServerSocket.getReuseAddress();\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = jSocket.getReuseAddress();\r
--                                              }\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      case SocketOptionName.SendBuffer:\r
--                                              ival = jSocket.getSendBufferSize();\r
--                                              obj_val = ival;\r
--                                              break;\r
--                                      case SocketOptionName.OutOfBandInline:\r
--                                              bval = jSocket.getOOBInline();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      default:\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              break;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              obj_val = null;\r
--                      }\r
--              }\r
--              \r
--              public void GetSocketOption_arr_internal(SocketOptionLevel level, SocketOptionName name, \r
--                      ref byte[] byte_val, out int error)\r
--              {\r
--                      error = -1;\r
--                      throw new NotImplementedException();\r
--              }\r
--\r
--              public int WSAIoctl (int ioctl_code, byte [] input, byte [] output, out int error)\r
--              {\r
--                      error = -1;\r
--                      throw new NotImplementedException();\r
--              }\r
--\r
--              public void Shutdown_internal(SocketShutdown how, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (jServerSocket != null || jSocket == null || !jSocket.isConnected())\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              switch (how)\r
--                              {\r
--                                      case SocketShutdown.Receive: \r
--                                                              jSocket.shutdownInput();\r
--                                                              break;\r
--                                      case SocketShutdown.Send: \r
--                                                                              jSocket.shutdownOutput();\r
--                                                                              break;\r
--                                      case SocketShutdown.Both: \r
--                                                                              jSocket.shutdownInput();\r
--                                                                              jSocket.shutdownOutput();\r
--                                                                              break;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Shutdown_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              private java.io.FileInputStream searchDefaultCacerts()\r
--              {\r
--                      try\r
--                      {\r
--                              string javaHome = java.lang.System.getProperty("java.home");\r
--                              if(javaHome == null)\r
--                                      return null;\r
--\r
--                              string keyStorePath = javaHome + "/lib/security/cacerts";\r
--                              //Console.WriteLine("keyStorePath = {0}", keyStorePath);\r
--\r
--                              java.io.File f = new java.io.File(keyStorePath);\r
--                              if(!f.exists())\r
--                                      return null;\r
--                              return new java.io.FileInputStream(f);\r
--                      }\r
--                      catch(Exception e)\r
--                      {\r
--#if DEBUG\r
--                              //todo log it\r
--                              Console.WriteLine(e.GetType() + ":" + e.Message + "\n" + e.StackTrace);\r
--#endif\r
--                              return null;\r
--                      }\r
--              }\r
--\r
--              private SSLSocketFactory getSSLSocketFactory()\r
--              {\r
--                      SSLSocketFactory factory = null;\r
--\r
--                      try\r
--                      {\r
--                              //reading the keyStore path and password from the environment properties\r
--                              string keyStorePath = java.lang.System.getProperty("javax.net.ssl.keyStore");\r
--                              java.io.FileInputStream keyStoreStream = null;\r
--                              if (keyStorePath != null)\r
--                              {\r
--                                      java.io.File file = new java.io.File(keyStorePath);\r
--                                      if(file.exists())\r
--                                              keyStoreStream = new java.io.FileInputStream(file);\r
--                                      else\r
--                                              keyStoreStream = searchDefaultCacerts();\r
--                              }\r
--                              else\r
--                                      keyStoreStream = searchDefaultCacerts();\r
--\r
--                              string keyStorePassWord = java.lang.System.getProperty("javax.net.ssl.keyStorePassword");\r
--                              if (keyStorePassWord == null)\r
--                                      keyStorePassWord = "changeit";\r
--                              char[] passphrase = keyStorePassWord.ToCharArray();                             \r
--                                              \r
--                              //initiating SSLContext\r
--                              SSLContext ctx = SSLContext.getInstance("TLS");\r
--                              KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());\r
--                              TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());\r
--                              KeyStore ks = KeyStore.getInstance("JKS");\r
--                              if (keyStoreStream != null)\r
--                                      ks.load(keyStoreStream,passphrase);\r
--                              else\r
--                                      ks.load(null,null);\r
--                              kmf.init(ks, passphrase);\r
--                              tmf.init(ks);\r
--                              ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);\r
--\r
--                              factory = ctx.getSocketFactory();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              factory = null;\r
--#if DEBUG\r
--                              Console.WriteLine("Can't get SSL Socket Factory, the exception is {0}, {1}", e.GetType(), e.Message);\r
--#endif\r
--                      }\r
--\r
--                      return factory;\r
--              }\r
--\r
--              public GHSocket ChangeToSSL(EndPoint remote_end)\r
--              {\r
--                      if (jSocket == null)\r
--                      {\r
--                              throw new InvalidOperationException("The underlying socket is null");\r
--                      }\r
--\r
--                      if (!jSocketChannel.isBlocking())\r
--                      {\r
--                              throw new NotImplementedException("The SSL Socket for non-blocking mode is not supported");\r
--                      }\r
--\r
--                      SSLSocketFactory factory = getSSLSocketFactory();\r
--                      if (factory == null)\r
--                      {\r
--                              throw new ApplicationException("Can't get SSL Socket Factory");\r
--                      }\r
--\r
--                      int err;\r
--\r
--                      // The problem with local address, when I closed the socket and try to create the new one\r
--                      // bounded to the given local address, I receive exception "Address already in use"\r
--                      IPEndPoint localEndPoint = null;\r
--//                    IPEndPoint localEndPoint = (IPEndPoint) LocalEndPoint_internal(out err);\r
--//                    if (err != 0)\r
--//                            localEndPoint = null;\r
--\r
--                      IPEndPoint remoteEndPoint = remote_end as IPEndPoint;\r
--                      if (remoteEndPoint == null)\r
--                      {\r
--                              remoteEndPoint = (IPEndPoint) RemoteEndPoint_internal(out err);\r
--                              if (err != 0)\r
--                                      remoteEndPoint = null;\r
--                      }\r
--\r
--                      java.net.Socket sslSocket = null;\r
--                      try\r
--                      {\r
--                              if (remoteEndPoint != null)\r
--                              {\r
--                                      if (localEndPoint != null)\r
--                                      {\r
--                                              sslSocket = factory.createSocket(\r
--                                                      java.net.InetAddress.getByName(remoteEndPoint.Address.ToString()),\r
--                                                      remoteEndPoint.Port,\r
--                                                      java.net.InetAddress.getByName(localEndPoint.Address.ToString()),\r
--                                                      localEndPoint.Port);\r
--                                      }\r
--                                      else\r
--                                      {\r
--                                              sslSocket = factory.createSocket(\r
--                                                      jSocket, \r
--                                                      remoteEndPoint.Address.ToString(),\r
--                                                      remoteEndPoint.Port,\r
--                                                      false);\r
--                                      }\r
--\r
--                                      if (sslSocket != null)\r
--                                      {\r
--                                              String[] protocols = { "TLSv1", "SSLv3" };\r
--                                              ((SSLSocket)sslSocket).setUseClientMode(true);\r
--                                              ((SSLSocket)sslSocket).startHandshake();\r
--                                      }\r
--\r
--                              }\r
--                              else\r
--                              {\r
--                                      sslSocket = factory.createSocket();\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              sslSocket = null;\r
--#if DEBUG\r
--                              Console.WriteLine("Can't create SSL Socket, the exception is {0}, {1}", e.GetType(), e.Message);\r
--#endif\r
--                      }\r
--\r
--                      if (sslSocket == null)\r
--                      {\r
--//                            throw new ApplicationException("Can't create SSL Socket");\r
--                              // it is important to the Socket class to distinguish if the underlying \r
--                              // handle (GHSocket) is still valid and can be used as non-SSL, or it is already\r
--                              // closed by this function and can't be used any more.\r
--                              return null;\r
--                      }\r
--\r
--/*\r
--                      string[] arr = ((SSLSocket)sslSocket).getEnabledProtocols();\r
--                      if (arr != null)\r
--                      {\r
--                              foreach (string s in arr)\r
--                                      Console.WriteLine("s:"+s);\r
--                      }\r
--                      string [] arr1 = ((SSLSocket)sslSocket).getEnabledCipherSuites();\r
--                      if (arr1 != null)\r
--                      {\r
--                              foreach (string s in arr1)\r
--                                      Console.WriteLine("s:"+s);\r
--                      }\r
--*/\r
--\r
--                      return new GHStreamSocketSSL(sslSocket);\r
--              }\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..035de50bf66278b354bc4a62b06b5f112e33be01
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,1269 @@@
++using System;\r
++using System.Net;\r
++using javax.net;\r
++using javax.net.ssl;\r
++using java.security;\r
++\r
++namespace System.Net.Sockets\r
++{\r
++      /// <summary>\r
++      /// Summary description for GHStreamSocket.\r
++      /// </summary>\r
++      internal class GHStreamSocket : GHSocket\r
++      {\r
++              java.net.ServerSocket jServerSocket;\r
++              java.net.Socket jSocket;\r
++              java.nio.channels.ServerSocketChannel jServerSocketChannel;\r
++              java.nio.channels.SocketChannel jSocketChannel;\r
++\r
++              // This field I need because a bug in the java.nio.channels.SocketAdapter, which \r
++              // returns local port 0 if the socket is not connected (even if the socket is bound)\r
++              // so I need temporary use regular socket (not channel socket) to bind it to the \r
++              // local address and use this address in the LocalPoint property and to create the \r
++              // actual client/server channel sockets\r
++              // The bug #5076965 (SocketChannel does not report local address after binding to a wildcard )\r
++              // See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5076965\r
++              java.net.InetSocketAddress jTempLocalSocketAddress;\r
++\r
++              public GHStreamSocket()\r
++              {\r
++                      jSocketChannel = java.nio.channels.SocketChannel.open();\r
++                      jSocket = jSocketChannel.socket();\r
++              }\r
++\r
++              public GHStreamSocket(java.nio.channels.SocketChannel socketChannel)\r
++              {\r
++                      jSocketChannel = socketChannel;\r
++                      jSocket = jSocketChannel.socket();\r
++              }\r
++\r
++              public override int GetHashCode ()\r
++              {\r
++                      if (jSocket == null && jServerSocket == null)\r
++                              return -1;\r
++\r
++                      if (jServerSocket != null) {\r
++                              return jServerSocket.ToString ().GetHashCode ();\r
++                      }\r
++\r
++                      return jSocket.ToString ().GetHashCode ();\r
++              }\r
++\r
++              public int Available_internal(out int error)\r
++              {\r
++                      error = 0;\r
++                      int r = 0;\r
++\r
++                      if (jSocket == null || !jSocket.isConnected())\r
++                      {\r
++                              return r;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              r = jSocket.getInputStream().available();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
++                              r = 0;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Available_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      return r;\r
++              }\r
++\r
++              public void Blocking_internal(bool block, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (jSocket == null && jServerSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              if (jServerSocket != null)\r
++                              {\r
++                                      jServerSocketChannel.configureBlocking(block);\r
++                              }\r
++                              else\r
++                              {\r
++                                      jSocketChannel.configureBlocking(block);\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Blocking_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public EndPoint LocalEndPoint_internal(out int error)\r
++              {\r
++                      error = 0;\r
++                      java.net.InetSocketAddress localAddr = null;\r
++\r
++                      try\r
++                      {\r
++                              if (jTempLocalSocketAddress != null)\r
++                              {\r
++                                      localAddr = jTempLocalSocketAddress;\r
++                              }\r
++                              else if (jServerSocket != null)\r
++                              {\r
++                                      localAddr = (java.net.InetSocketAddress)jServerSocket.getLocalSocketAddress();\r
++                              }\r
++                              else\r
++                              {\r
++                                      localAddr = (java.net.InetSocketAddress)jSocket.getLocalSocketAddress();\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              localAddr = null;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during LocalEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (localAddr == null || localAddr.getAddress() == null || localAddr.getPort() < 0)\r
++                      {\r
++                return null;\r
++                      }\r
++\r
++                      IPHostEntry lipa = Dns.Resolve(localAddr.getHostName());\r
++                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], localAddr.getPort());\r
++                      return ret;\r
++              }\r
++\r
++              public EndPoint RemoteEndPoint_internal(out int error)\r
++              {\r
++                      error = 0;\r
++                      java.net.InetSocketAddress remoteAddr = null;\r
++\r
++                      if (jSocket == null || !jSocket.isBound())\r
++                      {\r
++                              return null;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              remoteAddr = (java.net.InetSocketAddress)jSocket.getRemoteSocketAddress();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              remoteAddr = null;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during RemoteEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (remoteAddr == null || remoteAddr.getAddress() == null || remoteAddr.getPort() <= 0)\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return null;\r
++                      }\r
++\r
++                      IPHostEntry lipa = Dns.Resolve(remoteAddr.getHostName());\r
++                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], remoteAddr.getPort());\r
++                      return ret;\r
++              }\r
++\r
++              public GHSocket Accept_internal(out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (jServerSocket == null)\r
++                      {\r
++                              throw new InvalidOperationException("You must call Bind and Listen before calling Accept.");\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              /*\r
++                                      If this channel is in non-blocking mode then this method will immediately \r
++                                      return null if there are no pending connections. \r
++                                      Otherwise it will block indefinitely until a new connection is \r
++                                      available or an I/O error occurs.                                \r
++                              */\r
++                              java.nio.channels.SocketChannel acceptedSocket = jServerSocketChannel.accept();\r
++                              if (acceptedSocket == null) \r
++                              {\r
++                                      error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
++#if DEBUG\r
++                                      Console.WriteLine("The Accept_internal is in non-blocking mode and no pending connections are available");\r
++#endif\r
++                                      return null;\r
++                              }\r
++\r
++                              return new GHStreamSocket(acceptedSocket);\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10061; //WSAECONNREFUSED (Connection refused)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Accept_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      return null;\r
++              }\r
++\r
++              public void Bind_internal(EndPoint sa, out int error)\r
++              {\r
++                      error = 0;\r
++                      IPEndPoint addr = sa as IPEndPoint;\r
++                      if (addr == null)\r
++                      {\r
++                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket == null || jSocket.isBound() || jSocket.isConnected() || jSocketChannel.isConnectionPending())\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              // This code I need because a bug in the java.nio.channels.SocketAdapter, which \r
++                              // returns local port 0 if the socket is not connected (even if the socket is bound)\r
++                              // so I need temporary use regular socket (not channel socket) to bind it to the \r
++                              // local address and use this address in the LocalPoint property and to create the \r
++                              // actual client/server channel sockets\r
++                              // The bug #5076965 (SocketChannel does not report local address after binding to a wildcard )\r
++                              // See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5076965\r
++                              java.net.Socket jTempSocket = new java.net.Socket();\r
++                              jTempSocket.bind(new java.net.InetSocketAddress(java.net.InetAddress.getByName(addr.Address.ToString()),\r
++                                                                                              addr.Port));\r
++                              jTempLocalSocketAddress = (java.net.InetSocketAddress)jTempSocket.getLocalSocketAddress();\r
++                              jTempSocket.close();\r
++                              jSocket.bind(jTempLocalSocketAddress);\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10048; //WSAEADDRINUSE (Address already in use)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Bind_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public void Close_internal(out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (jServerSocket != null)\r
++                      {\r
++                              try\r
++                              {\r
++                                      jServerSocket.close();\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during Close_internal jServerSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                              try\r
++                              {\r
++                                      jServerSocketChannel.close();\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during Close_internal jServerSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                              jServerSocket = null;\r
++                              jServerSocketChannel = null;\r
++                      }\r
++                      else if (jSocket != null)\r
++                      {\r
++                              try\r
++                              {\r
++                                      jSocket.close();\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during Close_internal jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                              try\r
++                              {\r
++                                      jSocketChannel.close();\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during Close_internal jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                              jSocket = null;\r
++                              jSocketChannel = null;\r
++                      }\r
++              }\r
++\r
++              public void Connect_internal(EndPoint sa, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      IPEndPoint addr = sa as IPEndPoint;\r
++                      if (addr == null)\r
++                      {\r
++                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket.isConnected() || jSocketChannel.isConnectionPending())\r
++                      {\r
++                              error = 10056; //WSAEISCONN (Socket is already connected)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              /*\r
++                               If this channel is in non-blocking mode then an invocation of this method\r
++                               initiates a non-blocking connection operation. If the connection is \r
++                               established immediately, as can happen with a local connection, then this \r
++                               method returns true. Otherwise this method returns false.  \r
++                 If this channel is in blocking mode then an invocation of this method \r
++                               will block until the connection is established or an I/O error occurs. \r
++                               */\r
++                              bool status = jSocketChannel.connect(new java.net.InetSocketAddress(\r
++                                      java.net.InetAddress.getByName(addr.Address.ToString()), \r
++                                      addr.Port));\r
++                              if (!status)\r
++                              {\r
++                                      error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
++                              }\r
++                      }\r
++                      catch (java.nio.channels.AlreadyConnectedException ae)\r
++                      {                               \r
++                              error = 10056; //WSAEISCONN (Socket is already connected)\r
++                      }\r
++                      catch (java.nio.channels.ConnectionPendingException cpe)\r
++                      {                               \r
++                              error = 10036; //WSAEINPROGRESS (Operation now in progress)\r
++                      }\r
++                      catch (java.nio.channels.UnresolvedAddressException uae)\r
++                      {                               \r
++                              error = 10039; //WSAEDESTADDRREQ (Destination address required)\r
++                      }\r
++                      catch (java.nio.channels.UnsupportedAddressTypeException uate)\r
++                      {                               \r
++                              error = 10041; //WSAEPROTOTYPE (Protocol wrong type for socket)\r
++                      }\r
++                      catch (Exception e)\r
++                      {                               \r
++                              error = 10061; //WSAECONNREFUSED (Connection refused)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Connect_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public void Listen_internal(int backlog, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (jSocket == null || !jSocket.isBound())\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket.isConnected() || jSocketChannel.isConnectionPending())\r
++                      {\r
++                              error = 10056; //WSAEISCONN (Socket is already connected)\r
++                              return;\r
++                      }\r
++\r
++                      bool blockMode = jSocketChannel.isBlocking();\r
++                      bool reuseAddr = jSocket.getReuseAddress();\r
++\r
++                      try\r
++                      {\r
++                              jSocket.close();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Listen_internal close old jSocket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              jSocketChannel.close();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Listen_internal close old jSocketChannel - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      jSocket = null;\r
++                      jSocketChannel = null;\r
++\r
++                      try\r
++                      {\r
++                              jServerSocketChannel = java.nio.channels.ServerSocketChannel.open();\r
++                              jServerSocket = jServerSocketChannel.socket();\r
++                              jServerSocket.bind(jTempLocalSocketAddress, backlog);\r
++                              jServerSocketChannel.configureBlocking(blockMode);\r
++                              jServerSocket.setReuseAddress(reuseAddr);\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10048; //WSAEADDRINUSE (Address already in use)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Listen_internal create server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public bool Poll_internal (SelectMode mode, int timeout, Socket source, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (mode == SelectMode.SelectError && !jSocketChannel.isConnectionPending())\r
++                      {\r
++                              return false;\r
++                      }\r
++\r
++                      java.nio.channels.Selector selector = java.nio.channels.Selector.open();\r
++                      RegisterSelector(selector, ((mode == SelectMode.SelectRead)?0:1), source, out error);\r
++\r
++                      if (error != 0)\r
++                      {\r
++                              error = 0;\r
++                              GHSocketFactory.CloseSelector(selector);\r
++                              return (mode == SelectMode.SelectError);\r
++                      }\r
++\r
++                      bool retVal = false;\r
++\r
++                      long timeOutMillis = 1;\r
++                      if (timeout < 0)\r
++                      {\r
++                              timeOutMillis = 0;\r
++                      } \r
++                      else if (timeout > 999)\r
++                      {\r
++                              timeOutMillis = (long)(timeout / 1000);\r
++                      }\r
++\r
++                      int readyCount = 0;\r
++                      try\r
++                      {\r
++                              readyCount = selector.select(timeOutMillis);\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Poll_internal selector.select - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (readyCount > 0)\r
++                      {\r
++                              if (jSocket != null && jSocketChannel.isConnectionPending())\r
++                              {\r
++                                      bool status = false;\r
++                                      try\r
++                                      {\r
++                                              status = jSocketChannel.finishConnect();\r
++                                      }\r
++                                      catch (Exception e)\r
++                                      {\r
++#if DEBUG\r
++                                              Console.WriteLine("Caught exception during Poll_internal, finishConnect - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                                      }\r
++                                      if (status)\r
++                                      {\r
++                                              retVal =  (mode != SelectMode.SelectError);\r
++                                      }\r
++                                      else \r
++                                      {\r
++                                              retVal =  (mode == SelectMode.SelectError);\r
++                                      }\r
++                              }\r
++                              else\r
++                              {\r
++                                      retVal =  true;\r
++                              }\r
++                      }\r
++\r
++                      GHSocketFactory.CloseSelector(selector);\r
++\r
++                      return retVal;\r
++              }\r
++\r
++              public void RegisterSelector(java.nio.channels.Selector selector, int mode, Socket source, out int error)\r
++              {\r
++                      error = 0;\r
++                      if (jServerSocket != null)\r
++                      {\r
++                              // only accept operation, which included to the read list, is allowed for server sockets\r
++                              if (mode != 0)\r
++                              {\r
++//                                    error = 10038; //WSAENOTSOCK (Socket operation on nonsocket)\r
++#if DEBUG\r
++                                      Console.WriteLine("RegisterSelector, invalid mode {0} for the server socket", mode);\r
++#endif\r
++                                      return;\r
++                              }\r
++\r
++                              try\r
++                              {\r
++                                      if (jServerSocketChannel.isBlocking())\r
++                                      {\r
++                                              /*\r
++                                                      A channel must be placed into non-blocking mode before being registered \r
++                                                      with a selector, and may not be returned to blocking mode until it has been \r
++                                                      deregistered. \r
++                                              */\r
++                                              jServerSocketChannel.configureBlocking(false);\r
++                                      }\r
++\r
++                                      jServerSocketChannel.register(selector, java.nio.channels.SelectionKey.OP_ACCEPT, source);\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during RegisterSelector, register server socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                      }\r
++                      else\r
++                      {\r
++                              try\r
++                              {\r
++                                      int ops = java.nio.channels.SelectionKey.OP_READ;\r
++                                      if (mode > 0)\r
++                                      {\r
++                                              if (jSocketChannel.isConnectionPending())\r
++                                              {\r
++                                                      ops = java.nio.channels.SelectionKey.OP_CONNECT;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      ops = java.nio.channels.SelectionKey.OP_WRITE;\r
++                                              }\r
++                                      }\r
++                                      \r
++                                      if (jSocketChannel.isBlocking())\r
++                                      {\r
++                                              /*\r
++                                                      A channel must be placed into non-blocking mode before being registered \r
++                                                      with a selector, and may not be returned to blocking mode until it has been \r
++                                                      deregistered. \r
++                                              */\r
++                                              jSocketChannel.configureBlocking(false);\r
++                                      }\r
++\r
++                                      jSocketChannel.register(selector, ops, source);\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during RegisterSelector, register client socket - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                      }\r
++              }\r
++\r
++              public bool CheckConnectionFinished()\r
++              {\r
++                      bool status = true;\r
++                      if (jSocket != null && jSocketChannel.isConnectionPending())\r
++                      {\r
++                              try\r
++                              {\r
++                                      status = jSocketChannel.finishConnect();\r
++                              }\r
++                              catch (Exception e)\r
++                              {\r
++                                      status = false;\r
++#if DEBUG\r
++                                      Console.WriteLine("Caught exception during Poll_internal, finishConnect - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                              }\r
++                      }\r
++\r
++                      return status;\r
++              }\r
++\r
++              public int Receive_internal(byte[] buffer,      int offset,     int count, SocketFlags flags,\r
++                      out int error)\r
++              {\r
++                      error = 0;\r
++                      int ret = 0;\r
++\r
++                      if (jSocket == null)\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return ret;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              if (jSocketChannel.isConnectionPending())\r
++                              {\r
++                                      bool status = jSocketChannel.finishConnect();\r
++                                      if (!status)\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                              Console.WriteLine("Receive_internal, jSocketChannel.finishConnect return false");\r
++#endif\r
++                                              return 0;\r
++                                      }\r
++                              }\r
++                              else if (!jSocketChannel.isConnected())\r
++                              {\r
++                                      error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                                      return ret;\r
++                              }\r
++\r
++                              java.nio.ByteBuffer readBuff = java.nio.ByteBuffer.wrap(vmw.common.TypeUtils.ToSByteArray(buffer), offset, count);\r
++                              ret = jSocketChannel.read(readBuff);\r
++                              if (ret < 0) ret = 0;\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
++                              ret = 0;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Receive_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (ret == 0 && !jSocketChannel.isBlocking())\r
++                      {\r
++                              error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
++                      }\r
++                      return ret;\r
++              }\r
++\r
++              public int RecvFrom_internal(byte[] buffer, int offset, int count,      SocketFlags flags,\r
++                      ref SocketAddress sockaddr, out int error)\r
++              {\r
++                      return Receive_internal(buffer, offset, count, flags, out error);\r
++              }\r
++\r
++              public int Send_internal(byte[] buf, int offset, int count, SocketFlags flags,\r
++                      out int error)\r
++              {\r
++                      error = 0;\r
++                      int ret = 0;\r
++\r
++                      if (jSocket == null)\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return ret;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              if (jSocketChannel.isConnectionPending())\r
++                              {\r
++                                      bool status = jSocketChannel.finishConnect();\r
++                                      if (!status)\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                                              Console.WriteLine("Send_internal, jSocketChannel.finishConnect return false");\r
++#endif\r
++                                              return 0;\r
++                                      }\r
++                              }\r
++                              else if (!jSocketChannel.isConnected())\r
++                              {\r
++                                      error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                                      return ret;\r
++                              }\r
++\r
++                              java.nio.ByteBuffer writeBuff = java.nio.ByteBuffer.wrap(vmw.common.TypeUtils.ToSByteArray(buf), offset, count);\r
++                              ret = jSocketChannel.write(writeBuff);\r
++                              if (ret < 0) ret = 0;\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
++                              ret = 0;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Send_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (ret == 0 && !jSocketChannel.isBlocking())\r
++                      {\r
++                              error = 10035; //WSAEWOULDBLOCK (Resource temporarily unavailable)\r
++                      }\r
++                      return ret;\r
++              }\r
++\r
++              public int SendTo_internal(byte[] buffer, int offset, int count,\r
++                      SocketFlags flags,      SocketAddress sa, out int error)\r
++              {\r
++                      return Send_internal(buffer, offset, count, flags, out error);\r
++              }\r
++\r
++              public void SetSocketOption_internal (SocketOptionLevel level,\r
++                      SocketOptionName name, object obj_val,\r
++                      byte [] byte_val, int int_val, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (byte_val != null)\r
++                      {\r
++                              error = -1;\r
++                              throw new NotImplementedException();\r
++                      }\r
++\r
++                      if (jSocket == null && jServerSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      switch (level)\r
++                      {\r
++                              case SocketOptionLevel.IPv6:\r
++                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      return;\r
++                              case SocketOptionLevel.IP:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                              case SocketOptionLevel.Udp:\r
++                                      if (name == SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      }\r
++                                      else\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                      }\r
++                                      return;\r
++                              case SocketOptionLevel.Tcp:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              bool bval = false;\r
++                              int ival = 0;\r
++                              switch (name)\r
++                              {\r
++                                      case SocketOptionName.DontLinger:\r
++                                              jSocket.setSoLinger(false, 0);\r
++                                              break;\r
++                                      case SocketOptionName.Linger:\r
++                                              LingerOption lval = obj_val as LingerOption;\r
++                                              if (lval != null)\r
++                                              {\r
++                                                      jSocket.setSoLinger(lval.Enabled, lval.LingerTime);\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.KeepAlive:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setKeepAlive(bval);\r
++                                              break;\r
++                                      case SocketOptionName.NoDelay:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setTcpNoDelay(bval);\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveBuffer:\r
++                                              ival = int_val;\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      ival = (int) obj_val;\r
++                                              }\r
++                                              if (jServerSocket != null)\r
++                                              {\r
++                                                      jServerSocket.setReceiveBufferSize(ival);\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      jSocket.setReceiveBufferSize(ival);\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveTimeout:\r
++                                              ival = int_val;\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      ival = (int) obj_val;\r
++                                              }\r
++                                              if (jServerSocket != null)\r
++                                              {\r
++                                                      jServerSocket.setSoTimeout(ival);\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      jSocket.setSoTimeout(ival);\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.ReuseAddress:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              if (jServerSocket != null)\r
++                                              {\r
++                                                      jServerSocket.setReuseAddress(bval);\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      jSocket.setReuseAddress(bval);\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.SendBuffer:\r
++                                              ival = int_val;\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      ival = (int) obj_val;\r
++                                              }\r
++                                              jSocket.setSendBufferSize(ival);\r
++                                              break;\r
++                                      case SocketOptionName.OutOfBandInline:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setOOBInline(bval);\r
++                                              break;\r
++                                      default:\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              break;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              obj_val = null;\r
++                      }\r
++              }\r
++\r
++              public void GetSocketOption_obj_internal(SocketOptionLevel level, SocketOptionName name, \r
++                      out object obj_val, out int error)\r
++              {\r
++                      obj_val = null;\r
++                      error = 0;\r
++\r
++                      if (jSocket == null && jServerSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      switch (level)\r
++                      {\r
++                              case SocketOptionLevel.IPv6:\r
++                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      return;\r
++                              case SocketOptionLevel.IP:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                              case SocketOptionLevel.Udp:\r
++                                      if (name == SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      }\r
++                                      else\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                      }\r
++                                      return;\r
++                              case SocketOptionLevel.Tcp:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              bool bval = false;\r
++                              int ival = 0;\r
++                              switch (name)\r
++                              {\r
++                                      case SocketOptionName.DontLinger:\r
++                                              ival = jSocket.getSoLinger();\r
++                                              if (ival == -1)\r
++                                              {\r
++                                                      obj_val = 1;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      obj_val = 0;\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.Linger:\r
++                                              ival = jSocket.getSoLinger();\r
++                                              if (ival == -1)\r
++                                              {\r
++                                                      ival = 0;\r
++                                              }\r
++                                              LingerOption ret = new LingerOption((ival != 0), ival);\r
++                                              obj_val = ret;\r
++                                              break;\r
++                                      case SocketOptionName.KeepAlive:\r
++                                              bval = jSocket.getKeepAlive();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      case SocketOptionName.NoDelay:\r
++                                              bval = jSocket.getTcpNoDelay();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveBuffer:\r
++                                              if (jServerSocket != null)\r
++                                              {\r
++                                                      ival = jServerSocket.getReceiveBufferSize();\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      ival = jSocket.getReceiveBufferSize();\r
++                                              }\r
++                                              obj_val = ival;\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveTimeout:\r
++                                              if (jServerSocket != null)\r
++                                              {\r
++                                                      ival = jServerSocket.getSoTimeout();\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      ival = jSocket.getSoTimeout();\r
++                                              }\r
++                                              obj_val = ival;\r
++                                              break;\r
++                                      case SocketOptionName.ReuseAddress:\r
++                                              if (jServerSocket != null)\r
++                                              {\r
++                                                      bval = jServerSocket.getReuseAddress();\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = jSocket.getReuseAddress();\r
++                                              }\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      case SocketOptionName.SendBuffer:\r
++                                              ival = jSocket.getSendBufferSize();\r
++                                              obj_val = ival;\r
++                                              break;\r
++                                      case SocketOptionName.OutOfBandInline:\r
++                                              bval = jSocket.getOOBInline();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      default:\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              break;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              obj_val = null;\r
++                      }\r
++              }\r
++              \r
++              public void GetSocketOption_arr_internal(SocketOptionLevel level, SocketOptionName name, \r
++                      ref byte[] byte_val, out int error)\r
++              {\r
++                      error = -1;\r
++                      throw new NotImplementedException();\r
++              }\r
++\r
++              public int WSAIoctl (int ioctl_code, byte [] input, byte [] output, out int error)\r
++              {\r
++                      error = -1;\r
++                      throw new NotImplementedException();\r
++              }\r
++\r
++              public void Shutdown_internal(SocketShutdown how, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (jServerSocket != null || jSocket == null || !jSocket.isConnected())\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              switch (how)\r
++                              {\r
++                                      case SocketShutdown.Receive: \r
++                                                              jSocket.shutdownInput();\r
++                                                              break;\r
++                                      case SocketShutdown.Send: \r
++                                                                              jSocket.shutdownOutput();\r
++                                                                              break;\r
++                                      case SocketShutdown.Both: \r
++                                                                              jSocket.shutdownInput();\r
++                                                                              jSocket.shutdownOutput();\r
++                                                                              break;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Shutdown_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              private java.io.FileInputStream searchDefaultCacerts()\r
++              {\r
++                      try\r
++                      {\r
++                              string javaHome = java.lang.System.getProperty("java.home");\r
++                              if(javaHome == null)\r
++                                      return null;\r
++\r
++                              string keyStorePath = javaHome + "/lib/security/cacerts";\r
++                              //Console.WriteLine("keyStorePath = {0}", keyStorePath);\r
++\r
++                              java.io.File f = new java.io.File(keyStorePath);\r
++                              if(!f.exists())\r
++                                      return null;\r
++                              return new java.io.FileInputStream(f);\r
++                      }\r
++                      catch(Exception e)\r
++                      {\r
++#if DEBUG\r
++                              //todo log it\r
++                              Console.WriteLine(e.GetType() + ":" + e.Message + "\n" + e.StackTrace);\r
++#endif\r
++                              return null;\r
++                      }\r
++              }\r
++\r
++              private SSLSocketFactory getSSLSocketFactory()\r
++              {\r
++                      SSLSocketFactory factory = null;\r
++\r
++                      try\r
++                      {\r
++                              //reading the keyStore path and password from the environment properties\r
++                              string keyStorePath = java.lang.System.getProperty("javax.net.ssl.keyStore");\r
++                              java.io.FileInputStream keyStoreStream = null;\r
++                              if (keyStorePath != null)\r
++                              {\r
++                                      java.io.File file = new java.io.File(keyStorePath);\r
++                                      if(file.exists())\r
++                                              keyStoreStream = new java.io.FileInputStream(file);\r
++                                      else\r
++                                              keyStoreStream = searchDefaultCacerts();\r
++                              }\r
++                              else\r
++                                      keyStoreStream = searchDefaultCacerts();\r
++\r
++                              string keyStorePassWord = java.lang.System.getProperty("javax.net.ssl.keyStorePassword");\r
++                              if (keyStorePassWord == null)\r
++                                      keyStorePassWord = "changeit";\r
++                              char[] passphrase = keyStorePassWord.ToCharArray();                             \r
++                                              \r
++                              //initiating SSLContext\r
++                              SSLContext ctx = SSLContext.getInstance("TLS");\r
++                              KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());\r
++                              TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());\r
++                              KeyStore ks = KeyStore.getInstance("JKS");\r
++                              if (keyStoreStream != null)\r
++                                      ks.load(keyStoreStream,passphrase);\r
++                              else\r
++                                      ks.load(null,null);\r
++                              kmf.init(ks, passphrase);\r
++                              tmf.init(ks);\r
++                              ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);\r
++\r
++                              factory = ctx.getSocketFactory();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              factory = null;\r
++#if DEBUG\r
++                              Console.WriteLine("Can't get SSL Socket Factory, the exception is {0}, {1}", e.GetType(), e.Message);\r
++#endif\r
++                      }\r
++\r
++                      return factory;\r
++              }\r
++\r
++              public GHSocket ChangeToSSL(EndPoint remote_end)\r
++              {\r
++                      if (jSocket == null)\r
++                      {\r
++                              throw new InvalidOperationException("The underlying socket is null");\r
++                      }\r
++\r
++                      if (!jSocketChannel.isBlocking())\r
++                      {\r
++                              throw new NotImplementedException("The SSL Socket for non-blocking mode is not supported");\r
++                      }\r
++\r
++                      SSLSocketFactory factory = getSSLSocketFactory();\r
++                      if (factory == null)\r
++                      {\r
++                              throw new ApplicationException("Can't get SSL Socket Factory");\r
++                      }\r
++\r
++                      int err;\r
++\r
++                      // The problem with local address, when I closed the socket and try to create the new one\r
++                      // bounded to the given local address, I receive exception "Address already in use"\r
++                      IPEndPoint localEndPoint = null;\r
++//                    IPEndPoint localEndPoint = (IPEndPoint) LocalEndPoint_internal(out err);\r
++//                    if (err != 0)\r
++//                            localEndPoint = null;\r
++\r
++                      IPEndPoint remoteEndPoint = remote_end as IPEndPoint;\r
++                      if (remoteEndPoint == null)\r
++                      {\r
++                              remoteEndPoint = (IPEndPoint) RemoteEndPoint_internal(out err);\r
++                              if (err != 0)\r
++                                      remoteEndPoint = null;\r
++                      }\r
++\r
++                      java.net.Socket sslSocket = null;\r
++                      try\r
++                      {\r
++                              if (remoteEndPoint != null)\r
++                              {\r
++                                      if (localEndPoint != null)\r
++                                      {\r
++                                              sslSocket = factory.createSocket(\r
++                                                      java.net.InetAddress.getByName(remoteEndPoint.Address.ToString()),\r
++                                                      remoteEndPoint.Port,\r
++                                                      java.net.InetAddress.getByName(localEndPoint.Address.ToString()),\r
++                                                      localEndPoint.Port);\r
++                                      }\r
++                                      else\r
++                                      {\r
++                                              sslSocket = factory.createSocket(\r
++                                                      jSocket, \r
++                                                      remoteEndPoint.Address.ToString(),\r
++                                                      remoteEndPoint.Port,\r
++                                                      false);\r
++                                      }\r
++\r
++                                      if (sslSocket != null)\r
++                                      {\r
++                                              String[] protocols = { "TLSv1", "SSLv3" };\r
++                                              ((SSLSocket)sslSocket).setUseClientMode(true);\r
++                                              ((SSLSocket)sslSocket).startHandshake();\r
++                                      }\r
++\r
++                              }\r
++                              else\r
++                              {\r
++                                      sslSocket = factory.createSocket();\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              sslSocket = null;\r
++#if DEBUG\r
++                              Console.WriteLine("Can't create SSL Socket, the exception is {0}, {1}", e.GetType(), e.Message);\r
++#endif\r
++                      }\r
++\r
++                      if (sslSocket == null)\r
++                      {\r
++//                            throw new ApplicationException("Can't create SSL Socket");\r
++                              // it is important to the Socket class to distinguish if the underlying \r
++                              // handle (GHSocket) is still valid and can be used as non-SSL, or it is already\r
++                              // closed by this function and can't be used any more.\r
++                              return null;\r
++                      }\r
++\r
++/*\r
++                      string[] arr = ((SSLSocket)sslSocket).getEnabledProtocols();\r
++                      if (arr != null)\r
++                      {\r
++                              foreach (string s in arr)\r
++                                      Console.WriteLine("s:"+s);\r
++                      }\r
++                      string [] arr1 = ((SSLSocket)sslSocket).getEnabledCipherSuites();\r
++                      if (arr1 != null)\r
++                      {\r
++                              foreach (string s in arr1)\r
++                                      Console.WriteLine("s:"+s);\r
++                      }\r
++*/\r
++\r
++                      return new GHStreamSocketSSL(sslSocket);\r
++              }\r
++      }\r
++}\r
diff --cc mcs/class/System/System.Net.Sockets/GHStreamSocketSSL.cs
index 429dae43332958dc698702635651e9d1828eba6c,429dae43332958dc698702635651e9d1828eba6c..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,620 -1,620 +1,0 @@@
--using System;\r
--using System.Net;\r
--\r
--namespace System.Net.Sockets\r
--{\r
--      /// <summary>\r
--      /// Summary description for GHStreamSocket.\r
--      /// </summary>\r
--      internal class GHStreamSocketSSL : GHSocket\r
--      {\r
--              java.net.Socket jSocket;\r
--\r
--              public GHStreamSocketSSL(java.net.Socket sslSocket)\r
--              {\r
--                      jSocket = sslSocket;\r
--              }\r
--\r
--              public override int GetHashCode ()\r
--              {\r
--                      if (jSocket == null)\r
--                              return -1;\r
--\r
--                      return jSocket.ToString().GetHashCode();\r
--              }\r
--\r
--              public int Available_internal(out int error)\r
--              {\r
--                      error = 0;\r
--                      int r = 0;\r
--\r
--                      if (jSocket == null || !jSocket.isConnected())\r
--                      {\r
--                              return r;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              r = jSocket.getInputStream().available();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
--                              r = 0;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Available_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      return r;\r
--              }\r
--\r
--              public void Blocking_internal(bool block, out int error)\r
--              {\r
--                      //SVETA: see in the non-blocking io\r
--                      error = 0;\r
--\r
--                      if (block == false)\r
--                              throw new NotSupportedException();\r
--              }\r
--\r
--              public EndPoint LocalEndPoint_internal(out int error)\r
--              {\r
--                      error = 0;\r
--                      java.net.InetSocketAddress localAddr = null;\r
--\r
--                      try\r
--                      {\r
--                              localAddr = (java.net.InetSocketAddress)jSocket.getLocalSocketAddress();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              localAddr = null;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during LocalEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (localAddr == null || localAddr.getAddress() == null || localAddr.getPort() < 0)\r
--                      {\r
--                return null;\r
--                      }\r
--\r
--                      IPHostEntry lipa = Dns.Resolve(localAddr.getHostName());\r
--                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], localAddr.getPort());\r
--                      return ret;\r
--              }\r
--\r
--              public EndPoint RemoteEndPoint_internal(out int error)\r
--              {\r
--                      error = 0;\r
--                      java.net.InetSocketAddress remoteAddr = null;\r
--\r
--                      if (jSocket == null || !jSocket.isBound())\r
--                      {\r
--                              return null;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              remoteAddr = (java.net.InetSocketAddress)jSocket.getRemoteSocketAddress();\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              remoteAddr = null;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during RemoteEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      if (remoteAddr == null || remoteAddr.getAddress() == null || remoteAddr.getPort() <= 0)\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return null;\r
--                      }\r
--\r
--                      IPHostEntry lipa = Dns.Resolve(remoteAddr.getHostName());\r
--                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], remoteAddr.getPort());\r
--                      return ret;\r
--              }\r
--\r
--              public GHSocket Accept_internal(out int error)\r
--              {\r
--                      error = 10022; //WSAEINVAL (Invalid argument)\r
--                      return null;\r
--              }\r
--\r
--              public void Bind_internal(EndPoint sa, out int error)\r
--              {\r
--                      error = 0;\r
--                      IPEndPoint addr = sa as IPEndPoint;\r
--                      if (addr == null)\r
--                      {\r
--                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket == null || jSocket.isBound() || jSocket.isConnected())\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              jSocket.bind(new java.net.InetSocketAddress(java.net.InetAddress.getByName(addr.Address.ToString()),\r
--                                                                                              addr.Port));\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10048; //WSAEADDRINUSE (Address already in use)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Bind_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public void Close_internal(out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      try\r
--                      {\r
--                              if (jSocket != null)\r
--                              {\r
--                                      jSocket.close();\r
--                                      jSocket = null;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Close_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public void Connect_internal(EndPoint sa, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      IPEndPoint addr = sa as IPEndPoint;\r
--                      if (addr == null)\r
--                      {\r
--                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      if (jSocket.isConnected())\r
--                      {\r
--                              error = 10056; //WSAEISCONN (Socket is already connected)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              jSocket.connect(new java.net.InetSocketAddress(\r
--                                                                      java.net.InetAddress.getByName(addr.Address.ToString()), \r
--                                                                      addr.Port));\r
--                      }\r
--                      catch (Exception e)\r
--                      {                               \r
--                              error = 10061; //WSAECONNREFUSED (Connection refused)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Connect_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public void Listen_internal(int backlog, out int error)\r
--              {\r
--                      error = 10022; //WSAEINVAL (Invalid argument)\r
--                      return;\r
--              }\r
--\r
--              public bool Poll_internal (SelectMode mode, int timeout, Socket source, out int error)\r
--              {\r
--                      error = 0;\r
--                      throw new NotImplementedException();\r
--              }\r
--\r
--              public int Receive_internal(byte[] buffer,      int offset,     int count, SocketFlags flags,\r
--                      out int error)\r
--              {\r
--                      error = 0;\r
--                      int ret = 0;\r
--\r
--                      if (jSocket == null || !jSocket.isConnected())\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return ret;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              ret = jSocket.getInputStream().read(vmw.common.TypeUtils.ToSByteArray(buffer), offset, count);\r
--                              if (ret < 0) ret = 0;\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
--                              ret = 0;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Receive_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      return ret;\r
--              }\r
--\r
--              public int RecvFrom_internal(byte[] buffer, int offset, int count,      SocketFlags flags,\r
--                      ref SocketAddress sockaddr, out int error)\r
--              {\r
--                      return Receive_internal(buffer, offset, count, flags, out error);\r
--              }\r
--\r
--              public int Send_internal(byte[] buf, int offset, int count, SocketFlags flags,\r
--                      out int error)\r
--              {\r
--                      error = 0;\r
--                      int ret = 0;\r
--\r
--                      if (jSocket == null || !jSocket.isConnected())\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return ret;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              jSocket.getOutputStream().write(vmw.common.TypeUtils.ToSByteArray(buf), offset, count);\r
--                              ret = count;\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
--                              ret = 0;\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Send_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--\r
--                      return ret;\r
--              }\r
--\r
--              public int SendTo_internal(byte[] buffer, int offset, int count,\r
--                      SocketFlags flags,      SocketAddress sa, out int error)\r
--              {\r
--                      return Send_internal(buffer, offset, count, flags, out error);\r
--              }\r
--\r
--              public void SetSocketOption_internal (SocketOptionLevel level,\r
--                      SocketOptionName name, object obj_val,\r
--                      byte [] byte_val, int int_val, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (byte_val != null)\r
--                      {\r
--                              error = -1;\r
--                              throw new NotImplementedException();\r
--                      }\r
--\r
--                      if (jSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      switch (level)\r
--                      {\r
--                              case SocketOptionLevel.IPv6:\r
--                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      return;\r
--                              case SocketOptionLevel.IP:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                              case SocketOptionLevel.Udp:\r
--                                      if (name == SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      }\r
--                                      else\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                      }\r
--                                      return;\r
--                              case SocketOptionLevel.Tcp:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              bool bval = false;\r
--                              int ival = 0;\r
--                              switch (name)\r
--                              {\r
--                                      case SocketOptionName.DontLinger:\r
--                                              jSocket.setSoLinger(false, 0);\r
--                                              break;\r
--                                      case SocketOptionName.Linger:\r
--                                              LingerOption lval = obj_val as LingerOption;\r
--                                              if (lval != null)\r
--                                              {\r
--                                                      jSocket.setSoLinger(lval.Enabled, lval.LingerTime);\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.KeepAlive:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setKeepAlive(bval);\r
--                                              break;\r
--                                      case SocketOptionName.NoDelay:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setTcpNoDelay(bval);\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveBuffer:\r
--                                              ival = int_val;\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      ival = (int) obj_val;\r
--                                              }\r
--                                              jSocket.setReceiveBufferSize(ival);\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveTimeout:\r
--                                              ival = int_val;\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      ival = (int) obj_val;\r
--                                              }\r
--                                              jSocket.setSoTimeout(ival);\r
--                                              break;\r
--                                      case SocketOptionName.ReuseAddress:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setReuseAddress(bval);\r
--                                              break;\r
--                                      case SocketOptionName.SendBuffer:\r
--                                              ival = int_val;\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      ival = (int) obj_val;\r
--                                              }\r
--                                              jSocket.setSendBufferSize(ival);\r
--                                              break;\r
--                                      case SocketOptionName.OutOfBandInline:\r
--                                              if (obj_val != null)\r
--                                              {\r
--                                                      bval = ((int)obj_val == 0)?false:true;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      bval = (int_val == 0)?false:true;\r
--                                              }\r
--                                              jSocket.setOOBInline(bval);\r
--                                              break;\r
--                                      default:\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              break;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              obj_val = null;\r
--                      }\r
--              }\r
--\r
--              public void GetSocketOption_obj_internal(SocketOptionLevel level, SocketOptionName name, \r
--                      out object obj_val, out int error)\r
--              {\r
--                      obj_val = null;\r
--                      error = 0;\r
--\r
--                      if (jSocket == null)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              return;\r
--                      }\r
--\r
--                      switch (level)\r
--                      {\r
--                              case SocketOptionLevel.IPv6:\r
--                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      return;\r
--                              case SocketOptionLevel.IP:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                              case SocketOptionLevel.Udp:\r
--                                      if (name == SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
--                                      }\r
--                                      else\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                      }\r
--                                      return;\r
--                              case SocketOptionLevel.Tcp:\r
--                                      if (name != SocketOptionName.NoDelay)\r
--                                      {\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              return;\r
--                                      }\r
--                                      break;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              bool bval = false;\r
--                              int ival = 0;\r
--                              switch (name)\r
--                              {\r
--                                      case SocketOptionName.DontLinger:\r
--                                              ival = jSocket.getSoLinger();\r
--                                              if (ival == -1)\r
--                                              {\r
--                                                      obj_val = 1;\r
--                                              }\r
--                                              else\r
--                                              {\r
--                                                      obj_val = 0;\r
--                                              }\r
--                                              break;\r
--                                      case SocketOptionName.Linger:\r
--                                              ival = jSocket.getSoLinger();\r
--                                              if (ival == -1)\r
--                                              {\r
--                                                      ival = 0;\r
--                                              }\r
--                                              LingerOption ret = new LingerOption((ival != 0), ival);\r
--                                              obj_val = ret;\r
--                                              break;\r
--                                      case SocketOptionName.KeepAlive:\r
--                                              bval = jSocket.getKeepAlive();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      case SocketOptionName.NoDelay:\r
--                                              bval = jSocket.getTcpNoDelay();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveBuffer:\r
--                                              ival = jSocket.getReceiveBufferSize();\r
--                                              obj_val = ival;\r
--                                              break;\r
--                                      case SocketOptionName.ReceiveTimeout:\r
--                                              ival = jSocket.getSoTimeout();\r
--                                              obj_val = ival;\r
--                                              break;\r
--                                      case SocketOptionName.ReuseAddress:\r
--                                              bval = jSocket.getReuseAddress();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      case SocketOptionName.SendBuffer:\r
--                                              ival = jSocket.getSendBufferSize();\r
--                                              obj_val = ival;\r
--                                              break;\r
--                                      case SocketOptionName.OutOfBandInline:\r
--                                              bval = jSocket.getOOBInline();\r
--                                              obj_val = ((bval)?1:0);\r
--                                              break;\r
--                                      default:\r
--                                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                                              break;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--                              obj_val = null;\r
--                      }\r
--              }\r
--              \r
--              public void GetSocketOption_arr_internal(SocketOptionLevel level, SocketOptionName name, \r
--                      ref byte[] byte_val, out int error)\r
--              {\r
--                      error = -1;\r
--                      throw new NotImplementedException();\r
--              }\r
--\r
--              public int WSAIoctl (int ioctl_code, byte [] input, byte [] output, out int error)\r
--              {\r
--                      error = -1;\r
--                      throw new NotImplementedException();\r
--              }\r
--\r
--              public void Shutdown_internal(SocketShutdown how, out int error)\r
--              {\r
--                      error = 0;\r
--\r
--                      if (jSocket == null || !jSocket.isConnected())\r
--                      {\r
--                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
--                              return;\r
--                      }\r
--\r
--                      try\r
--                      {\r
--                              switch (how)\r
--                              {\r
--                                      case SocketShutdown.Receive: \r
--                                                              jSocket.shutdownInput();\r
--                                                              break;\r
--                                      case SocketShutdown.Send: \r
--                                                                              jSocket.shutdownOutput();\r
--                                                                              break;\r
--                                      case SocketShutdown.Both: \r
--                                                                              jSocket.shutdownInput();\r
--                                                                              jSocket.shutdownOutput();\r
--                                                                              break;\r
--                              }\r
--                      }\r
--                      catch (Exception e)\r
--                      {\r
--                              error = 10022; //WSAEINVAL (Invalid argument)\r
--#if DEBUG\r
--                              Console.WriteLine("Caught exception during Shutdown_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
--#endif\r
--                      }\r
--              }\r
--\r
--              public void RegisterSelector(java.nio.channels.Selector selector, int mode, Socket source, out int error)\r
--              {\r
--                      throw new InvalidOperationException();\r
--              }\r
--\r
--              public bool CheckConnectionFinished()\r
--              {\r
--                      throw new InvalidOperationException();\r
--              }\r
--\r
--              public GHSocket ChangeToSSL(EndPoint remote_end)\r
--              {\r
--                      return this;\r
--              }\r
--\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..429dae43332958dc698702635651e9d1828eba6c
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,620 @@@
++using System;\r
++using System.Net;\r
++\r
++namespace System.Net.Sockets\r
++{\r
++      /// <summary>\r
++      /// Summary description for GHStreamSocket.\r
++      /// </summary>\r
++      internal class GHStreamSocketSSL : GHSocket\r
++      {\r
++              java.net.Socket jSocket;\r
++\r
++              public GHStreamSocketSSL(java.net.Socket sslSocket)\r
++              {\r
++                      jSocket = sslSocket;\r
++              }\r
++\r
++              public override int GetHashCode ()\r
++              {\r
++                      if (jSocket == null)\r
++                              return -1;\r
++\r
++                      return jSocket.ToString().GetHashCode();\r
++              }\r
++\r
++              public int Available_internal(out int error)\r
++              {\r
++                      error = 0;\r
++                      int r = 0;\r
++\r
++                      if (jSocket == null || !jSocket.isConnected())\r
++                      {\r
++                              return r;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              r = jSocket.getInputStream().available();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
++                              r = 0;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Available_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      return r;\r
++              }\r
++\r
++              public void Blocking_internal(bool block, out int error)\r
++              {\r
++                      //SVETA: see in the non-blocking io\r
++                      error = 0;\r
++\r
++                      if (block == false)\r
++                              throw new NotSupportedException();\r
++              }\r
++\r
++              public EndPoint LocalEndPoint_internal(out int error)\r
++              {\r
++                      error = 0;\r
++                      java.net.InetSocketAddress localAddr = null;\r
++\r
++                      try\r
++                      {\r
++                              localAddr = (java.net.InetSocketAddress)jSocket.getLocalSocketAddress();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              localAddr = null;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during LocalEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (localAddr == null || localAddr.getAddress() == null || localAddr.getPort() < 0)\r
++                      {\r
++                return null;\r
++                      }\r
++\r
++                      IPHostEntry lipa = Dns.Resolve(localAddr.getHostName());\r
++                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], localAddr.getPort());\r
++                      return ret;\r
++              }\r
++\r
++              public EndPoint RemoteEndPoint_internal(out int error)\r
++              {\r
++                      error = 0;\r
++                      java.net.InetSocketAddress remoteAddr = null;\r
++\r
++                      if (jSocket == null || !jSocket.isBound())\r
++                      {\r
++                              return null;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              remoteAddr = (java.net.InetSocketAddress)jSocket.getRemoteSocketAddress();\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              remoteAddr = null;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during RemoteEndPoint_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      if (remoteAddr == null || remoteAddr.getAddress() == null || remoteAddr.getPort() <= 0)\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return null;\r
++                      }\r
++\r
++                      IPHostEntry lipa = Dns.Resolve(remoteAddr.getHostName());\r
++                      IPEndPoint ret = new IPEndPoint(lipa.AddressList[0], remoteAddr.getPort());\r
++                      return ret;\r
++              }\r
++\r
++              public GHSocket Accept_internal(out int error)\r
++              {\r
++                      error = 10022; //WSAEINVAL (Invalid argument)\r
++                      return null;\r
++              }\r
++\r
++              public void Bind_internal(EndPoint sa, out int error)\r
++              {\r
++                      error = 0;\r
++                      IPEndPoint addr = sa as IPEndPoint;\r
++                      if (addr == null)\r
++                      {\r
++                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket == null || jSocket.isBound() || jSocket.isConnected())\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              jSocket.bind(new java.net.InetSocketAddress(java.net.InetAddress.getByName(addr.Address.ToString()),\r
++                                                                                              addr.Port));\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10048; //WSAEADDRINUSE (Address already in use)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Bind_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public void Close_internal(out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      try\r
++                      {\r
++                              if (jSocket != null)\r
++                              {\r
++                                      jSocket.close();\r
++                                      jSocket = null;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Close_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public void Connect_internal(EndPoint sa, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      IPEndPoint addr = sa as IPEndPoint;\r
++                      if (addr == null)\r
++                      {\r
++                              error = 10044; //WSAESOCKTNOSUPPORT (Socket type not supported)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      if (jSocket.isConnected())\r
++                      {\r
++                              error = 10056; //WSAEISCONN (Socket is already connected)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              jSocket.connect(new java.net.InetSocketAddress(\r
++                                                                      java.net.InetAddress.getByName(addr.Address.ToString()), \r
++                                                                      addr.Port));\r
++                      }\r
++                      catch (Exception e)\r
++                      {                               \r
++                              error = 10061; //WSAECONNREFUSED (Connection refused)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Connect_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public void Listen_internal(int backlog, out int error)\r
++              {\r
++                      error = 10022; //WSAEINVAL (Invalid argument)\r
++                      return;\r
++              }\r
++\r
++              public bool Poll_internal (SelectMode mode, int timeout, Socket source, out int error)\r
++              {\r
++                      error = 0;\r
++                      throw new NotImplementedException();\r
++              }\r
++\r
++              public int Receive_internal(byte[] buffer,      int offset,     int count, SocketFlags flags,\r
++                      out int error)\r
++              {\r
++                      error = 0;\r
++                      int ret = 0;\r
++\r
++                      if (jSocket == null || !jSocket.isConnected())\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return ret;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              ret = jSocket.getInputStream().read(vmw.common.TypeUtils.ToSByteArray(buffer), offset, count);\r
++                              if (ret < 0) ret = 0;\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
++                              ret = 0;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Receive_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      return ret;\r
++              }\r
++\r
++              public int RecvFrom_internal(byte[] buffer, int offset, int count,      SocketFlags flags,\r
++                      ref SocketAddress sockaddr, out int error)\r
++              {\r
++                      return Receive_internal(buffer, offset, count, flags, out error);\r
++              }\r
++\r
++              public int Send_internal(byte[] buf, int offset, int count, SocketFlags flags,\r
++                      out int error)\r
++              {\r
++                      error = 0;\r
++                      int ret = 0;\r
++\r
++                      if (jSocket == null || !jSocket.isConnected())\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return ret;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              jSocket.getOutputStream().write(vmw.common.TypeUtils.ToSByteArray(buf), offset, count);\r
++                              ret = count;\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10054; //WSAECONNRESET (Connection reset by peer)\r
++                              ret = 0;\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Send_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++\r
++                      return ret;\r
++              }\r
++\r
++              public int SendTo_internal(byte[] buffer, int offset, int count,\r
++                      SocketFlags flags,      SocketAddress sa, out int error)\r
++              {\r
++                      return Send_internal(buffer, offset, count, flags, out error);\r
++              }\r
++\r
++              public void SetSocketOption_internal (SocketOptionLevel level,\r
++                      SocketOptionName name, object obj_val,\r
++                      byte [] byte_val, int int_val, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (byte_val != null)\r
++                      {\r
++                              error = -1;\r
++                              throw new NotImplementedException();\r
++                      }\r
++\r
++                      if (jSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      switch (level)\r
++                      {\r
++                              case SocketOptionLevel.IPv6:\r
++                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      return;\r
++                              case SocketOptionLevel.IP:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                              case SocketOptionLevel.Udp:\r
++                                      if (name == SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      }\r
++                                      else\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                      }\r
++                                      return;\r
++                              case SocketOptionLevel.Tcp:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              bool bval = false;\r
++                              int ival = 0;\r
++                              switch (name)\r
++                              {\r
++                                      case SocketOptionName.DontLinger:\r
++                                              jSocket.setSoLinger(false, 0);\r
++                                              break;\r
++                                      case SocketOptionName.Linger:\r
++                                              LingerOption lval = obj_val as LingerOption;\r
++                                              if (lval != null)\r
++                                              {\r
++                                                      jSocket.setSoLinger(lval.Enabled, lval.LingerTime);\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.KeepAlive:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setKeepAlive(bval);\r
++                                              break;\r
++                                      case SocketOptionName.NoDelay:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setTcpNoDelay(bval);\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveBuffer:\r
++                                              ival = int_val;\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      ival = (int) obj_val;\r
++                                              }\r
++                                              jSocket.setReceiveBufferSize(ival);\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveTimeout:\r
++                                              ival = int_val;\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      ival = (int) obj_val;\r
++                                              }\r
++                                              jSocket.setSoTimeout(ival);\r
++                                              break;\r
++                                      case SocketOptionName.ReuseAddress:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setReuseAddress(bval);\r
++                                              break;\r
++                                      case SocketOptionName.SendBuffer:\r
++                                              ival = int_val;\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      ival = (int) obj_val;\r
++                                              }\r
++                                              jSocket.setSendBufferSize(ival);\r
++                                              break;\r
++                                      case SocketOptionName.OutOfBandInline:\r
++                                              if (obj_val != null)\r
++                                              {\r
++                                                      bval = ((int)obj_val == 0)?false:true;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      bval = (int_val == 0)?false:true;\r
++                                              }\r
++                                              jSocket.setOOBInline(bval);\r
++                                              break;\r
++                                      default:\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              break;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              obj_val = null;\r
++                      }\r
++              }\r
++\r
++              public void GetSocketOption_obj_internal(SocketOptionLevel level, SocketOptionName name, \r
++                      out object obj_val, out int error)\r
++              {\r
++                      obj_val = null;\r
++                      error = 0;\r
++\r
++                      if (jSocket == null)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              return;\r
++                      }\r
++\r
++                      switch (level)\r
++                      {\r
++                              case SocketOptionLevel.IPv6:\r
++                                      error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      return;\r
++                              case SocketOptionLevel.IP:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                              case SocketOptionLevel.Udp:\r
++                                      if (name == SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10042; //WSAENOPROTOOPT (Bad protocol option)\r
++                                      }\r
++                                      else\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                      }\r
++                                      return;\r
++                              case SocketOptionLevel.Tcp:\r
++                                      if (name != SocketOptionName.NoDelay)\r
++                                      {\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              return;\r
++                                      }\r
++                                      break;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              bool bval = false;\r
++                              int ival = 0;\r
++                              switch (name)\r
++                              {\r
++                                      case SocketOptionName.DontLinger:\r
++                                              ival = jSocket.getSoLinger();\r
++                                              if (ival == -1)\r
++                                              {\r
++                                                      obj_val = 1;\r
++                                              }\r
++                                              else\r
++                                              {\r
++                                                      obj_val = 0;\r
++                                              }\r
++                                              break;\r
++                                      case SocketOptionName.Linger:\r
++                                              ival = jSocket.getSoLinger();\r
++                                              if (ival == -1)\r
++                                              {\r
++                                                      ival = 0;\r
++                                              }\r
++                                              LingerOption ret = new LingerOption((ival != 0), ival);\r
++                                              obj_val = ret;\r
++                                              break;\r
++                                      case SocketOptionName.KeepAlive:\r
++                                              bval = jSocket.getKeepAlive();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      case SocketOptionName.NoDelay:\r
++                                              bval = jSocket.getTcpNoDelay();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveBuffer:\r
++                                              ival = jSocket.getReceiveBufferSize();\r
++                                              obj_val = ival;\r
++                                              break;\r
++                                      case SocketOptionName.ReceiveTimeout:\r
++                                              ival = jSocket.getSoTimeout();\r
++                                              obj_val = ival;\r
++                                              break;\r
++                                      case SocketOptionName.ReuseAddress:\r
++                                              bval = jSocket.getReuseAddress();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      case SocketOptionName.SendBuffer:\r
++                                              ival = jSocket.getSendBufferSize();\r
++                                              obj_val = ival;\r
++                                              break;\r
++                                      case SocketOptionName.OutOfBandInline:\r
++                                              bval = jSocket.getOOBInline();\r
++                                              obj_val = ((bval)?1:0);\r
++                                              break;\r
++                                      default:\r
++                                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                                              break;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++                              obj_val = null;\r
++                      }\r
++              }\r
++              \r
++              public void GetSocketOption_arr_internal(SocketOptionLevel level, SocketOptionName name, \r
++                      ref byte[] byte_val, out int error)\r
++              {\r
++                      error = -1;\r
++                      throw new NotImplementedException();\r
++              }\r
++\r
++              public int WSAIoctl (int ioctl_code, byte [] input, byte [] output, out int error)\r
++              {\r
++                      error = -1;\r
++                      throw new NotImplementedException();\r
++              }\r
++\r
++              public void Shutdown_internal(SocketShutdown how, out int error)\r
++              {\r
++                      error = 0;\r
++\r
++                      if (jSocket == null || !jSocket.isConnected())\r
++                      {\r
++                              error = 10057; //WSAENOTCONN (Socket is not connected)\r
++                              return;\r
++                      }\r
++\r
++                      try\r
++                      {\r
++                              switch (how)\r
++                              {\r
++                                      case SocketShutdown.Receive: \r
++                                                              jSocket.shutdownInput();\r
++                                                              break;\r
++                                      case SocketShutdown.Send: \r
++                                                                              jSocket.shutdownOutput();\r
++                                                                              break;\r
++                                      case SocketShutdown.Both: \r
++                                                                              jSocket.shutdownInput();\r
++                                                                              jSocket.shutdownOutput();\r
++                                                                              break;\r
++                              }\r
++                      }\r
++                      catch (Exception e)\r
++                      {\r
++                              error = 10022; //WSAEINVAL (Invalid argument)\r
++#if DEBUG\r
++                              Console.WriteLine("Caught exception during Shutdown_internal - {0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);\r
++#endif\r
++                      }\r
++              }\r
++\r
++              public void RegisterSelector(java.nio.channels.Selector selector, int mode, Socket source, out int error)\r
++              {\r
++                      throw new InvalidOperationException();\r
++              }\r
++\r
++              public bool CheckConnectionFinished()\r
++              {\r
++                      throw new InvalidOperationException();\r
++              }\r
++\r
++              public GHSocket ChangeToSSL(EndPoint remote_end)\r
++              {\r
++                      return this;\r
++              }\r
++\r
++      }\r
++}\r
diff --cc mcs/class/System/System.Net/HttpProvider.cs
index dd1fdccad497daff547019a6b2a6bbe077fcd9d5,dd1fdccad497daff547019a6b2a6bbe077fcd9d5..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,330 -1,330 +1,0 @@@
--using System;\r
--using System.Security.Cryptography.X509Certificates;\r
--using System.IO;\r
--\r
--namespace System.Net\r
--{\r
--      [Serializable]\r
--      internal abstract class HttpProvider\r
--      {\r
--              #region Fields\r
--\r
--              protected static int _defaultMaxResponseHeadersLength;\r
--              protected static int _defaultMaxRedirectsNum = 50;\r
--              \r
--              protected Uri _originalUri;\r
--              protected WebHeaderCollection _headers;\r
--              protected bool _allowAutoRedirect;\r
--              protected bool _allowWriteStreamBuffering = true;\r
--              protected X509CertificateCollection _certificates;\r
--              protected string _connectionGroupName;\r
--              protected HttpContinueDelegate _continueDelegate;\r
--              protected CookieContainer _cookieContainer;\r
--              protected ICredentials _credentials;\r
--              protected bool _keepAlive = true;\r
--              protected int _maxResponseHeadersLength = _defaultMaxResponseHeadersLength;\r
--              protected int _maxAutoRedirections = _defaultMaxRedirectsNum;\r
--              protected int _readWriteTimeout = 300000;\r
--              protected string _mediaType = string.Empty;\r
--              protected string _methodName = "GET";\r
--              protected bool _pipelined = true;\r
--              protected bool _preAuthenticate;\r
--              protected Version _version = HttpVersion.Version11;\r
--              protected IWebProxy _proxy;\r
--              protected bool _sendChunked;\r
--              protected ServicePoint _servicePoint;\r
--              protected int _timeout = 100000;\r
--\r
--              protected bool _isAborted;\r
--              protected long _contentLength = -1L;\r
--\r
--              \r
--              \r
--\r
--              #endregion /* Fields */\r
--\r
--              #region Constructors and Factory Methods\r
--              protected HttpProvider(Uri uri)\r
--              {\r
--                      _originalUri = uri;\r
--                      _headers = new WebHeaderCollection(true);\r
--                      _allowAutoRedirect = true;\r
--              }\r
--\r
--              public static HttpProvider GetHttpProvider(Uri uri)\r
--              {\r
--                      return new VMWHttpProvider(uri);\r
--              }\r
--\r
--              public static HttpProvider  GetHttpProvider(string provider, Uri uri)\r
--              {\r
--                      Type type = Type.GetType(provider, true);\r
--                      if(type != null)\r
--                              return GetHttpProvider(type, uri);\r
--                      //log it as an error\r
--                      return new VMWHttpProvider(uri);\r
--              }\r
--\r
--              public static HttpProvider GetHttpProvider(Type provider, Uri uri)\r
--              {\r
--                      try\r
--                      {\r
--                              return (HttpProvider)Activator.CreateInstance(provider, \r
--                                      new object[]{uri});                     \r
--                      }\r
--                      catch\r
--                      {\r
--                              //log it as an error\r
--                              return new VMWHttpProvider(uri);\r
--                      }\r
--              }\r
--\r
--              #endregion\r
--\r
--              #region Properties\r
--              internal virtual WebHeaderCollection Headers\r
--              {\r
--                      get{return _headers;}\r
--                      set\r
--                      {\r
--                              if(IsRequestStarted ())\r
--                                      throw new InvalidOperationException("Connection already opened");\r
--                              WebHeaderCollection newHeaders = new WebHeaderCollection (true);\r
--                              int count = value.Count;\r
--                              for (int i = 0; i < count; i++) \r
--                                      newHeaders.Add (value.GetKey (i), value.Get (i));\r
--\r
--                              _headers = newHeaders;\r
--                      }\r
--              }\r
--\r
--              internal virtual bool AllowAutoRedirect\r
--              {\r
--                      get{return _allowAutoRedirect;}\r
--                      set{_allowAutoRedirect = value;}\r
--              }\r
--\r
--              internal virtual bool AllowWriteStreamBuffering\r
--              {\r
--                      get{return _allowWriteStreamBuffering;}\r
--                      set{_allowWriteStreamBuffering = value;}\r
--              }\r
--\r
--              internal virtual string ConnectionGroupName\r
--              {\r
--                      get{return _connectionGroupName;}\r
--                      set{_connectionGroupName = value;}\r
--              }\r
--\r
--              internal virtual HttpContinueDelegate ContinueDelegate\r
--              {\r
--                      get{return _continueDelegate;}\r
--                      set{_continueDelegate = value;}\r
--              }\r
--\r
--              internal virtual CookieContainer CookieContainer\r
--              {\r
--                      get{return _cookieContainer;}\r
--                      set{_cookieContainer = value;}\r
--              }\r
--\r
--              internal virtual ICredentials Credentials\r
--              {\r
--                      get{return _credentials;}\r
--                      set{_credentials = value;}\r
--              }\r
--              internal static int DefaultMaxResponseHeadersLength\r
--              {\r
--                      get{return _defaultMaxResponseHeadersLength;}\r
--                      set\r
--                      {\r
--                              if (value < 0 && value != -1)\r
--                                      throw new ArgumentOutOfRangeException("Argument should be positive");\r
--                              _defaultMaxResponseHeadersLength = value;\r
--                      }\r
--              }\r
--\r
--              internal virtual bool KeepAlive\r
--              {\r
--                      get{return _keepAlive;}\r
--                      set{_keepAlive = value;}\r
--              }\r
--\r
--              internal virtual int MaxAutoRedirections\r
--              {\r
--                      get{return _maxAutoRedirections;}\r
--                      set\r
--                      {\r
--                              if (value <= 0)\r
--                                      throw new ArgumentException("Must be > 0", "value");\r
--                              _maxAutoRedirections = value;\r
--                      }\r
--              }\r
--\r
--              internal virtual int MaximumResponseHeadersLength\r
--              {\r
--                      get{return _maxResponseHeadersLength;}\r
--                      set\r
--                      {\r
--                              if (IsRequestStarted())\r
--                              {\r
--                                      throw new InvalidOperationException("Request has been already submitted.");\r
--                              }\r
--                              if (value < 0 && value != -1)\r
--                                      throw new ArgumentOutOfRangeException("The argument must be positive or -1");\r
--                              _maxResponseHeadersLength = value;\r
--                      }\r
--              }\r
--              \r
--              internal virtual string MediaType\r
--              {\r
--                      get{return _mediaType;}\r
--                      set{_mediaType = value;}\r
--              }\r
--\r
--              internal virtual string MethodName\r
--              {\r
--                      get{return _methodName;}\r
--                      set\r
--                      {\r
--                              if (value == null || value.Trim () == "")\r
--                                      throw new ArgumentException ("not a valid method");\r
--\r
--                              _methodName = value;\r
--                      }\r
--              }\r
--              internal virtual bool Pipelined\r
--              {\r
--                      get{return _pipelined;}\r
--                      set{_pipelined = value;}\r
--              }\r
--\r
--              internal virtual bool PreAuthenticate \r
--              { \r
--                      get { return _preAuthenticate; }\r
--                      set { _preAuthenticate = value; }\r
--              }\r
--\r
--              internal virtual Version ProtocolVersion\r
--              {\r
--                      get{return _version;}\r
--                      set\r
--                      {\r
--                              if (value != HttpVersion.Version10 && value != HttpVersion.Version11)\r
--                                      throw new ArgumentException ("value");\r
--\r
--                              _version = value; \r
--                      }\r
--              }\r
--              internal virtual IWebProxy Proxy\r
--              {\r
--                      get{return _proxy;}\r
--                      set\r
--                      {\r
--                              if(IsRequestStarted())\r
--                                      throw new InvalidOperationException("Request already has been submitted");\r
--                              if(value == null)\r
--                                      throw new ArgumentNullException("value");\r
--                              if(!(value is WebProxy))\r
--                                      throw new NotImplementedException("The supported proxy objects only of type System.Net.WebProxy");\r
--                              _proxy = value;\r
--                      }\r
--              }\r
--              internal virtual int ReadWriteTimeout\r
--              {\r
--                      get{return _readWriteTimeout;}\r
--                      set\r
--                      {\r
--                              if (IsRequestStarted())\r
--                                      throw new InvalidOperationException("Request has been submitted.");\r
--\r
--                              if (value < 0 && value != -1)\r
--                                      throw new ArgumentOutOfRangeException("value");\r
--\r
--                              _readWriteTimeout = value;\r
--                      }\r
--              }\r
--\r
--              internal virtual bool SendChunked\r
--              {\r
--                      get{return _sendChunked;}\r
--                      set\r
--                      {\r
--                              if(IsRequestStarted ())\r
--                                      throw new InvalidOperationException("Request has been submitted.");\r
--                              _sendChunked = value;\r
--                      }\r
--              }\r
--\r
--              internal virtual ServicePoint ServicePoint\r
--              {\r
--                      get{return _servicePoint;}\r
--              }\r
--\r
--              internal virtual int Timeout\r
--              {\r
--                      get{return _timeout;}\r
--                      set\r
--                      {\r
--                              if (value < -1)\r
--                                      throw new ArgumentOutOfRangeException ("value");\r
--\r
--                              _timeout = value;\r
--                      }\r
--              }\r
--\r
--              internal virtual long ContentLength\r
--              {\r
--                      get{return _contentLength;}\r
--                      set\r
--                      {\r
--                              if(value < 0)\r
--                                      throw new ArgumentOutOfRangeException("value", "The Content-Length property value must be positive");\r
--                              _contentLength = value;\r
--                      }\r
--              }\r
--\r
--\r
--\r
--              #endregion\r
--\r
--              #region Methods\r
--\r
--              public virtual Uri GetOriginalAddress()\r
--              {\r
--                      return _originalUri;\r
--              }\r
--\r
--              public virtual X509CertificateCollection GetX509Certificates()\r
--              {\r
--                      if(_certificates == null)\r
--                              _certificates = new X509CertificateCollection();\r
--                      return _certificates;\r
--              }\r
--\r
--              public abstract bool IsRequestStarted();\r
--\r
--              public abstract Uri GetAddress();\r
--\r
--              public abstract bool IsHaveResponse();\r
--\r
--              public abstract void Abort();\r
--\r
--              public abstract Stream GetRequestStream();\r
--\r
--              public abstract WebResponse GetResponse();\r
--\r
--              public abstract IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);\r
--\r
--              public abstract Stream EndGetRequestStream(IAsyncResult asyncResult);\r
--\r
--              public abstract IAsyncResult BeginGetResponse(AsyncCallback callback, object state);\r
--\r
--              public abstract WebResponse EndGetResponse(IAsyncResult asyncResult);\r
--\r
--\r
--              #endregion\r
--\r
--\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..dd1fdccad497daff547019a6b2a6bbe077fcd9d5
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,330 @@@
++using System;\r
++using System.Security.Cryptography.X509Certificates;\r
++using System.IO;\r
++\r
++namespace System.Net\r
++{\r
++      [Serializable]\r
++      internal abstract class HttpProvider\r
++      {\r
++              #region Fields\r
++\r
++              protected static int _defaultMaxResponseHeadersLength;\r
++              protected static int _defaultMaxRedirectsNum = 50;\r
++              \r
++              protected Uri _originalUri;\r
++              protected WebHeaderCollection _headers;\r
++              protected bool _allowAutoRedirect;\r
++              protected bool _allowWriteStreamBuffering = true;\r
++              protected X509CertificateCollection _certificates;\r
++              protected string _connectionGroupName;\r
++              protected HttpContinueDelegate _continueDelegate;\r
++              protected CookieContainer _cookieContainer;\r
++              protected ICredentials _credentials;\r
++              protected bool _keepAlive = true;\r
++              protected int _maxResponseHeadersLength = _defaultMaxResponseHeadersLength;\r
++              protected int _maxAutoRedirections = _defaultMaxRedirectsNum;\r
++              protected int _readWriteTimeout = 300000;\r
++              protected string _mediaType = string.Empty;\r
++              protected string _methodName = "GET";\r
++              protected bool _pipelined = true;\r
++              protected bool _preAuthenticate;\r
++              protected Version _version = HttpVersion.Version11;\r
++              protected IWebProxy _proxy;\r
++              protected bool _sendChunked;\r
++              protected ServicePoint _servicePoint;\r
++              protected int _timeout = 100000;\r
++\r
++              protected bool _isAborted;\r
++              protected long _contentLength = -1L;\r
++\r
++              \r
++              \r
++\r
++              #endregion /* Fields */\r
++\r
++              #region Constructors and Factory Methods\r
++              protected HttpProvider(Uri uri)\r
++              {\r
++                      _originalUri = uri;\r
++                      _headers = new WebHeaderCollection(true);\r
++                      _allowAutoRedirect = true;\r
++              }\r
++\r
++              public static HttpProvider GetHttpProvider(Uri uri)\r
++              {\r
++                      return new VMWHttpProvider(uri);\r
++              }\r
++\r
++              public static HttpProvider  GetHttpProvider(string provider, Uri uri)\r
++              {\r
++                      Type type = Type.GetType(provider, true);\r
++                      if(type != null)\r
++                              return GetHttpProvider(type, uri);\r
++                      //log it as an error\r
++                      return new VMWHttpProvider(uri);\r
++              }\r
++\r
++              public static HttpProvider GetHttpProvider(Type provider, Uri uri)\r
++              {\r
++                      try\r
++                      {\r
++                              return (HttpProvider)Activator.CreateInstance(provider, \r
++                                      new object[]{uri});                     \r
++                      }\r
++                      catch\r
++                      {\r
++                              //log it as an error\r
++                              return new VMWHttpProvider(uri);\r
++                      }\r
++              }\r
++\r
++              #endregion\r
++\r
++              #region Properties\r
++              internal virtual WebHeaderCollection Headers\r
++              {\r
++                      get{return _headers;}\r
++                      set\r
++                      {\r
++                              if(IsRequestStarted ())\r
++                                      throw new InvalidOperationException("Connection already opened");\r
++                              WebHeaderCollection newHeaders = new WebHeaderCollection (true);\r
++                              int count = value.Count;\r
++                              for (int i = 0; i < count; i++) \r
++                                      newHeaders.Add (value.GetKey (i), value.Get (i));\r
++\r
++                              _headers = newHeaders;\r
++                      }\r
++              }\r
++\r
++              internal virtual bool AllowAutoRedirect\r
++              {\r
++                      get{return _allowAutoRedirect;}\r
++                      set{_allowAutoRedirect = value;}\r
++              }\r
++\r
++              internal virtual bool AllowWriteStreamBuffering\r
++              {\r
++                      get{return _allowWriteStreamBuffering;}\r
++                      set{_allowWriteStreamBuffering = value;}\r
++              }\r
++\r
++              internal virtual string ConnectionGroupName\r
++              {\r
++                      get{return _connectionGroupName;}\r
++                      set{_connectionGroupName = value;}\r
++              }\r
++\r
++              internal virtual HttpContinueDelegate ContinueDelegate\r
++              {\r
++                      get{return _continueDelegate;}\r
++                      set{_continueDelegate = value;}\r
++              }\r
++\r
++              internal virtual CookieContainer CookieContainer\r
++              {\r
++                      get{return _cookieContainer;}\r
++                      set{_cookieContainer = value;}\r
++              }\r
++\r
++              internal virtual ICredentials Credentials\r
++              {\r
++                      get{return _credentials;}\r
++                      set{_credentials = value;}\r
++              }\r
++              internal static int DefaultMaxResponseHeadersLength\r
++              {\r
++                      get{return _defaultMaxResponseHeadersLength;}\r
++                      set\r
++                      {\r
++                              if (value < 0 && value != -1)\r
++                                      throw new ArgumentOutOfRangeException("Argument should be positive");\r
++                              _defaultMaxResponseHeadersLength = value;\r
++                      }\r
++              }\r
++\r
++              internal virtual bool KeepAlive\r
++              {\r
++                      get{return _keepAlive;}\r
++                      set{_keepAlive = value;}\r
++              }\r
++\r
++              internal virtual int MaxAutoRedirections\r
++              {\r
++                      get{return _maxAutoRedirections;}\r
++                      set\r
++                      {\r
++                              if (value <= 0)\r
++                                      throw new ArgumentException("Must be > 0", "value");\r
++                              _maxAutoRedirections = value;\r
++                      }\r
++              }\r
++\r
++              internal virtual int MaximumResponseHeadersLength\r
++              {\r
++                      get{return _maxResponseHeadersLength;}\r
++                      set\r
++                      {\r
++                              if (IsRequestStarted())\r
++                              {\r
++                                      throw new InvalidOperationException("Request has been already submitted.");\r
++                              }\r
++                              if (value < 0 && value != -1)\r
++                                      throw new ArgumentOutOfRangeException("The argument must be positive or -1");\r
++                              _maxResponseHeadersLength = value;\r
++                      }\r
++              }\r
++              \r
++              internal virtual string MediaType\r
++              {\r
++                      get{return _mediaType;}\r
++                      set{_mediaType = value;}\r
++              }\r
++\r
++              internal virtual string MethodName\r
++              {\r
++                      get{return _methodName;}\r
++                      set\r
++                      {\r
++                              if (value == null || value.Trim () == "")\r
++                                      throw new ArgumentException ("not a valid method");\r
++\r
++                              _methodName = value;\r
++                      }\r
++              }\r
++              internal virtual bool Pipelined\r
++              {\r
++                      get{return _pipelined;}\r
++                      set{_pipelined = value;}\r
++              }\r
++\r
++              internal virtual bool PreAuthenticate \r
++              { \r
++                      get { return _preAuthenticate; }\r
++                      set { _preAuthenticate = value; }\r
++              }\r
++\r
++              internal virtual Version ProtocolVersion\r
++              {\r
++                      get{return _version;}\r
++                      set\r
++                      {\r
++                              if (value != HttpVersion.Version10 && value != HttpVersion.Version11)\r
++                                      throw new ArgumentException ("value");\r
++\r
++                              _version = value; \r
++                      }\r
++              }\r
++              internal virtual IWebProxy Proxy\r
++              {\r
++                      get{return _proxy;}\r
++                      set\r
++                      {\r
++                              if(IsRequestStarted())\r
++                                      throw new InvalidOperationException("Request already has been submitted");\r
++                              if(value == null)\r
++                                      throw new ArgumentNullException("value");\r
++                              if(!(value is WebProxy))\r
++                                      throw new NotImplementedException("The supported proxy objects only of type System.Net.WebProxy");\r
++                              _proxy = value;\r
++                      }\r
++              }\r
++              internal virtual int ReadWriteTimeout\r
++              {\r
++                      get{return _readWriteTimeout;}\r
++                      set\r
++                      {\r
++                              if (IsRequestStarted())\r
++                                      throw new InvalidOperationException("Request has been submitted.");\r
++\r
++                              if (value < 0 && value != -1)\r
++                                      throw new ArgumentOutOfRangeException("value");\r
++\r
++                              _readWriteTimeout = value;\r
++                      }\r
++              }\r
++\r
++              internal virtual bool SendChunked\r
++              {\r
++                      get{return _sendChunked;}\r
++                      set\r
++                      {\r
++                              if(IsRequestStarted ())\r
++                                      throw new InvalidOperationException("Request has been submitted.");\r
++                              _sendChunked = value;\r
++                      }\r
++              }\r
++\r
++              internal virtual ServicePoint ServicePoint\r
++              {\r
++                      get{return _servicePoint;}\r
++              }\r
++\r
++              internal virtual int Timeout\r
++              {\r
++                      get{return _timeout;}\r
++                      set\r
++                      {\r
++                              if (value < -1)\r
++                                      throw new ArgumentOutOfRangeException ("value");\r
++\r
++                              _timeout = value;\r
++                      }\r
++              }\r
++\r
++              internal virtual long ContentLength\r
++              {\r
++                      get{return _contentLength;}\r
++                      set\r
++                      {\r
++                              if(value < 0)\r
++                                      throw new ArgumentOutOfRangeException("value", "The Content-Length property value must be positive");\r
++                              _contentLength = value;\r
++                      }\r
++              }\r
++\r
++\r
++\r
++              #endregion\r
++\r
++              #region Methods\r
++\r
++              public virtual Uri GetOriginalAddress()\r
++              {\r
++                      return _originalUri;\r
++              }\r
++\r
++              public virtual X509CertificateCollection GetX509Certificates()\r
++              {\r
++                      if(_certificates == null)\r
++                              _certificates = new X509CertificateCollection();\r
++                      return _certificates;\r
++              }\r
++\r
++              public abstract bool IsRequestStarted();\r
++\r
++              public abstract Uri GetAddress();\r
++\r
++              public abstract bool IsHaveResponse();\r
++\r
++              public abstract void Abort();\r
++\r
++              public abstract Stream GetRequestStream();\r
++\r
++              public abstract WebResponse GetResponse();\r
++\r
++              public abstract IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);\r
++\r
++              public abstract Stream EndGetRequestStream(IAsyncResult asyncResult);\r
++\r
++              public abstract IAsyncResult BeginGetResponse(AsyncCallback callback, object state);\r
++\r
++              public abstract WebResponse EndGetResponse(IAsyncResult asyncResult);\r
++\r
++\r
++              #endregion\r
++\r
++\r
++      }\r
++}\r
diff --cc mcs/class/System/System.Net/HttpStateCache.cs
index 81e60523a76ef1d28e016c3be0c3f02db1517f46,81e60523a76ef1d28e016c3be0c3f02db1517f46..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,43 -1,43 +1,0 @@@
--using System;\r
--using System.Collections;\r
--\r
--using mainsoft.apache.commons.httpclient;\r
--\r
--namespace System.Net\r
--{\r
--      \r
--      class HttpStateCache\r
--      {\r
--              private static readonly int MAX_SIZE = 30;\r
--\r
--              private Stack _states;\r
--              private int _currentSize;\r
--\r
--              internal HttpStateCache()\r
--              {\r
--                      _states = new Stack(20);\r
--              }\r
--\r
--              internal HttpState GetHttpState()\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_states.Count > 0)\r
--                                      return (HttpState) _states.Pop();\r
--                      }\r
--                      return new HttpState();\r
--              }\r
--\r
--              internal void ReleaseHttpState(HttpState state)\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_states.Count < MAX_SIZE)\r
--                              {\r
--                                      state.clear();\r
--                                      _states.Push(state);\r
--                              }\r
--                      }\r
--              }\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..81e60523a76ef1d28e016c3be0c3f02db1517f46
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,43 @@@
++using System;\r
++using System.Collections;\r
++\r
++using mainsoft.apache.commons.httpclient;\r
++\r
++namespace System.Net\r
++{\r
++      \r
++      class HttpStateCache\r
++      {\r
++              private static readonly int MAX_SIZE = 30;\r
++\r
++              private Stack _states;\r
++              private int _currentSize;\r
++\r
++              internal HttpStateCache()\r
++              {\r
++                      _states = new Stack(20);\r
++              }\r
++\r
++              internal HttpState GetHttpState()\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_states.Count > 0)\r
++                                      return (HttpState) _states.Pop();\r
++                      }\r
++                      return new HttpState();\r
++              }\r
++\r
++              internal void ReleaseHttpState(HttpState state)\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_states.Count < MAX_SIZE)\r
++                              {\r
++                                      state.clear();\r
++                                      _states.Push(state);\r
++                              }\r
++                      }\r
++              }\r
++      }\r
++}\r
diff --cc mcs/class/System/System.Net/VMWHttpProvider.cs
index 689ba3aa307989894b1254160e2e93e5348f0086,689ba3aa307989894b1254160e2e93e5348f0086..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,1071 -1,1071 +1,0 @@@
--using System;\r
--using System.IO;\r
--using System.Threading;\r
--\r
--using mainsoft.apache.commons.httpclient;\r
--using mainsoft.apache.commons.httpclient.methods;\r
--using mainsoft.apache.commons.httpclient.@params;\r
--using mainsoft.apache.commons.httpclient.auth;\r
--\r
--namespace System.Net\r
--{\r
--      /// <summary>\r
--      /// Summary description for VMWHttpProvider.\r
--      /// </summary>\r
--      internal class VMWHttpProvider : HttpProvider\r
--      {\r
--              protected static HttpClient _client;     //todo init it in static constructor\r
--              protected static HttpStateCache _stateCache = new HttpStateCache();\r
--\r
--              protected static object LOCK_OBJECT = new object();\r
--              \r
--              \r
--\r
--              protected HttpMethod _method;\r
--              protected HttpState _state;\r
--              protected HostConfiguration _hostConfig;\r
--              \r
--              protected HttpWebResponse _response;\r
--              protected bool _hasResponse;\r
--              protected bool _hasRequest;\r
--              protected Stream _writeStream;\r
--              private GHWebAsyncResult _asyncWrite;\r
--              private GHWebAsyncResult _asyncRead;\r
--\r
--              private bool _isConnectionOpened;\r
--              \r
--              static VMWHttpProvider()\r
--              {\r
--                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.Log") == null)\r
--                              java.lang.System.setProperty("mainsoft.apache.commons.logging.Log",\r
--                                      "mainsoft.apache.commons.logging.impl.SimpleLog");\r
--                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.showdatetime") == null)\r
--                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.showdatetime",\r
--                                      "true");\r
--                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire") == null)\r
--                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire",\r
--                                      "error");\r
--                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.log.mainsoft.apache.commons.httpclient")\r
--                              == null)\r
--                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.log.mainsoft.apache.commons.httpclient",\r
--                                      "error");\r
--                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire.header")\r
--                              == null)\r
--                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire.header", \r
--                                      "error");\r
--\r
--              }\r
--              public VMWHttpProvider(Uri uri) : base (uri)\r
--              {\r
--              }\r
--\r
--              internal override ServicePoint ServicePoint\r
--              {\r
--                      get {throw new NotImplementedException();}\r
--              }\r
--\r
--\r
--\r
--              public override bool IsRequestStarted()\r
--              {\r
--                      if(_method == null)\r
--                              return false;\r
--                      return _method.isRequestSent();\r
--              }\r
--\r
--              public override Uri GetAddress()\r
--              {\r
--                      if(_method == null)\r
--                              return GetOriginalAddress();\r
--                      mainsoft.apache.commons.httpclient.URI javaURI =  _method.getURI();\r
--                      return new Uri(javaURI.ToString());\r
--              }\r
--\r
--              public override bool IsHaveResponse()\r
--              {\r
--                      return _hasResponse;\r
--              }\r
--\r
--              private void SetJavaCredential(NetworkCredential nc, string type)\r
--              {\r
--                      SetJavaCredential(nc, type, false);\r
--              }\r
--\r
--              private void SetJavaCredential(NetworkCredential nc, string type, bool proxyCredentials)\r
--              {\r
--                      type = type.ToLower();\r
--                      string host = null;\r
--                      \r
--                      if(!proxyCredentials)\r
--                              host = GetOriginalAddress().Host;\r
--                      else\r
--                              host = ((WebProxy)this.Proxy).Address.Host;\r
--\r
--                      string domain = (nc.Domain == null) ? host : nc.Domain;\r
--\r
--                      if(type.Equals("any"))\r
--                      {\r
--                              if(!proxyCredentials)\r
--                              {\r
--                                      _state.setCredentials(AuthScope.ANY,\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "Ntlm"),\r
--                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
--                              }\r
--                              else\r
--                              {\r
--                                      _state.setProxyCredentials(AuthScope.ANY,\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "Ntlm"),\r
--                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
--                              }\r
--                      }\r
--                      else if(type.Equals("basic"))\r
--                      {\r
--                              if(!proxyCredentials)\r
--                              {\r
--                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "basic"),\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                              }\r
--                              else\r
--                              {\r
--                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "basic"),\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                              }\r
--                      }\r
--                      else if(type.Equals("digest"))\r
--                      {\r
--                              if(!proxyCredentials)\r
--                              {\r
--                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "digest"),\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                              }\r
--                              else\r
--                              {\r
--                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "digest"),\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                              }\r
--                      }\r
--                      else if(type.Equals("ntlm"))\r
--                      {\r
--                              if(!proxyCredentials)\r
--                              {\r
--                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "ntlm"),\r
--                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
--                              }\r
--                              else\r
--                              {\r
--                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "ntlm"),\r
--                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
--                              }\r
--                      }\r
--                      else\r
--                      {\r
--                              if(!proxyCredentials)\r
--                              {\r
--                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, type),\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                              }\r
--                              else\r
--                              {\r
--                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
--                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, type),\r
--                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
--                              }\r
--                      }\r
--\r
--              }\r
--              private void InitProxyCredentials()\r
--              {\r
--                      if(this.Proxy == null)\r
--                              return;\r
--\r
--                      if(!(this.Proxy is WebProxy))\r
--                              return;\r
--                      \r
--                      WebProxy proxy = (WebProxy)this.Proxy;\r
--                      ICredentials creds = proxy.Credentials;\r
--\r
--                      if(creds == null)\r
--                              return;\r
--\r
--                      if(creds is CredentialCache)\r
--                      {\r
--                              string type = "basic";\r
--                              NetworkCredential nc = ((CredentialCache)creds).GetCredential(proxy.Address, "basic");\r
--                              if(nc == null)\r
--                              {\r
--                                      type = "digest";\r
--                                      nc = ((CredentialCache)creds).GetCredential(proxy.Address, "digest");\r
--                                      if(nc == null)\r
--                                      {\r
--                                              type = "ntlm";\r
--                                              nc = ((CredentialCache)creds).GetCredential(proxy.Address, "ntlm");\r
--                                      }\r
--                              }\r
--                              if(nc != null)\r
--                              {\r
--                                      SetJavaCredential(nc, type, true);\r
--                              }\r
--                      }\r
--                      else if (creds is NetworkCredential)\r
--                      {\r
--                              SetJavaCredential((NetworkCredential)creds, "any", true);\r
--                      }\r
--\r
--                      _method.setDoAuthentication(true);\r
--              }\r
--\r
--              private void InitCredentials()\r
--              {\r
--                      if(_credentials == null)\r
--                              return;\r
--                      if(_credentials is CredentialCache)\r
--                      {\r
--                              NetworkCredential nc = ((CredentialCache)_credentials).GetCredential(GetOriginalAddress(), "basic");\r
--                              string type = "basic";\r
--                              if(nc == null)\r
--                              {\r
--                                      nc = ((CredentialCache)_credentials).GetCredential(GetOriginalAddress(), "digest");\r
--                                      type = "digest";\r
--                                      if(nc == null)\r
--                                      {\r
--                                              nc = ((CredentialCache)_credentials).GetCredential(GetOriginalAddress(), "ntlm");\r
--                                              type = "ntlm";\r
--                                      }\r
--                              }\r
--                              if(nc != null)\r
--                              {\r
--                                      SetJavaCredential(nc, type);\r
--                              }\r
--                      }\r
--                      else if(_credentials is NetworkCredential)\r
--                      {\r
--                              SetJavaCredential((NetworkCredential)_credentials, "any");\r
--                      }\r
--\r
--                      _method.setDoAuthentication(true);\r
--              }\r
--\r
--              private void InitHostConfig()\r
--              {\r
--                      if(this.Proxy == null)\r
--                              return;\r
--                      if(this.Proxy.IsBypassed(GetOriginalAddress()))\r
--                              return;\r
--\r
--                      _hostConfig = new HostConfiguration();                  \r
--                      _hostConfig.setHost(new HttpHost(_method.getURI()));\r
--\r
--                      \r
--                      if(this.Proxy is WebProxy)\r
--                      {\r
--                              WebProxy wp = (WebProxy) this.Proxy;\r
--                              _hostConfig.setProxyHost(new ProxyHost(wp.Address.Host, wp.Address.Port));\r
--                      }\r
--                      else\r
--                              throw new NotImplementedException("Cannot accept Proxy which is not System.Net.WebProxy instance");\r
--\r
--                      \r
--              }\r
--\r
--              private void SetConnectionHeader(string val)\r
--              {\r
--                      string connectionHeader = (this.Proxy != null) ? "Proxy-Connection" : "Connection";\r
--                      Headers.RemoveInternal ((this.Proxy != null) ? "Proxy-Connection" : "Connection");\r
--                      \r
--                      if(val != null)\r
--                              _method.setRequestHeader(connectionHeader, val);\r
--\r
--                      if (_keepAlive) \r
--                      {\r
--                              _method.addRequestHeader (connectionHeader, "keep-alive");\r
--                              Headers.SetInternal(connectionHeader,"keep-alive");\r
--                      }\r
--                      else if (!_keepAlive && _version == HttpVersion.Version11) \r
--                      {\r
--                              _method.addRequestHeader (connectionHeader, "close");\r
--                              Headers.SetInternal(connectionHeader,"close");\r
--                      }\r
--\r
--              }\r
--              private bool OpenConnection()\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_isConnectionOpened)\r
--                                      return false;\r
--                              _isConnectionOpened = true;\r
--                      }\r
--                      InitClient();\r
--                      InitMethod();\r
--\r
--                      _state = _stateCache.GetHttpState();\r
--\r
--                      //todo insert needed Authontication, Cookies info to state!\r
--                      _method.setDoAuthentication(this.PreAuthenticate);\r
--                      \r
--                      InitHostConfig();\r
--                      InitCredentials();\r
--                      InitProxyCredentials();\r
--                      \r
--                      if(this.ProtocolVersion == HttpVersion.Version11)\r
--                              _method.getParams().setVersion(mainsoft.apache.commons.httpclient.HttpVersion.HTTP_1_1);\r
--                      else if(ProtocolVersion == HttpVersion.Version10)\r
--                              _method.getParams().setVersion(mainsoft.apache.commons.httpclient.HttpVersion.HTTP_1_0);\r
--                      else \r
--                              throw new ProtocolViolationException("Unsupported protocol version: " + ProtocolVersion);\r
--\r
--                      if(!(_method is mainsoft.apache.commons.httpclient.methods.EntityEnclosingMethod))\r
--                      {\r
--                              _method.setFollowRedirects(this.AllowAutoRedirect);\r
--                      }\r
--                      else\r
--                      {\r
--                              if(!AllowWriteStreamBuffering && _contentLength < 0 && !SendChunked)\r
--                                      throw new ProtocolViolationException();\r
--                              if(SendChunked)\r
--                                      ((EntityEnclosingMethod)_method).setContentChunked(SendChunked);                                \r
--                      }\r
--                      if(MaxAutoRedirections != _defaultMaxRedirectsNum)\r
--                      {\r
--                              _method.getParams().setParameter(HttpClientParams.MAX_REDIRECTS,\r
--                                      new java.lang.Integer(MaxAutoRedirections));\r
--                      }\r
--                      \r
--                      \r
--                      \r
--                      foreach(string k in Headers)\r
--                      {       \r
--                              if(k.ToLower().Equals("connection"))\r
--                                      continue;\r
--                              string val = Headers[k];\r
--                              val = (val == null) ? "" : val;\r
--                              _method.setRequestHeader(k, val);\r
--                      }\r
--\r
--                      if (this.CookieContainer != null) \r
--                      {
--                              string cookieHeader = this.CookieContainer.GetCookieHeader (this.GetOriginalAddress());
--                              if (cookieHeader != "")
--                                      _method.setRequestHeader("Cookie", cookieHeader);
--                      }\r
--                      SetConnectionHeader(Headers["Connection"]);\r
--                      \r
--                      _method.getParams().setSoTimeout(ReadWriteTimeout);\r
--\r
--                      return true;\r
--                      \r
--              }\r
--\r
--              private static void InitClient()\r
--              {\r
--                      lock(LOCK_OBJECT)\r
--                      {\r
--                              if(_client == null)\r
--                              {\r
--                                      mainsoft.apache.commons.httpclient.MultiThreadedHttpConnectionManager manager =\r
--                                              new mainsoft.apache.commons.httpclient.MultiThreadedHttpConnectionManager();\r
--                                      manager.setConnectionStaleCheckingEnabled(true);\r
--                                      manager.setMaxTotalConnections(200);\r
--                                      //by some reasons RFC something - the default \r
--                                      //value will be 2 , so we need to change it ...\r
--                                      manager.setMaxConnectionsPerHost(20);\r
--                                      _client = new HttpClient(manager);\r
--                                      _client.getParams().setIntParameter(HttpClientParams.MAX_REDIRECTS, _defaultMaxRedirectsNum);\r
--                                      _client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, new java.lang.Boolean(true));\r
--                                      _client.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new java.lang.Long(30000));\r
--                                      _client.getParams().setParameter(HttpClientParams.USER_AGENT, \r
--                                                      "VMW4J HttpClient (based on Jakarta Commons HttpClient)");\r
--                              }\r
--                      }\r
--              }\r
--\r
--              private void InitMethod()\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_method == null)\r
--                              {\r
--                                      string uriString = this.GetOriginalAddress().AbsoluteUri;\r
--\r
--                                      if(this.MethodName == null || this.MethodName == "")\r
--                                      {\r
--                                              this.MethodName = "GET";\r
--                                      }\r
--                      \r
--                                      string name = this.MethodName.ToUpper().Trim();\r
--\r
--                                      switch(name)\r
--                                      {\r
--                                              case "GET" : _method = new GetMethod(uriString); break;\r
--                                              case "PUT" : _method = new PutMethod(uriString); break;\r
--                                              case "POST": _method = new PostMethod(uriString); break;\r
--                                              case "HEAD": _method = new HeadMethod(uriString); break;\r
--                                              case "TRACE": _method = new TraceMethod(uriString);break;\r
--                                              case "DELETE": _method = new DeleteMethod(uriString);break;\r
--                                              case "OPTIONS": _method = new OptionsMethod(uriString);break;\r
--                                              default: _method = new GenericMethod(uriString, MethodName); break;\r
--                                      }\r
--                              }\r
--                      }\r
--              }\r
--\r
--              private void InitHostConfiguration()\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_hostConfig == null)\r
--                              {\r
--                                      _hostConfig = new HostConfiguration();\r
--                              }\r
--                      }\r
--              }\r
--\r
--              \r
--\r
--              public override Stream GetRequestStream()\r
--              {\r
--                      bool isPutPost = String.Compare("post", MethodName, true) == 0 \r
--                              || String.Compare("put", MethodName, true) == 0;\r
--                      if(!isPutPost)\r
--                              throw new ProtocolViolationException();\r
--                      lock(this)\r
--                      {\r
--                              if(_writeStream != null)\r
--                                      return _writeStream;\r
--                              this.OpenConnection();\r
--\r
--                              //java.io.PipedInputStream inJavaStream = new java.io.PipedInputStream();\r
--                              //java.io.PipedOutputStream outJavaStream = new java.io.PipedOutputStream(inJavaStream);\r
--                                                      \r
--                              long contLen = _contentLength;\r
--                              \r
--                              OutputStreamRequestEntity reqEntity = new OutputStreamRequestEntity(contLen);\r
--\r
--                              _writeStream = new VMWRequestStream(reqEntity, contLen);\r
--                      \r
--                              EntityEnclosingMethod method = (EntityEnclosingMethod)_method;\r
--                              if(AllowWriteStreamBuffering )\r
--                                      method.setRequestEntity(reqEntity);\r
--                              else if(!AllowWriteStreamBuffering && contLen < 0 && !SendChunked)\r
--                                      throw new ProtocolViolationException();\r
--                              else\r
--                                      method.setRequestEntity(reqEntity);\r
--                      \r
--                              _hasRequest = true;\r
--                              return _writeStream;\r
--                      }\r
--              }\r
--              private bool isRedirectNeeded(HttpMethod method)\r
--              {\r
--                      switch (method.getStatusCode()) \r
--                      {\r
--                              case 302:\r
--                              case 301:\r
--                              case 303:\r
--                              case 307:\r
--                                      if (method.getFollowRedirects()) \r
--                                              return true;\r
--                                      else \r
--                                              return false;\r
--                              default:\r
--                                      return false;\r
--                      } //end of switch\r
--              }\r
--\r
--              private void synchHeaders()\r
--              {\r
--                      foreach(string k in Headers)\r
--                      {       \r
--                              if(k.ToLower().Equals("connection"))\r
--                                      continue;\r
--                              string val = Headers[k];\r
--                              val = (val == null) ? "" : val;\r
--                              _method.setRequestHeader(k, val);\r
--                      }\r
--              }\r
--\r
--              public override WebResponse GetResponse()\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(!_isConnectionOpened)\r
--                                      OpenConnection();\r
--                              if(_response == null)\r
--                              {\r
--                                      try\r
--                                      {       \r
--                                              synchHeaders();\r
--                                              _client.executeMethod(_hostConfig, _method, _state);\r
--                                              //todo right place to re-put all headers again...\r
--                                              mainsoft.apache.commons.httpclient.Header hostHeader =\r
--                                                      _method.getRequestHeader("Host");\r
--                                              if(hostHeader != null)\r
--                                                      Headers.SetInternal("Host", hostHeader.getValue());\r
--\r
--                                              _response = new HttpWebResponse(_method, _state, _stateCache, GetAddress(), this.MethodName);\r
--                                              \r
--                                              if(_response != null && \r
--                                                      _response.Cookies != null && \r
--                                                      _response.Cookies.Count > 0)\r
--                                              {\r
--                                                      if(CookieContainer != null)\r
--                                                      {\r
--                                                              foreach(Cookie cooky in _response.Cookies)\r
--                                                              {\r
--                                                                      CookieContainer.Add(GetAddress(), cooky);\r
--                                                              }\r
--                                                      }\r
--                                              }\r
--\r
--                                              _hasResponse = true;\r
--                                              int respCodeAsInt = (int) _response.StatusCode;\r
--                                              if(respCodeAsInt >= 400)\r
--                                              {\r
--                                                      // The WebException contains the readable (not closed) response stream.\r
--                                                      // So, in case of WebException, we should read all data from the \r
--                                                      // network response stream into the memory stream, and after that\r
--                                                      // close the underlying network stream. The following requests to read\r
--                                                      // from the stream will actually read from the memory stream.\r
--                                                      // So, the this.Abort() should not be called in this case.\r
--                                                      _response.ReadAllAndClose();\r
--                                                      //this.Abort();\r
--                                                      throw new WebException("The remote server returned an error: (" + respCodeAsInt +") " +_response.StatusCode, null, WebExceptionStatus.ProtocolError, _response);\r
--                                              }\r
--                                              if(isRedirectNeeded(_method) && _method.getResponseHeader("location") == null)\r
--                                              {\r
--                                                      // See comments above for the error >= 400\r
--                                                      _response.ReadAllAndClose();\r
--                                                      //this.Abort();\r
--                                                      throw new WebException("Got response code "+_response.StatusCode+", but no location provided", null, WebExceptionStatus.ProtocolError, _response);\r
--                                              }\r
--                                      }\r
--                                      catch(ProtocolException e)\r
--                                      {\r
--                                              throw new WebException("", e);\r
--                                      }\r
--                                      catch(java.net.ConnectException e)\r
--                                      {\r
--                                              throw new WebException("Unable to connect to the remote server.", e);\r
--                                      }\r
--                                      catch(java.net.SocketTimeoutException e)\r
--                                      {\r
--                                              throw new WebException("Timeout exceeded", e);\r
--                                      }\r
--                                      catch(java.io.IOException e)\r
--                                      {\r
--                                              throw new WebException("", e);\r
--                                      }\r
--                              }\r
--                              return _response;\r
--                      }\r
--\r
--              }\r
--\r
--              public override void Abort()\r
--              {\r
--                      _isAborted = true;\r
--                      try\r
--                      {\r
--                              if(_hasResponse)\r
--                              {\r
--                                      _response.Close();\r
--                              }\r
--                      }\r
--                      finally\r
--                      {\r
--                              _method.releaseConnection();                            \r
--                      }\r
--              }\r
--\r
--              public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_asyncWrite != null)\r
--                              {\r
--                                      throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
--                                              "method while a previous call is still in progress.");
--                              }
--      
--                              _asyncWrite = new GHWebAsyncResult (this, callback, state);
--                              if (_hasRequest) 
--                              {
--                                      if (_writeStream != null) 
--                                      {
--                                              _asyncWrite.SetCompleted (true, _writeStream);
--                                              _asyncWrite.DoCallback ();
--                                              return _asyncWrite;
--                                      }\r
--                              }\r
--                              \r
--                              \r
--                              try\r
--                              {\r
--                                      this.GetRequestStream();                                        \r
--                              }\r
--                              catch(Exception e)\r
--                              {\r
--                                      _asyncWrite.SetCompleted(false, e);\r
--                              }\r
--\r
--                              _asyncWrite.SetCompleted (true, _writeStream);
--                              _asyncWrite.DoCallback ();
--                              return _asyncWrite;\r
--                              \r
--                      }\r
--              }   \r
--\r
--              public override Stream EndGetRequestStream(IAsyncResult asyncResult)\r
--              {\r
--                      if (asyncResult == null)
--                              throw new ArgumentNullException ("asyncResult");
--
--                      GHWebAsyncResult result = asyncResult as GHWebAsyncResult;
--                      if (result == null)
--                              throw new ArgumentException ("Invalid IAsyncResult");
--
--                      _asyncWrite = result;
--
--                      result.WaitUntilComplete ();
--
--                      Exception e = result.Exception;
--                      
--                      if (e != null)
--                              throw e;
--
--                      return result.WriteStream;\r
--              }\r
--\r
--              public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)\r
--              {\r
--                      lock(this)\r
--                      {\r
--                              if(_asyncRead != null && !_hasResponse)\r
--                              {\r
--                                      throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
--                                              "method while a previous call is still in progress.");
--                              }
--      
--                              _asyncRead = new GHWebAsyncResult (this, callback, state);
--                              if (_hasResponse) 
--                              {
--                                      if (_response != null) 
--                                      {
--                                              _asyncRead.SetCompleted (true, _writeStream);
--                                              _asyncRead.DoCallback ();
--                                              return _asyncRead;
--                                      }\r
--                              }\r
--                              \r
--\r
--                              try\r
--                              {\r
--                                      GetResponse();\r
--                              }\r
--                              catch(Exception e)\r
--                              {\r
--                                      _asyncRead.SetCompleted(false, e);\r
--                              }
--                              _asyncRead.SetCompleted (true, _writeStream);
--                              _asyncRead.DoCallback ();       
--                              return _asyncRead;\r
--                              \r
--                      }\r
--              }\r
--\r
--              public override WebResponse EndGetResponse(IAsyncResult asyncResult)\r
--              {\r
--                      if (asyncResult == null)
--                              throw new ArgumentNullException ("asyncResult");
--
--                      GHWebAsyncResult result = asyncResult as GHWebAsyncResult;
--                      if (result == null)
--                              throw new ArgumentException ("Invalid IAsyncResult", "asyncResult");
--
--                      
--                      _asyncRead = result;
--                      if (!result.WaitUntilComplete (_timeout, false)) \r
--                      {
--                              Abort ();
--                              throw new WebException("The request timed out", WebExceptionStatus.Timeout);
--                      }
--                      
--                      return result.Response;\r
--              }\r
--\r
--\r
--\r
--\r
--\r
--\r
--\r
--              \r
--\r
--\r
--\r
--\r
--              #region VMWRequestStream class\r
--              internal class VMWRequestStream : Stream, IDisposable\r
--              {\r
--\r
--                      private java.io.OutputStream _javaOutput;\r
--                      private long _len;\r
--                      private long _contentLength;\r
--\r
--                      internal VMWRequestStream (java.io.OutputStream stream) :\r
--                              this(stream , -1L)\r
--                      {\r
--                      }\r
--\r
--                      internal VMWRequestStream (java.io.OutputStream stream, long contentLength)\r
--                      {\r
--                              _javaOutput = stream;\r
--                              _contentLength = contentLength;\r
--                              _len = 0;\r
--                      }\r
--                      public override bool CanRead\r
--                      {\r
--                              get    {return false;}\r
--                      }\r
--\r
--                      public override bool CanWrite\r
--                      {\r
--                              get{return true;}\r
--                      }\r
--\r
--                      public override bool CanSeek\r
--                      {\r
--                              get { return false;}\r
--                      }\r
--\r
--                      public override long Length\r
--                      {\r
--                              get{ return _len;}\r
--                      }\r
--\r
--                      public override long Position\r
--                      {\r
--                              get\r
--                              {\r
--                                      return _len;\r
--                              }\r
--\r
--                              set\r
--                              {\r
--                                      throw new NotSupportedException();\r
--                              }\r
--                      }\r
--\r
--                      private volatile bool _closed = false;\r
--\r
--                      public override void Close()\r
--                      {\r
--                              if(!_closed)\r
--                              {\r
--                                      lock(this)\r
--                                      {\r
--                                              if(!_closed)\r
--                                              {\r
--                                                      _closed = true;\r
--                                                      _javaOutput.flush();\r
--                                                      _javaOutput.close();\r
--                                              }\r
--                                      }\r
--                              }\r
--                      }\r
--\r
--                      public override void Flush()\r
--                      {\r
--                              _javaOutput.flush();\r
--                      }\r
--\r
--                      public override int ReadByte()\r
--                      {\r
--                              throw new NotSupportedException();\r
--                      }\r
--\r
--                      public override int Read(byte[] buffer, int offset, int count)\r
--                      {\r
--                              throw new NotSupportedException();\r
--                      }\r
--\r
--                      public override void Write(byte[] buffer, int offset, int count)\r
--                      {\r
--                              if(_contentLength >= 0)\r
--                              {\r
--                                      _len += count;\r
--                                      if(_len > _contentLength)\r
--                                      {\r
--                                              throw new  System.Net.ProtocolViolationException(\r
--                                                      "Bytes to be written to the stream exceed Content-Length bytes size specified.");\r
--                                      }\r
--                              }\r
--                              _javaOutput.write(vmw.common.TypeUtils.ToSByteArray(buffer), offset, count);\r
--\r
--                              if(_contentLength == _len)\r
--                              {\r
--                                      _javaOutput.flush();\r
--                                      _javaOutput.close();\r
--                              }\r
--                      }\r
--\r
--                      public override long Seek(long offset, SeekOrigin origin)\r
--                      {\r
--                              throw new NotSupportedException();\r
--                      }\r
--\r
--                      public override void SetLength(long length)\r
--                      {\r
--                              throw new NotSupportedException();\r
--                      }\r
--\r
--                      void IDisposable.Dispose()\r
--                      {\r
--                              try\r
--                              {\r
--                                      Close();\r
--                              }\r
--                              catch(Exception)\r
--                              {\r
--                              }\r
--                      }\r
--              }\r
--              \r
--              #endregion\r
--\r
--              #region GHWebAsyncResult\r
--              internal class GHWebAsyncResult  : IAsyncResult\r
--              {\r
--                      private object _state;\r
--                      private AsyncCallback _callback;\r
--                      private ManualResetEvent _handle;\r
--                      private bool _isCompleted = false;\r
--                      private bool _callbackDone;\r
--                      private Stream _writeStream;\r
--                      private HttpProvider _provider;\r
--\r
--                      private Exception _exception;\r
--\r
--                      #region   Constructors\r
--\r
--                      public GHWebAsyncResult(HttpProvider provider, \r
--                              AsyncCallback callback, object state) : \r
--                              this(state, callback)\r
--                      {\r
--                              _provider = provider;\r
--                      }\r
--\r
--                      public GHWebAsyncResult(object state, AsyncCallback callback)\r
--                      {\r
--                              _state = state;\r
--                              _callback = callback;\r
--                      }\r
--                      #endregion\r
--\r
--                      #region IAsyncResult Members\r
--\r
--                      public object AsyncState\r
--                      {\r
--                              get\r
--                              {\r
--                                      return _state;\r
--                              }\r
--                      }\r
--\r
--                      public bool CompletedSynchronously\r
--                      {\r
--                              get\r
--                              {\r
--                                      // TODO:  Add HWebAsyncResult.CompletedSynchronously getter implementation\r
--                                      return false;\r
--                              }\r
--                      }\r
--\r
--                      public WaitHandle AsyncWaitHandle \r
--                      {
--                              get \r
--                              {
--                                      if (_handle == null) \r
--                                      {
--                                              lock (this) \r
--                                              {
--                                                      if (_handle == null)
--                                                              _handle = new ManualResetEvent (_isCompleted);
--                                              }
--                                      }
--                              
--                                      return _handle;
--                              }
--                      }\r
--\r
--                      public bool IsCompleted\r
--                      {\r
--                              get\r
--                              {\r
--                                      return _isCompleted;    \r
--                              }\r
--                      }\r
--\r
--                      #endregion\r
--\r
--                      #region Internal Properties\r
--\r
--                      internal Stream WriteStream\r
--                      {\r
--                              get\r
--                              {\r
--                                      return _writeStream;\r
--                              }\r
--                      }\r
--\r
--                      internal Exception Exception\r
--                      {\r
--                              get\r
--                              {\r
--                                      return _exception;\r
--                              }\r
--                      }\r
--\r
--                      internal HttpWebResponse Response\r
--                      {\r
--                              get\r
--                              {\r
--                                      return ((VMWHttpProvider)_provider)._response;\r
--                              }\r
--                      }\r
--\r
--                      #endregion\r
--\r
--                      #region Internal Methods\r
--\r
--                      internal void SetCompleted(bool res, Stream writeStream)\r
--                      {\r
--                              _isCompleted = res;\r
--                              _writeStream = writeStream;\r
--                              ((ManualResetEvent) AsyncWaitHandle).Set ();\r
--                      }\r
--\r
--                      internal void SetCompleted(bool res, Exception exc)\r
--                      {\r
--                              _isCompleted = res;\r
--                              _exception = exc;\r
--                              ((ManualResetEvent) AsyncWaitHandle).Set ();\r
--                      }\r
--\r
--                      internal void DoCallback()\r
--                      {\r
--                              if (!_callbackDone && _callback != null) \r
--                              {
--                                      _callbackDone = true;
--                                      _callback (this);
--                              }\r
--                      }\r
--\r
--                      internal void WaitUntilComplete()\r
--                      {\r
--                              if(_isCompleted)\r
--                                      return;\r
--                              AsyncWaitHandle.WaitOne ();\r
--                      }\r
--\r
--                      internal bool WaitUntilComplete (int timeout, bool exitContext)
--                      {
--                              if (_isCompleted)
--                                      return true;
--
--                              return AsyncWaitHandle.WaitOne (timeout, exitContext);
--                      }\r
--                      #endregion\r
--\r
--              }\r
--\r
--              #endregion\r
--\r
--              #region OutputStreamRequestEntity\r
--\r
--              internal class OutputStreamRequestEntity : java.io.OutputStream, RequestEntity\r
--              {\r
--                      private long _contentLength;\r
--                      private java.io.ByteArrayOutputStream _out;\r
--                      private sbyte[] _buffer;\r
--\r
--                      internal OutputStreamRequestEntity(): this(-1)\r
--                      {\r
--                      }\r
--\r
--                      internal OutputStreamRequestEntity(long length)\r
--                      {\r
--                              _contentLength = length;\r
--                              int tmp = (int) _contentLength;\r
--\r
--                              if(tmp <=0)\r
--                                      tmp = 4096;\r
--                              _out = new java.io.ByteArrayOutputStream(tmp);\r
--                      }\r
--\r
--                      #region RequestEntity Members\r
--\r
--                      public bool isRepeatable()\r
--                      {\r
--                              return ((_out != null) || (_buffer != null));\r
--                      }\r
--\r
--                      public long getContentLength()\r
--                      {\r
--                              if(_out != null)\r
--                              {\r
--                                      _buffer = _out.toByteArray();\r
--                              }\r
--                              if(_buffer != null)\r
--                              {\r
--                                      _contentLength = _buffer.Length;\r
--                                      _out = null;\r
--                              }\r
--                              return _contentLength;\r
--                      }\r
--\r
--                      public void writeRequest(java.io.OutputStream output)\r
--                      {\r
--                              if(_out != null)\r
--                                      _buffer = _out.toByteArray();\r
--                              if(_buffer != null)\r
--                              {\r
--                                      output.write(_buffer, 0, _buffer.Length);\r
--                                      _out = null;\r
--                              }\r
--                              else throw new ApplicationException();\r
--                      }\r
--\r
--                      public string getContentType()\r
--                      {\r
--                              return null;\r
--                      }\r
--\r
--                      #endregion\r
--\r
--                      public override void write(int i)\r
--                      {\r
--                              _out.write(i);\r
--                      }\r
--\r
--              }\r
--\r
--              #endregion\r
--\r
--\r
--\r
--\r
--\r
--\r
--\r
--      }\r
--}\r
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..689ba3aa307989894b1254160e2e93e5348f0086
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,1071 @@@
++using System;\r
++using System.IO;\r
++using System.Threading;\r
++\r
++using mainsoft.apache.commons.httpclient;\r
++using mainsoft.apache.commons.httpclient.methods;\r
++using mainsoft.apache.commons.httpclient.@params;\r
++using mainsoft.apache.commons.httpclient.auth;\r
++\r
++namespace System.Net\r
++{\r
++      /// <summary>\r
++      /// Summary description for VMWHttpProvider.\r
++      /// </summary>\r
++      internal class VMWHttpProvider : HttpProvider\r
++      {\r
++              protected static HttpClient _client;     //todo init it in static constructor\r
++              protected static HttpStateCache _stateCache = new HttpStateCache();\r
++\r
++              protected static object LOCK_OBJECT = new object();\r
++              \r
++              \r
++\r
++              protected HttpMethod _method;\r
++              protected HttpState _state;\r
++              protected HostConfiguration _hostConfig;\r
++              \r
++              protected HttpWebResponse _response;\r
++              protected bool _hasResponse;\r
++              protected bool _hasRequest;\r
++              protected Stream _writeStream;\r
++              private GHWebAsyncResult _asyncWrite;\r
++              private GHWebAsyncResult _asyncRead;\r
++\r
++              private bool _isConnectionOpened;\r
++              \r
++              static VMWHttpProvider()\r
++              {\r
++                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.Log") == null)\r
++                              java.lang.System.setProperty("mainsoft.apache.commons.logging.Log",\r
++                                      "mainsoft.apache.commons.logging.impl.SimpleLog");\r
++                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.showdatetime") == null)\r
++                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.showdatetime",\r
++                                      "true");\r
++                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire") == null)\r
++                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire",\r
++                                      "error");\r
++                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.log.mainsoft.apache.commons.httpclient")\r
++                              == null)\r
++                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.log.mainsoft.apache.commons.httpclient",\r
++                                      "error");\r
++                      if(java.lang.System.getProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire.header")\r
++                              == null)\r
++                              java.lang.System.setProperty("mainsoft.apache.commons.logging.simplelog.log.httpclient.wire.header", \r
++                                      "error");\r
++\r
++              }\r
++              public VMWHttpProvider(Uri uri) : base (uri)\r
++              {\r
++              }\r
++\r
++              internal override ServicePoint ServicePoint\r
++              {\r
++                      get {throw new NotImplementedException();}\r
++              }\r
++\r
++\r
++\r
++              public override bool IsRequestStarted()\r
++              {\r
++                      if(_method == null)\r
++                              return false;\r
++                      return _method.isRequestSent();\r
++              }\r
++\r
++              public override Uri GetAddress()\r
++              {\r
++                      if(_method == null)\r
++                              return GetOriginalAddress();\r
++                      mainsoft.apache.commons.httpclient.URI javaURI =  _method.getURI();\r
++                      return new Uri(javaURI.ToString());\r
++              }\r
++\r
++              public override bool IsHaveResponse()\r
++              {\r
++                      return _hasResponse;\r
++              }\r
++\r
++              private void SetJavaCredential(NetworkCredential nc, string type)\r
++              {\r
++                      SetJavaCredential(nc, type, false);\r
++              }\r
++\r
++              private void SetJavaCredential(NetworkCredential nc, string type, bool proxyCredentials)\r
++              {\r
++                      type = type.ToLower();\r
++                      string host = null;\r
++                      \r
++                      if(!proxyCredentials)\r
++                              host = GetOriginalAddress().Host;\r
++                      else\r
++                              host = ((WebProxy)this.Proxy).Address.Host;\r
++\r
++                      string domain = (nc.Domain == null) ? host : nc.Domain;\r
++\r
++                      if(type.Equals("any"))\r
++                      {\r
++                              if(!proxyCredentials)\r
++                              {\r
++                                      _state.setCredentials(AuthScope.ANY,\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "Ntlm"),\r
++                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
++                              }\r
++                              else\r
++                              {\r
++                                      _state.setProxyCredentials(AuthScope.ANY,\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, "Ntlm"),\r
++                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
++                              }\r
++                      }\r
++                      else if(type.Equals("basic"))\r
++                      {\r
++                              if(!proxyCredentials)\r
++                              {\r
++                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "basic"),\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                              }\r
++                              else\r
++                              {\r
++                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "basic"),\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                              }\r
++                      }\r
++                      else if(type.Equals("digest"))\r
++                      {\r
++                              if(!proxyCredentials)\r
++                              {\r
++                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "digest"),\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                              }\r
++                              else\r
++                              {\r
++                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "digest"),\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                              }\r
++                      }\r
++                      else if(type.Equals("ntlm"))\r
++                      {\r
++                              if(!proxyCredentials)\r
++                              {\r
++                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "ntlm"),\r
++                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
++                              }\r
++                              else\r
++                              {\r
++                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, "ntlm"),\r
++                                              new NTCredentials(nc.UserName, nc.Password, host, domain));\r
++                              }\r
++                      }\r
++                      else\r
++                      {\r
++                              if(!proxyCredentials)\r
++                              {\r
++                                      _state.setCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, type),\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                              }\r
++                              else\r
++                              {\r
++                                      _state.setProxyCredentials(new AuthScope(AuthScope.ANY_HOST,\r
++                                              AuthScope.ANY_PORT, AuthScope.ANY_REALM, type),\r
++                                              new UsernamePasswordCredentials(nc.UserName, nc.Password));\r
++                              }\r
++                      }\r
++\r
++              }\r
++              private void InitProxyCredentials()\r
++              {\r
++                      if(this.Proxy == null)\r
++                              return;\r
++\r
++                      if(!(this.Proxy is WebProxy))\r
++                              return;\r
++                      \r
++                      WebProxy proxy = (WebProxy)this.Proxy;\r
++                      ICredentials creds = proxy.Credentials;\r
++\r
++                      if(creds == null)\r
++                              return;\r
++\r
++                      if(creds is CredentialCache)\r
++                      {\r
++                              string type = "basic";\r
++                              NetworkCredential nc = ((CredentialCache)creds).GetCredential(proxy.Address, "basic");\r
++                              if(nc == null)\r
++                              {\r
++                                      type = "digest";\r
++                                      nc = ((CredentialCache)creds).GetCredential(proxy.Address, "digest");\r
++                                      if(nc == null)\r
++                                      {\r
++                                              type = "ntlm";\r
++                                              nc = ((CredentialCache)creds).GetCredential(proxy.Address, "ntlm");\r
++                                      }\r
++                              }\r
++                              if(nc != null)\r
++                              {\r
++                                      SetJavaCredential(nc, type, true);\r
++                              }\r
++                      }\r
++                      else if (creds is NetworkCredential)\r
++                      {\r
++                              SetJavaCredential((NetworkCredential)creds, "any", true);\r
++                      }\r
++\r
++                      _method.setDoAuthentication(true);\r
++              }\r
++\r
++              private void InitCredentials()\r
++              {\r
++                      if(_credentials == null)\r
++                              return;\r
++                      if(_credentials is CredentialCache)\r
++                      {\r
++                              NetworkCredential nc = ((CredentialCache)_credentials).GetCredential(GetOriginalAddress(), "basic");\r
++                              string type = "basic";\r
++                              if(nc == null)\r
++                              {\r
++                                      nc = ((CredentialCache)_credentials).GetCredential(GetOriginalAddress(), "digest");\r
++                                      type = "digest";\r
++                                      if(nc == null)\r
++                                      {\r
++                                              nc = ((CredentialCache)_credentials).GetCredential(GetOriginalAddress(), "ntlm");\r
++                                              type = "ntlm";\r
++                                      }\r
++                              }\r
++                              if(nc != null)\r
++                              {\r
++                                      SetJavaCredential(nc, type);\r
++                              }\r
++                      }\r
++                      else if(_credentials is NetworkCredential)\r
++                      {\r
++                              SetJavaCredential((NetworkCredential)_credentials, "any");\r
++                      }\r
++\r
++                      _method.setDoAuthentication(true);\r
++              }\r
++\r
++              private void InitHostConfig()\r
++              {\r
++                      if(this.Proxy == null)\r
++                              return;\r
++                      if(this.Proxy.IsBypassed(GetOriginalAddress()))\r
++                              return;\r
++\r
++                      _hostConfig = new HostConfiguration();                  \r
++                      _hostConfig.setHost(new HttpHost(_method.getURI()));\r
++\r
++                      \r
++                      if(this.Proxy is WebProxy)\r
++                      {\r
++                              WebProxy wp = (WebProxy) this.Proxy;\r
++                              _hostConfig.setProxyHost(new ProxyHost(wp.Address.Host, wp.Address.Port));\r
++                      }\r
++                      else\r
++                              throw new NotImplementedException("Cannot accept Proxy which is not System.Net.WebProxy instance");\r
++\r
++                      \r
++              }\r
++\r
++              private void SetConnectionHeader(string val)\r
++              {\r
++                      string connectionHeader = (this.Proxy != null) ? "Proxy-Connection" : "Connection";\r
++                      Headers.RemoveInternal ((this.Proxy != null) ? "Proxy-Connection" : "Connection");\r
++                      \r
++                      if(val != null)\r
++                              _method.setRequestHeader(connectionHeader, val);\r
++\r
++                      if (_keepAlive) \r
++                      {\r
++                              _method.addRequestHeader (connectionHeader, "keep-alive");\r
++                              Headers.SetInternal(connectionHeader,"keep-alive");\r
++                      }\r
++                      else if (!_keepAlive && _version == HttpVersion.Version11) \r
++                      {\r
++                              _method.addRequestHeader (connectionHeader, "close");\r
++                              Headers.SetInternal(connectionHeader,"close");\r
++                      }\r
++\r
++              }\r
++              private bool OpenConnection()\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_isConnectionOpened)\r
++                                      return false;\r
++                              _isConnectionOpened = true;\r
++                      }\r
++                      InitClient();\r
++                      InitMethod();\r
++\r
++                      _state = _stateCache.GetHttpState();\r
++\r
++                      //todo insert needed Authontication, Cookies info to state!\r
++                      _method.setDoAuthentication(this.PreAuthenticate);\r
++                      \r
++                      InitHostConfig();\r
++                      InitCredentials();\r
++                      InitProxyCredentials();\r
++                      \r
++                      if(this.ProtocolVersion == HttpVersion.Version11)\r
++                              _method.getParams().setVersion(mainsoft.apache.commons.httpclient.HttpVersion.HTTP_1_1);\r
++                      else if(ProtocolVersion == HttpVersion.Version10)\r
++                              _method.getParams().setVersion(mainsoft.apache.commons.httpclient.HttpVersion.HTTP_1_0);\r
++                      else \r
++                              throw new ProtocolViolationException("Unsupported protocol version: " + ProtocolVersion);\r
++\r
++                      if(!(_method is mainsoft.apache.commons.httpclient.methods.EntityEnclosingMethod))\r
++                      {\r
++                              _method.setFollowRedirects(this.AllowAutoRedirect);\r
++                      }\r
++                      else\r
++                      {\r
++                              if(!AllowWriteStreamBuffering && _contentLength < 0 && !SendChunked)\r
++                                      throw new ProtocolViolationException();\r
++                              if(SendChunked)\r
++                                      ((EntityEnclosingMethod)_method).setContentChunked(SendChunked);                                \r
++                      }\r
++                      if(MaxAutoRedirections != _defaultMaxRedirectsNum)\r
++                      {\r
++                              _method.getParams().setParameter(HttpClientParams.MAX_REDIRECTS,\r
++                                      new java.lang.Integer(MaxAutoRedirections));\r
++                      }\r
++                      \r
++                      \r
++                      \r
++                      foreach(string k in Headers)\r
++                      {       \r
++                              if(k.ToLower().Equals("connection"))\r
++                                      continue;\r
++                              string val = Headers[k];\r
++                              val = (val == null) ? "" : val;\r
++                              _method.setRequestHeader(k, val);\r
++                      }\r
++\r
++                      if (this.CookieContainer != null) \r
++                      {
++                              string cookieHeader = this.CookieContainer.GetCookieHeader (this.GetOriginalAddress());
++                              if (cookieHeader != "")
++                                      _method.setRequestHeader("Cookie", cookieHeader);
++                      }\r
++                      SetConnectionHeader(Headers["Connection"]);\r
++                      \r
++                      _method.getParams().setSoTimeout(ReadWriteTimeout);\r
++\r
++                      return true;\r
++                      \r
++              }\r
++\r
++              private static void InitClient()\r
++              {\r
++                      lock(LOCK_OBJECT)\r
++                      {\r
++                              if(_client == null)\r
++                              {\r
++                                      mainsoft.apache.commons.httpclient.MultiThreadedHttpConnectionManager manager =\r
++                                              new mainsoft.apache.commons.httpclient.MultiThreadedHttpConnectionManager();\r
++                                      manager.setConnectionStaleCheckingEnabled(true);\r
++                                      manager.setMaxTotalConnections(200);\r
++                                      //by some reasons RFC something - the default \r
++                                      //value will be 2 , so we need to change it ...\r
++                                      manager.setMaxConnectionsPerHost(20);\r
++                                      _client = new HttpClient(manager);\r
++                                      _client.getParams().setIntParameter(HttpClientParams.MAX_REDIRECTS, _defaultMaxRedirectsNum);\r
++                                      _client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, new java.lang.Boolean(true));\r
++                                      _client.getParams().setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT, new java.lang.Long(30000));\r
++                                      _client.getParams().setParameter(HttpClientParams.USER_AGENT, \r
++                                                      "VMW4J HttpClient (based on Jakarta Commons HttpClient)");\r
++                              }\r
++                      }\r
++              }\r
++\r
++              private void InitMethod()\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_method == null)\r
++                              {\r
++                                      string uriString = this.GetOriginalAddress().AbsoluteUri;\r
++\r
++                                      if(this.MethodName == null || this.MethodName == "")\r
++                                      {\r
++                                              this.MethodName = "GET";\r
++                                      }\r
++                      \r
++                                      string name = this.MethodName.ToUpper().Trim();\r
++\r
++                                      switch(name)\r
++                                      {\r
++                                              case "GET" : _method = new GetMethod(uriString); break;\r
++                                              case "PUT" : _method = new PutMethod(uriString); break;\r
++                                              case "POST": _method = new PostMethod(uriString); break;\r
++                                              case "HEAD": _method = new HeadMethod(uriString); break;\r
++                                              case "TRACE": _method = new TraceMethod(uriString);break;\r
++                                              case "DELETE": _method = new DeleteMethod(uriString);break;\r
++                                              case "OPTIONS": _method = new OptionsMethod(uriString);break;\r
++                                              default: _method = new GenericMethod(uriString, MethodName); break;\r
++                                      }\r
++                              }\r
++                      }\r
++              }\r
++\r
++              private void InitHostConfiguration()\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_hostConfig == null)\r
++                              {\r
++                                      _hostConfig = new HostConfiguration();\r
++                              }\r
++                      }\r
++              }\r
++\r
++              \r
++\r
++              public override Stream GetRequestStream()\r
++              {\r
++                      bool isPutPost = String.Compare("post", MethodName, true) == 0 \r
++                              || String.Compare("put", MethodName, true) == 0;\r
++                      if(!isPutPost)\r
++                              throw new ProtocolViolationException();\r
++                      lock(this)\r
++                      {\r
++                              if(_writeStream != null)\r
++                                      return _writeStream;\r
++                              this.OpenConnection();\r
++\r
++                              //java.io.PipedInputStream inJavaStream = new java.io.PipedInputStream();\r
++                              //java.io.PipedOutputStream outJavaStream = new java.io.PipedOutputStream(inJavaStream);\r
++                                                      \r
++                              long contLen = _contentLength;\r
++                              \r
++                              OutputStreamRequestEntity reqEntity = new OutputStreamRequestEntity(contLen);\r
++\r
++                              _writeStream = new VMWRequestStream(reqEntity, contLen);\r
++                      \r
++                              EntityEnclosingMethod method = (EntityEnclosingMethod)_method;\r
++                              if(AllowWriteStreamBuffering )\r
++                                      method.setRequestEntity(reqEntity);\r
++                              else if(!AllowWriteStreamBuffering && contLen < 0 && !SendChunked)\r
++                                      throw new ProtocolViolationException();\r
++                              else\r
++                                      method.setRequestEntity(reqEntity);\r
++                      \r
++                              _hasRequest = true;\r
++                              return _writeStream;\r
++                      }\r
++              }\r
++              private bool isRedirectNeeded(HttpMethod method)\r
++              {\r
++                      switch (method.getStatusCode()) \r
++                      {\r
++                              case 302:\r
++                              case 301:\r
++                              case 303:\r
++                              case 307:\r
++                                      if (method.getFollowRedirects()) \r
++                                              return true;\r
++                                      else \r
++                                              return false;\r
++                              default:\r
++                                      return false;\r
++                      } //end of switch\r
++              }\r
++\r
++              private void synchHeaders()\r
++              {\r
++                      foreach(string k in Headers)\r
++                      {       \r
++                              if(k.ToLower().Equals("connection"))\r
++                                      continue;\r
++                              string val = Headers[k];\r
++                              val = (val == null) ? "" : val;\r
++                              _method.setRequestHeader(k, val);\r
++                      }\r
++              }\r
++\r
++              public override WebResponse GetResponse()\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(!_isConnectionOpened)\r
++                                      OpenConnection();\r
++                              if(_response == null)\r
++                              {\r
++                                      try\r
++                                      {       \r
++                                              synchHeaders();\r
++                                              _client.executeMethod(_hostConfig, _method, _state);\r
++                                              //todo right place to re-put all headers again...\r
++                                              mainsoft.apache.commons.httpclient.Header hostHeader =\r
++                                                      _method.getRequestHeader("Host");\r
++                                              if(hostHeader != null)\r
++                                                      Headers.SetInternal("Host", hostHeader.getValue());\r
++\r
++                                              _response = new HttpWebResponse(_method, _state, _stateCache, GetAddress(), this.MethodName);\r
++                                              \r
++                                              if(_response != null && \r
++                                                      _response.Cookies != null && \r
++                                                      _response.Cookies.Count > 0)\r
++                                              {\r
++                                                      if(CookieContainer != null)\r
++                                                      {\r
++                                                              foreach(Cookie cooky in _response.Cookies)\r
++                                                              {\r
++                                                                      CookieContainer.Add(GetAddress(), cooky);\r
++                                                              }\r
++                                                      }\r
++                                              }\r
++\r
++                                              _hasResponse = true;\r
++                                              int respCodeAsInt = (int) _response.StatusCode;\r
++                                              if(respCodeAsInt >= 400)\r
++                                              {\r
++                                                      // The WebException contains the readable (not closed) response stream.\r
++                                                      // So, in case of WebException, we should read all data from the \r
++                                                      // network response stream into the memory stream, and after that\r
++                                                      // close the underlying network stream. The following requests to read\r
++                                                      // from the stream will actually read from the memory stream.\r
++                                                      // So, the this.Abort() should not be called in this case.\r
++                                                      _response.ReadAllAndClose();\r
++                                                      //this.Abort();\r
++                                                      throw new WebException("The remote server returned an error: (" + respCodeAsInt +") " +_response.StatusCode, null, WebExceptionStatus.ProtocolError, _response);\r
++                                              }\r
++                                              if(isRedirectNeeded(_method) && _method.getResponseHeader("location") == null)\r
++                                              {\r
++                                                      // See comments above for the error >= 400\r
++                                                      _response.ReadAllAndClose();\r
++                                                      //this.Abort();\r
++                                                      throw new WebException("Got response code "+_response.StatusCode+", but no location provided", null, WebExceptionStatus.ProtocolError, _response);\r
++                                              }\r
++                                      }\r
++                                      catch(ProtocolException e)\r
++                                      {\r
++                                              throw new WebException("", e);\r
++                                      }\r
++                                      catch(java.net.ConnectException e)\r
++                                      {\r
++                                              throw new WebException("Unable to connect to the remote server.", e);\r
++                                      }\r
++                                      catch(java.net.SocketTimeoutException e)\r
++                                      {\r
++                                              throw new WebException("Timeout exceeded", e);\r
++                                      }\r
++                                      catch(java.io.IOException e)\r
++                                      {\r
++                                              throw new WebException("", e);\r
++                                      }\r
++                              }\r
++                              return _response;\r
++                      }\r
++\r
++              }\r
++\r
++              public override void Abort()\r
++              {\r
++                      _isAborted = true;\r
++                      try\r
++                      {\r
++                              if(_hasResponse)\r
++                              {\r
++                                      _response.Close();\r
++                              }\r
++                      }\r
++                      finally\r
++                      {\r
++                              _method.releaseConnection();                            \r
++                      }\r
++              }\r
++\r
++              public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_asyncWrite != null)\r
++                              {\r
++                                      throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
++                                              "method while a previous call is still in progress.");
++                              }
++      
++                              _asyncWrite = new GHWebAsyncResult (this, callback, state);
++                              if (_hasRequest) 
++                              {
++                                      if (_writeStream != null) 
++                                      {
++                                              _asyncWrite.SetCompleted (true, _writeStream);
++                                              _asyncWrite.DoCallback ();
++                                              return _asyncWrite;
++                                      }\r
++                              }\r
++                              \r
++                              \r
++                              try\r
++                              {\r
++                                      this.GetRequestStream();                                        \r
++                              }\r
++                              catch(Exception e)\r
++                              {\r
++                                      _asyncWrite.SetCompleted(false, e);\r
++                              }\r
++\r
++                              _asyncWrite.SetCompleted (true, _writeStream);
++                              _asyncWrite.DoCallback ();
++                              return _asyncWrite;\r
++                              \r
++                      }\r
++              }   \r
++\r
++              public override Stream EndGetRequestStream(IAsyncResult asyncResult)\r
++              {\r
++                      if (asyncResult == null)
++                              throw new ArgumentNullException ("asyncResult");
++
++                      GHWebAsyncResult result = asyncResult as GHWebAsyncResult;
++                      if (result == null)
++                              throw new ArgumentException ("Invalid IAsyncResult");
++
++                      _asyncWrite = result;
++
++                      result.WaitUntilComplete ();
++
++                      Exception e = result.Exception;
++                      
++                      if (e != null)
++                              throw e;
++
++                      return result.WriteStream;\r
++              }\r
++\r
++              public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)\r
++              {\r
++                      lock(this)\r
++                      {\r
++                              if(_asyncRead != null && !_hasResponse)\r
++                              {\r
++                                      throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
++                                              "method while a previous call is still in progress.");
++                              }
++      
++                              _asyncRead = new GHWebAsyncResult (this, callback, state);
++                              if (_hasResponse) 
++                              {
++                                      if (_response != null) 
++                                      {
++                                              _asyncRead.SetCompleted (true, _writeStream);
++                                              _asyncRead.DoCallback ();
++                                              return _asyncRead;
++                                      }\r
++                              }\r
++                              \r
++\r
++                              try\r
++                              {\r
++                                      GetResponse();\r
++                              }\r
++                              catch(Exception e)\r
++                              {\r
++                                      _asyncRead.SetCompleted(false, e);\r
++                              }
++                              _asyncRead.SetCompleted (true, _writeStream);
++                              _asyncRead.DoCallback ();       
++                              return _asyncRead;\r
++                              \r
++                      }\r
++              }\r
++\r
++              public override WebResponse EndGetResponse(IAsyncResult asyncResult)\r
++              {\r
++                      if (asyncResult == null)
++                              throw new ArgumentNullException ("asyncResult");
++
++                      GHWebAsyncResult result = asyncResult as GHWebAsyncResult;
++                      if (result == null)
++                              throw new ArgumentException ("Invalid IAsyncResult", "asyncResult");
++
++                      
++                      _asyncRead = result;
++                      if (!result.WaitUntilComplete (_timeout, false)) \r
++                      {
++                              Abort ();
++                              throw new WebException("The request timed out", WebExceptionStatus.Timeout);
++                      }
++                      
++                      return result.Response;\r
++              }\r
++\r
++\r
++\r
++\r
++\r
++\r
++\r
++              \r
++\r
++\r
++\r
++\r
++              #region VMWRequestStream class\r
++              internal class VMWRequestStream : Stream, IDisposable\r
++              {\r
++\r
++                      private java.io.OutputStream _javaOutput;\r
++                      private long _len;\r
++                      private long _contentLength;\r
++\r
++                      internal VMWRequestStream (java.io.OutputStream stream) :\r
++                              this(stream , -1L)\r
++                      {\r
++                      }\r
++\r
++                      internal VMWRequestStream (java.io.OutputStream stream, long contentLength)\r
++                      {\r
++                              _javaOutput = stream;\r
++                              _contentLength = contentLength;\r
++                              _len = 0;\r
++                      }\r
++                      public override bool CanRead\r
++                      {\r
++                              get    {return false;}\r
++                      }\r
++\r
++                      public override bool CanWrite\r
++                      {\r
++                              get{return true;}\r
++                      }\r
++\r
++                      public override bool CanSeek\r
++                      {\r
++                              get { return false;}\r
++                      }\r
++\r
++                      public override long Length\r
++                      {\r
++                              get{ return _len;}\r
++                      }\r
++\r
++                      public override long Position\r
++                      {\r
++                              get\r
++                              {\r
++                                      return _len;\r
++                              }\r
++\r
++                              set\r
++                              {\r
++                                      throw new NotSupportedException();\r
++                              }\r
++                      }\r
++\r
++                      private volatile bool _closed = false;\r
++\r
++                      public override void Close()\r
++                      {\r
++                              if(!_closed)\r
++                              {\r
++                                      lock(this)\r
++                                      {\r
++                                              if(!_closed)\r
++                                              {\r
++                                                      _closed = true;\r
++                                                      _javaOutput.flush();\r
++                                                      _javaOutput.close();\r
++                                              }\r
++                                      }\r
++                              }\r
++                      }\r
++\r
++                      public override void Flush()\r
++                      {\r
++                              _javaOutput.flush();\r
++                      }\r
++\r
++                      public override int ReadByte()\r
++                      {\r
++                              throw new NotSupportedException();\r
++                      }\r
++\r
++                      public override int Read(byte[] buffer, int offset, int count)\r
++                      {\r
++                              throw new NotSupportedException();\r
++                      }\r
++\r
++                      public override void Write(byte[] buffer, int offset, int count)\r
++                      {\r
++                              if(_contentLength >= 0)\r
++                              {\r
++                                      _len += count;\r
++                                      if(_len > _contentLength)\r
++                                      {\r
++                                              throw new  System.Net.ProtocolViolationException(\r
++                                                      "Bytes to be written to the stream exceed Content-Length bytes size specified.");\r
++                                      }\r
++                              }\r
++                              _javaOutput.write(vmw.common.TypeUtils.ToSByteArray(buffer), offset, count);\r
++\r
++                              if(_contentLength == _len)\r
++                              {\r
++                                      _javaOutput.flush();\r
++                                      _javaOutput.close();\r
++                              }\r
++                      }\r
++\r
++                      public override long Seek(long offset, SeekOrigin origin)\r
++                      {\r
++                              throw new NotSupportedException();\r
++                      }\r
++\r
++                      public override void SetLength(long length)\r
++                      {\r
++                              throw new NotSupportedException();\r
++                      }\r
++\r
++                      void IDisposable.Dispose()\r
++                      {\r
++                              try\r
++                              {\r
++                                      Close();\r
++                              }\r
++                              catch(Exception)\r
++                              {\r
++                              }\r
++                      }\r
++              }\r
++              \r
++              #endregion\r
++\r
++              #region GHWebAsyncResult\r
++              internal class GHWebAsyncResult  : IAsyncResult\r
++              {\r
++                      private object _state;\r
++                      private AsyncCallback _callback;\r
++                      private ManualResetEvent _handle;\r
++                      private bool _isCompleted = false;\r
++                      private bool _callbackDone;\r
++                      private Stream _writeStream;\r
++                      private HttpProvider _provider;\r
++\r
++                      private Exception _exception;\r
++\r
++                      #region   Constructors\r
++\r
++                      public GHWebAsyncResult(HttpProvider provider, \r
++                              AsyncCallback callback, object state) : \r
++                              this(state, callback)\r
++                      {\r
++                              _provider = provider;\r
++                      }\r
++\r
++                      public GHWebAsyncResult(object state, AsyncCallback callback)\r
++                      {\r
++                              _state = state;\r
++                              _callback = callback;\r
++                      }\r
++                      #endregion\r
++\r
++                      #region IAsyncResult Members\r
++\r
++                      public object AsyncState\r
++                      {\r
++                              get\r
++                              {\r
++                                      return _state;\r
++                              }\r
++                      }\r
++\r
++                      public bool CompletedSynchronously\r
++                      {\r
++                              get\r
++                              {\r
++                                      // TODO:  Add HWebAsyncResult.CompletedSynchronously getter implementation\r
++                                      return false;\r
++                              }\r
++                      }\r
++\r
++                      public WaitHandle AsyncWaitHandle \r
++                      {
++                              get \r
++                              {
++                                      if (_handle == null) \r
++                                      {
++                                              lock (this) \r
++                                              {
++                                                      if (_handle == null)
++                                                              _handle = new ManualResetEvent (_isCompleted);
++                                              }
++                                      }
++                              
++                                      return _handle;
++                              }
++                      }\r
++\r
++                      public bool IsCompleted\r
++                      {\r
++                              get\r
++                              {\r
++                                      return _isCompleted;    \r
++                              }\r
++                      }\r
++\r
++                      #endregion\r
++\r
++                      #region Internal Properties\r
++\r
++                      internal Stream WriteStream\r
++                      {\r
++                              get\r
++                              {\r
++                                      return _writeStream;\r
++                              }\r
++                      }\r
++\r
++                      internal Exception Exception\r
++                      {\r
++                              get\r
++                              {\r
++                                      return _exception;\r
++                              }\r
++                      }\r
++\r
++                      internal HttpWebResponse Response\r
++                      {\r
++                              get\r
++                              {\r
++                                      return ((VMWHttpProvider)_provider)._response;\r
++                              }\r
++                      }\r
++\r
++                      #endregion\r
++\r
++                      #region Internal Methods\r
++\r
++                      internal void SetCompleted(bool res, Stream writeStream)\r
++                      {\r
++                              _isCompleted = res;\r
++                              _writeStream = writeStream;\r
++                              ((ManualResetEvent) AsyncWaitHandle).Set ();\r
++                      }\r
++\r
++                      internal void SetCompleted(bool res, Exception exc)\r
++                      {\r
++                              _isCompleted = res;\r
++                              _exception = exc;\r
++                              ((ManualResetEvent) AsyncWaitHandle).Set ();\r
++                      }\r
++\r
++                      internal void DoCallback()\r
++                      {\r
++                              if (!_callbackDone && _callback != null) \r
++                              {
++                                      _callbackDone = true;
++                                      _callback (this);
++                              }\r
++                      }\r
++\r
++                      internal void WaitUntilComplete()\r
++                      {\r
++                              if(_isCompleted)\r
++                                      return;\r
++                              AsyncWaitHandle.WaitOne ();\r
++                      }\r
++\r
++                      internal bool WaitUntilComplete (int timeout, bool exitContext)
++                      {
++                              if (_isCompleted)
++                                      return true;
++
++                              return AsyncWaitHandle.WaitOne (timeout, exitContext);
++                      }\r
++                      #endregion\r
++\r
++              }\r
++\r
++              #endregion\r
++\r
++              #region OutputStreamRequestEntity\r
++\r
++              internal class OutputStreamRequestEntity : java.io.OutputStream, RequestEntity\r
++              {\r
++                      private long _contentLength;\r
++                      private java.io.ByteArrayOutputStream _out;\r
++                      private sbyte[] _buffer;\r
++\r
++                      internal OutputStreamRequestEntity(): this(-1)\r
++                      {\r
++                      }\r
++\r
++                      internal OutputStreamRequestEntity(long length)\r
++                      {\r
++                              _contentLength = length;\r
++                              int tmp = (int) _contentLength;\r
++\r
++                              if(tmp <=0)\r
++                                      tmp = 4096;\r
++                              _out = new java.io.ByteArrayOutputStream(tmp);\r
++                      }\r
++\r
++                      #region RequestEntity Members\r
++\r
++                      public bool isRepeatable()\r
++                      {\r
++                              return ((_out != null) || (_buffer != null));\r
++                      }\r
++\r
++                      public long getContentLength()\r
++                      {\r
++                              if(_out != null)\r
++                              {\r
++                                      _buffer = _out.toByteArray();\r
++                              }\r
++                              if(_buffer != null)\r
++                              {\r
++                                      _contentLength = _buffer.Length;\r
++                                      _out = null;\r
++                              }\r
++                              return _contentLength;\r
++                      }\r
++\r
++                      public void writeRequest(java.io.OutputStream output)\r
++                      {\r
++                              if(_out != null)\r
++                                      _buffer = _out.toByteArray();\r
++                              if(_buffer != null)\r
++                              {\r
++                                      output.write(_buffer, 0, _buffer.Length);\r
++                                      _out = null;\r
++                              }\r
++                              else throw new ApplicationException();\r
++                      }\r
++\r
++                      public string getContentType()\r
++                      {\r
++                              return null;\r
++                      }\r
++\r
++                      #endregion\r
++\r
++                      public override void write(int i)\r
++                      {\r
++                              _out.write(i);\r
++                      }\r
++\r
++              }\r
++\r
++              #endregion\r
++\r
++\r
++\r
++\r
++\r
++\r
++\r
++      }\r
++}\r
index ce8ae0c4c82df978b830d46f6a1cd326d075a6cf,ce8ae0c4c82df978b830d46f6a1cd326d075a6cf..4c93516f7d8563fbda83f6bb67a4f2a8af8fc06f
@@@ -1,4 -1,4 +1,4 @@@
--<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
++<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
    <PropertyGroup>\r
      <Configuration Condition=" '$(Configuration)' == '' ">Debug_Java</Configuration>\r
      <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
    -->\r
    <ProjectExtensions>\r
      <VisualStudio>\r
--      <UserProperties REFS-JarPath-apache_http_client="..\lib\apache_http_client.jar" REFS-JarPath-system-configuration="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\System.Configuration.jar" REFS-JarPath-rt="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jre5\lib\rt.jar" REFS-JarPath-mscorlib="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\mscorlib.jar" REFS-JarPath-j2se-helpers="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\J2SE.Helpers.jar" REFS-JarPath-system-xml="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\System.Xml.jar" />\r
++      <UserProperties REFS-JarPath-system-xml="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\System.Xml.jar" REFS-JarPath-j2se-helpers="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\J2SE.Helpers.jar" REFS-JarPath-mscorlib="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\mscorlib.jar" REFS-JarPath-rt="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jre5\lib\rt.jar" REFS-JarPath-system-configuration="..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE V2\jgac\vmw4j2ee_110\System.Configuration.jar" REFS-JarPath-apache_http_client="..\lib\apache_http_client.jar" />\r
      </VisualStudio>\r
    </ProjectExtensions>\r
    <ItemGroup>\r
      <Compile Include="System.Diagnostics\Debug.cs">\r
        <SubType>Code</SubType>\r
      </Compile>\r
++    <Compile Include="System.Diagnostics\Debugger.jvm.cs" />\r
      <Compile Include="System.Diagnostics\DefaultTraceListener.cs">\r
        <SubType>Code</SubType>\r
      </Compile>\r
      <Compile Include="System.Diagnostics\DiagnosticsConfigurationHandler.cs">\r
        <SubType>Code</SubType>\r
      </Compile>\r
++    <Compile Include="System.Diagnostics\StackFrame.jvm.cs" />\r
++    <Compile Include="System.Diagnostics\StackTrace.jvm.cs" />\r
      <Compile Include="System.Diagnostics\Trace.cs">\r
        <SubType>Code</SubType>\r
      </Compile>\r
      <Compile Include="System.Net.Security\SslPolicyErrors.cs" />\r
      <Compile Include="System.Net.Security\SslStream.cs" />\r
      <Compile Include="System.Net.Sockets\AddressFamily.cs" />\r
--    <Compile Include="System.Net.Sockets\GHSocket.cs" />\r
--    <Compile Include="System.Net.Sockets\GHSocketFactory.cs" />\r
--    <Compile Include="System.Net.Sockets\GHStreamSocket.cs" />\r
--    <Compile Include="System.Net.Sockets\GHStreamSocketSSL.cs" />\r
++    <Compile Include="System.Net.Sockets\GHSocket.jvm.cs" />\r
++    <Compile Include="System.Net.Sockets\GHSocketFactory.jvm.cs" />\r
++    <Compile Include="System.Net.Sockets\GHStreamSocket.jvm.cs" />\r
++    <Compile Include="System.Net.Sockets\GHStreamSocketSSL.jvm.cs" />\r
      <Compile Include="System.Net.Sockets\IPv6MulticastOption.cs" />\r
      <Compile Include="System.Net.Sockets\LingerOption.cs" />\r
      <Compile Include="System.Net.Sockets\MulticastOption.cs" />\r
      <Compile Include="System.Net\HttpListenerPrefixCollection.cs" />\r
      <Compile Include="System.Net\HttpListenerRequest.cs" />\r
      <Compile Include="System.Net\HttpListenerResponse.cs" />\r
--    <Compile Include="System.Net\HttpProvider.cs" />\r
++    <Compile Include="System.Net\HttpProvider.jvm.cs" />\r
      <Compile Include="System.Net\HttpRequestCreator.cs" />\r
      <Compile Include="System.Net\HttpRequestHeader.cs" />\r
      <Compile Include="System.Net\HttpResponseHeader.cs" />\r
--    <Compile Include="System.Net\HttpStateCache.cs" />\r
++    <Compile Include="System.Net\HttpStateCache.jvm.cs" />\r
      <Compile Include="System.Net\HttpStatusCode.cs" />\r
      <Compile Include="System.Net\HttpStreamAsyncResult.cs" />\r
      <Compile Include="System.Net\HttpUtility.cs" />\r
      <Compile Include="System.Net\UploadStringCompletedEventHandler.cs" />\r
      <Compile Include="System.Net\UploadValuesCompletedEventArgs.cs" />\r
      <Compile Include="System.Net\UploadValuesCompletedEventHandler.cs" />\r
--    <Compile Include="System.Net\VMWHttpProvider.cs" />\r
++    <Compile Include="System.Net\VMWHttpProvider.jvm.cs" />\r
      <Compile Include="System.Net\WebAsyncResult.cs" />\r
      <Compile Include="System.Net\WebClient.cs" />\r
      <Compile Include="System.Net\WebConnectionData.cs" />\r