public DispatcherClientTests()
 {
     _server = Substitute.For<ITalkToServer>();
     _err = Substitute.For<IDeliveryErrorsQueue>();
     _sut =new DispatcherClient(Setup.TestEndpoint.Host,_server,_err,new BusAuditor(new InMemoryAuditStorage()));
     _config = SetupFakeConfig();
     _sut.SubscribeToServer(new []{_config});
 }
 public ManagedSocketListener( IScheduler scheduler, IEndpointConfiguration endpoint, IServerConfiguration configuration )
 {
     try
     {
         Scheduler = scheduler;
         Configuration = configuration;
         Connection = Bind( endpoint );
     }
     catch (Exception ex)
     {
         Console.WriteLine( ex );
     }
 }
 public Win32SocketAdapter( IEndpointConfiguration endpoint, IServerConfiguration configuration )
 {
     try
     {
         Configuration = configuration;
         Connection = Bind( endpoint );
         Bytes = new byte[configuration.ReadBufferSize];
         OnDisconnect = new List<Action>();
     }
     catch (Exception ex)
     {
         Console.WriteLine( ex );
     }
 }
        public SOCKET Bind( IEndpointConfiguration configuration )
        {
            SOCKET socket = INVALID_SOCKET;
            "Binding to endpoint {0}:{1}"
                .ToDebug<ISocketServer>( configuration.BindTo ?? "0.0.0.0", configuration.Port );

            try
            {
                WSAPROTOCOL_INFO info = new WSAPROTOCOL_INFO();

                Native.WSASocket(
                        (int) AddressFamily.InterNetworkv4,
                        (int) SocketType.Stream,
                        (int) ProtocolType.Tcp,
                        out info,
                        0,
                        (int) SocketFlags.Overlapped
                    );

                var address = Native.inet_addr( configuration.AnyInterface
                                  ? "0.0.0.0"
                                  : configuration.BindTo );
                var port = Native.htons( (ushort) configuration.Port );
                sockaddr_in socket_address = new sockaddr_in();
                socket_address.sin_addr.S_addr = address;
                socket_address.sin_port = port;
                socket_address.sin_family = (short) AddressFamily.InterNetworkv4;

                Native.bind( socket, &socket_address, sizeof ( sockaddr_in ) );
                Native.listen( socket, 10000 );
                return socket;
            }
            catch (Exception e)
            {
                "Binding to endpoint {0}:{1} FAILED."
                    .ToDebug<ISocketServer>( configuration.BindTo ?? "0.0.0.0", configuration.Port );
            }
            return socket;
        }
 public void AddEndPoint( IEndpointConfiguration endpoint )
 {
     Endpoints.Add( endpoint );
 }
 private async Task SendToProcessor(IEndpointConfiguration ep, IMessage[] toSend)
 {
     this.LogDebug($"Sending {toSend.Length} messages to {ep.Id}");
     await ep.AddToProcessing(toSend).ConfigureFalse();
     _auditor.SentToLocal(ep.Id, toSend);
 }
 public Socket Bind( IEndpointConfiguration configuration )
 {
     try
     {
         var socket = new Socket(
             AddressFamily.InterNetwork,
             SocketType.Stream,
             ProtocolType.IP );
         var address = configuration.AnyInterface
                           ? IPAddress.Any
                           : IPAddress.Parse( configuration.BindTo );
         var endpoint = new IPEndPoint( address, configuration.Port );
         socket.Bind( endpoint );
         socket.Listen( 1000 );
         return socket;
     }
     catch ( Exception ex )
     {
         "Binding to endpoint {0}:{1} FAILED."
             .ToError<ISocketServer>( configuration.BindTo ?? "0.0.0.0", configuration.Port );
         throw ex;
     }
     return null;
 }
 public ISocketListener CreateListener( IScheduler scheduler, IEndpointConfiguration endpoint, IServerConfiguration server )
 {
     return new ManagedSocketListener( scheduler, endpoint, server );
 }
 public ISocketListener CreateListener( IScheduler scheduler, IEndpointConfiguration endpoint, IServerConfiguration server )
 {
     return Listener;
 }
 public HttpHostConfiguration AddEndpointConfiguration(IEndpointConfiguration configureEndpoint)
 {
     this.endpointConfiguration.Add(configureEndpoint);
     return this;
 }