CreateWSASocket() static private method

static private CreateWSASocket ( AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType ) : SafeCloseSocket
addressFamily AddressFamily
socketType SocketType
protocolType ProtocolType
return SafeCloseSocket
コード例 #1
0
        public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType)
        {
            SafeCloseSocket handle;

            Interop.Winsock.WSAPROTOCOL_INFO protocolInfo;

            fixed(byte *pinnedBuffer = socketInformation.ProtocolInformation)
            {
                handle       = SafeCloseSocket.CreateWSASocket(pinnedBuffer);
                protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFO)Marshal.PtrToStructure <Interop.Winsock.WSAPROTOCOL_INFO>((IntPtr)pinnedBuffer);
            }

            if (handle.IsInvalid)
            {
                SocketException e = new SocketException();
                if (e.SocketErrorCode == SocketError.InvalidArgument)
                {
                    throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation");
                }
                else
                {
                    throw e;
                }
            }

            addressFamily = protocolInfo.iAddressFamily;
            socketType    = (SocketType)protocolInfo.iSocketType;
            protocolType  = (ProtocolType)protocolInfo.iProtocol;
            return(handle);
        }
コード例 #2
0
 public static SocketError CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, out SafeCloseSocket socket)
 {
     socket = SafeCloseSocket.CreateWSASocket(addressFamily, socketType, protocolType);
     return(socket.IsInvalid ? GetLastSocketError() : SocketError.Success);
 }
コード例 #3
0
 public static SafeCloseSocket CreateSocket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
 {
     return(SafeCloseSocket.CreateWSASocket(addressFamily, socketType, protocolType));
 }