edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C452676
File: Initializers.Generated.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C452676  (server)    6/10/2008 4:09 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;socketpatch2
@@ -5309,7 +5309,7 @@
             #endif
             #if !SILVERLIGHT
             DefineGlobalClass("Socket", typeof(Ruby.StandardLibrary.Sockets.RubySocket), def1, new System.Action<Ruby.Builtins.RubyModule>(LoadSocket_Instance), new System.Action<Ruby.Builtins.RubyModule>(LoadSocket_Class), Ruby.Builtins.RubyModule.EmptyArray, new System.Delegate[] {
-                new Microsoft.Scripting.Utils.Function<Microsoft.Scripting.Runtime.CodeContext, Ruby.Builtins.MutableString, Ruby.Builtins.MutableString, System.Object, System.Net.Sockets.Socket>(Ruby.StandardLibrary.Sockets.RubySocket.CreateSocket),
+                new Microsoft.Scripting.Utils.Function<Microsoft.Scripting.Runtime.CodeContext, Ruby.Builtins.MutableString, Ruby.Builtins.MutableString, System.Object, Ruby.StandardLibrary.Sockets.RubySocket>(Ruby.StandardLibrary.Sockets.RubySocket.CreateSocket),
             });
             #endif
             #if !SILVERLIGHT
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs;C448462
File: BasicSocket.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs;C448462  (server)    6/10/2008 4:09 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/BasicSocket.cs;socketpatch2
@@ -24,7 +24,7 @@
             get { return _doNotReverseLookup; }
             set { _doNotReverseLookup = value; }
         }
-        
+
         /// <summary>
         /// Create a new RubyBasicSocket from a specified stream and mode
         /// </summary>
@@ -238,7 +238,7 @@
         public static MutableString GetSocketName(RubyBasicSocket/*!*/ self) {
             SocketAddress addr = self.Socket.LocalEndPoint.Serialize();
             byte[] bytes = new byte[addr.Size];
-            for(int i=0; i<addr.Size; ++i) {
+            for (int i = 0; i < addr.Size; ++i) {
                 bytes[i] = addr[i];
             }
             return MutableString.CreateBinary(bytes);
@@ -272,7 +272,7 @@
             // Unpack the socket address information from the to parameter
             SocketAddress address = new SocketAddress(AddressFamily.InterNetwork);
             byte[] bytes = strToAddress.ConvertToBytes();
-            for(int i=0;i<strToAddress.Length;++i) {
+            for (int i = 0; i < strToAddress.Length; ++i) {
                 address[i] = bytes[i];
             }
             EndPoint toEndPoint = self.Socket.LocalEndPoint.Create(address);
@@ -405,6 +405,22 @@
             return (SocketFlags)Protocols.CastToFixnum(context, flags);
         }
 
+        internal static SocketType ConvertToSocketType(CodeContext/*!*/ context, Type klass, object type) {
+            if (type == null) {
+                return SocketType.Stream;
+            }
+            if (type is int) {
+                return (SocketType)(int)type;
+            }
+            MutableString strType = Protocols.AsString(context, type);
+            if (strType != null) {
+                RubyExecutionContext ec = RubyUtils.GetExecutionContext(context);
+                RubyClass rubyKlass = ec.GetClass(klass);
+                return (SocketType)RubyUtils.GetConstant(context, rubyKlass, strType.ToSymbol(), true);
+            }
+            return (SocketType)Protocols.CastToFixnum(context, type);
+        }
+
         internal static AddressFamily ConvertToAddressFamily(CodeContext/*!*/ context, object family) {
             // Default is AF_INET
             if (family == null) {
@@ -442,7 +458,7 @@
             if (hostname is MutableString) {
                 MutableString strHostname = (MutableString)hostname;
                 // Special cases
-                if (strHostname.IsEmpty ) {
+                if (strHostname.IsEmpty) {
                     strHostname = ANY_IP_STRING;
                 } else if (strHostname.Equals(BROADCAST_STRING)) {
                     strHostname = BROADCAST_IP_STRING;
@@ -607,7 +623,7 @@
             public int Port { get { return _port; } }
             public MutableString Protocol { get { return _protocol; } }
             public MutableString Name { get { return _name; } }
-            
+
             public ServiceName(int port, string protocol, string name) {
                 _port = port;
                 _protocol = MutableString.Create(protocol);
===================================================================
edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/Socket.cs;C448462
File: Socket.cs
===================================================================
--- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/Socket.cs;C448462  (server)    6/10/2008 4:09 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/socket/Socket.cs;socketpatch2
@@ -22,14 +22,11 @@
         }
 
         [RubyConstructor]
-        public static Socket CreateSocket(CodeContext/*!*/ context, MutableString/*!*/ domain, MutableString/*!*/ type, object/*Numeric*/ protocol) {
-            RubyExecutionContext ec = RubyUtils.GetExecutionContext(context);
-            RubyClass rubySocketClass = ec.GetClass(typeof(RubySocket));
-
-            AddressFamily addressFamily = (AddressFamily)RubyUtils.GetConstant(context, rubySocketClass, domain.ToSymbol(), true);
+        public static RubySocket/*!*/ CreateSocket(CodeContext/*!*/ context, [NotNull]object/*!*/ domain, [NotNull]object/*!*/ type, object/*Numeric*/ protocol) {
+            AddressFamily addressFamily = ConvertToAddressFamily(context, domain);
+            SocketType socketType = ConvertToSocketType(context, typeof(RubySocket), type);
             ProtocolType protocolType = (ProtocolType)(Protocols.CastToFixnum(context, protocol));
-            SocketType socketType = (SocketType)RubyUtils.GetConstant(context, rubySocketClass, type.ToSymbol(), true);
-            return new Socket(addressFamily, socketType, protocolType);
+            return new RubySocket(context, new Socket(addressFamily, socketType, protocolType));
         }
 
         #endregion
@@ -37,15 +34,15 @@
         #region Public Singleton Methods
 
         [RubyMethod("getaddrinfo", RubyMethodAttributes.PublicSingleton)]
-        public static RubyArray GetAddressInfo(CodeContext/*!*/ context, RubyClass/*!*/ klass, object hostname, object port, 
-            [DefaultParameterValue(null)]object family, 
-            [DefaultParameterValue(0)]object socktype, 
-            [DefaultParameterValue(0)]object protocol, 
+        public static RubyArray GetAddressInfo(CodeContext/*!*/ context, RubyClass/*!*/ klass, object hostname, object port,
+            [DefaultParameterValue(null)]object family,
+            [DefaultParameterValue(0)]object socktype,
+            [DefaultParameterValue(0)]object protocol,
             [DefaultParameterValue(null)]object flags) {
 
             MutableString strHostname = ConvertToHostString(context, hostname);
             int iPort = ConvertToPortNum(context, port);
-            
+
             // Sadly the family, socktype, protocol and flags get passed through at best and ignored at worst, 
             // since System.Net does not provide for them
             AddressFamily addrFamily = ConvertToAddressFamily(context, family);
@@ -69,7 +66,7 @@
                 result.Add(MutableString.Create(address.ToString()));
                 result.Add((int)address.AddressFamily);
                 result.Add(socketType);
-                
+
                 // TODO: protocol type:
                 result.Add(protocolType);
 
@@ -114,7 +111,7 @@
             MutableString strAddress = Protocols.CastToString(context, address);
 
             IPHostEntry entry = GetHostEntry(new IPAddress(strAddress.ConvertToBytes()));
-            
+
             return CreateHostEntryArray(entry, true);
         }
 
@@ -145,7 +142,7 @@
                 // Since the conversion process returns 0 if the string is not a valid number
                 try {
                     return ParseInteger(context, strName.ConvertToString());
-                } catch(InvalidOperationException) {
+                } catch (InvalidOperationException) {
                     throw SocketErrorOps.Factory(MutableString.Create("no such service " + strName.ConvertToString() + " " + strProtocol.ConvertToString()));
                 }
             }
@@ -181,12 +178,12 @@
             // if it exists and is not null hostInfo[3] should have an IP address
             // in that case we use that rather than the host name.
             MutableString address = ConvertToHostString(context, hostInfo[2]);
-            if ( hostInfo.Count > 3 && hostInfo[3] != null ) {
+            if (hostInfo.Count > 3 && hostInfo[3] != null) {
                 address = ConvertToHostString(context, hostInfo[3]);
             }
-            
+
             IPHostEntry entry = GetHostEntry(address.ConvertToString());
-            
+
             RubyArray result = new RubyArray(2);
             result.Add(MutableString.Create(entry.HostName));
             if (service != null) {
@@ -224,7 +221,7 @@
             MutableString strHost = ConvertToHostString(context, host);
             IPEndPoint ep;
             IPAddress[] addresses = Dns.GetHostAddresses(strHost.ConvertToString());
-            if ( addresses.Length > 0 ) {
+            if (addresses.Length > 0) {
                 ep = new IPEndPoint(addresses[0], iPort);
             } else {
                 throw RubyExceptions.CreateArgumentError("invalid host");
@@ -256,7 +253,7 @@
         }
 
         #endregion
-        
+
         #region Public Instance Methods
 
         [RubyMethod("accept")]
@@ -268,7 +265,7 @@
             result.Add(MutableString.Create(addr.ToString()));
             return result;
         }
-        
+
         [RubyMethod("accept_nonblock")]
         public static RubyArray/*!*/ AcceptNonBlocking(CodeContext/*!*/ context, RubySocket/*!*/ self) {
             bool blocking = self.Socket.Blocking;
@@ -346,7 +343,7 @@
         #endregion
 
         #region Constants
-        
+
         #region Address Family
         [RubyConstant]
         public const int AF_APPLETALK = (int)AddressFamily.AppleTalk;
@@ -445,7 +442,7 @@
         public const int EAI_SYSTEM = 11;
         #endregion
 
-        #region 
+        #region
         [RubyConstant]
         public const uint INADDR_ALLHOSTS_GROUP = 0xe0000001;
         [RubyConstant]
@@ -519,47 +516,47 @@
 
         #region Protocol Family
         [RubyConstant]
-        public const int PF_APPLETALK =  (int)ProtocolFamily.AppleTalk;
+        public const int PF_APPLETALK = (int)ProtocolFamily.AppleTalk;
         [RubyConstant]
-        public const int PF_ATM =  (int)ProtocolFamily.Atm;
+        public const int PF_ATM = (int)ProtocolFamily.Atm;
         [RubyConstant]
-        public const int PF_CCITT =  (int)ProtocolFamily.Ccitt;
+        public const int PF_CCITT = (int)ProtocolFamily.Ccitt;
         [RubyConstant]
-        public const int PF_CHAOS =  (int)ProtocolFamily.Chaos;
+        public const int PF_CHAOS = (int)ProtocolFamily.Chaos;
         [RubyConstant]
-        public const int PF_DATAKIT =  (int)ProtocolFamily.DataKit;
+        public const int PF_DATAKIT = (int)ProtocolFamily.DataKit;
         [RubyConstant]
-        public const int PF_DLI =  (int)ProtocolFamily.DataLink;
+        public const int PF_DLI = (int)ProtocolFamily.DataLink;
         [RubyConstant]
-        public const int PF_ECMA =  (int)ProtocolFamily.Ecma;
+        public const int PF_ECMA = (int)ProtocolFamily.Ecma;
         [RubyConstant]
-        public const int PF_HYLINK =  (int)ProtocolFamily.HyperChannel;
+        public const int PF_HYLINK = (int)ProtocolFamily.HyperChannel;
         [RubyConstant]
-        public const int PF_IMPLINK =  (int)ProtocolFamily.ImpLink;
+        public const int PF_IMPLINK = (int)ProtocolFamily.ImpLink;
         [RubyConstant]
-        public const int PF_INET =  (int)ProtocolFamily.InterNetwork;
+        public const int PF_INET = (int)ProtocolFamily.InterNetwork;
         [RubyConstant]
-        public const int PF_IPX =  (int)ProtocolFamily.Ipx;
+        public const int PF_IPX = (int)ProtocolFamily.Ipx;
         [RubyConstant]
-        public const int PF_ISO =  (int)ProtocolFamily.Iso;
+        public const int PF_ISO = (int)ProtocolFamily.Iso;
         [RubyConstant]
-        public const int PF_LAT =  (int)ProtocolFamily.Lat;
+        public const int PF_LAT = (int)ProtocolFamily.Lat;
         [RubyConstant]
-        public const int PF_MAX =  (int)ProtocolFamily.Max;
+        public const int PF_MAX = (int)ProtocolFamily.Max;
         [RubyConstant]
-        public const int PF_NS =  (int)ProtocolFamily.NS;
+        public const int PF_NS = (int)ProtocolFamily.NS;
         [RubyConstant]
-        public const int PF_OSI =  (int)ProtocolFamily.Osi;
+        public const int PF_OSI = (int)ProtocolFamily.Osi;
         [RubyConstant]
-        public const int PF_PUP =  (int)ProtocolFamily.Pup;
+        public const int PF_PUP = (int)ProtocolFamily.Pup;
         [RubyConstant]
-        public const int PF_SNA =  (int)ProtocolFamily.Sna;
+        public const int PF_SNA = (int)ProtocolFamily.Sna;
         [RubyConstant]
-        public const int PF_UNIX =  (int)ProtocolFamily.Unix;
+        public const int PF_UNIX = (int)ProtocolFamily.Unix;
         [RubyConstant]
-        public const int PF_UNSPEC =  (int)ProtocolFamily.Unspecified;
+        public const int PF_UNSPEC = (int)ProtocolFamily.Unspecified;
         #endregion
-        
+
         #region Socket Shutdown
         [RubyConstant]
         public const int SHUT_RD = (int)SocketShutdown.Receive;
===================================================================
