/// <summary>
        /// Accepts a incoming connection request.
        /// </summary>
        /// <returns>A ISocket instance used to send and receive data</returns>
        public unsafe ISocketWrapper Accept()
        {
            EnsureAccessible();
            if (!isListening)
            {
                throw new InvalidOperationException("You must call the Listen method before performing this operation.");
            }

            var sockaddrlen = Ipv4AddressSize;
            var addrbuf     = stackalloc byte[(sockaddrlen / IntPtr.Size + 2) * IntPtr.Size]; //sizeof DWORD
            var sockaddr    = (IntPtr)addrbuf;

            var acceptedSockHandle = RioNative.accept(SockHandle, sockaddr, ref sockaddrlen);

            if (acceptedSockHandle == new IntPtr(-1))
            {
                // if the native call fails we'll throw a SocketException
                var socketException = new SocketException();
                logger.LogError("Native accept() failed with error {0}", socketException.NativeErrorCode);
                throw socketException;
            }

            var remoteEp = CreateIpEndPoint(sockaddr);
            var socket   = new RioSocketWrapper(acceptedSockHandle, LocalEndPoint, remoteEp);

            logger.LogDebug("Accepted connection from {0} to {1}", socket.RemoteEndPoint, socket.LocalEndPoint);
            return(socket);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a SocketStream with a RioSocketWrapper object.
 /// </summary>
 /// <param name="socket">a RioSocketWrapper object</param>
 public SocketStream(RioSocketWrapper socket)
 {
     if (socket == null)
     {
         throw new ArgumentNullException("socket");
     }
     streamSocket = socket;
     bufPool = ByteBufPool.UnsafeDefault;
 }
Exemple #3
0
 /// <summary>
 /// Initializes a SocketStream with a RioSocketWrapper object.
 /// </summary>
 /// <param name="socket">a RioSocketWrapper object</param>
 public SocketStream(RioSocketWrapper socket)
 {
     if (socket == null)
     {
         throw new ArgumentNullException("socket");
     }
     streamSocket = socket;
     bufPool      = ByteBufPool.UnsafeDefault;
 }
        /// <summary>
        /// Accepts a incoming connection request.
        /// </summary>
        /// <returns>A ISocket instance used to send and receive data</returns>
        public unsafe ISocketWrapper Accept()
        {
            EnsureAccessible();
            if (!isListening)
            {
                throw new InvalidOperationException("You must call the Listen method before performing this operation.");
            }

            var sockaddrlen = Ipv4AddressSize;
            var addrbuf = stackalloc byte[(sockaddrlen / IntPtr.Size + 2) * IntPtr.Size]; //sizeof DWORD
            var sockaddr = (IntPtr)addrbuf;

            var acceptedSockHandle = RioNative.accept(SockHandle, sockaddr, ref sockaddrlen);
            if (acceptedSockHandle == new IntPtr(-1))
            {
                // if the native call fails we'll throw a SocketException
                var socketException = new SocketException();
                logger.LogError("Native accept() failed with error {0}", socketException.NativeErrorCode);
                throw socketException;
            }

            var remoteEp = CreateIpEndPoint(sockaddr);
            var socket = new RioSocketWrapper(acceptedSockHandle, LocalEndPoint, remoteEp);
            logger.LogDebug("Accepted connection from {0} to {1}", socket.RemoteEndPoint, socket.LocalEndPoint);
            return socket;
        }